80 likes | 283 Views
Exercises for Explosion and Reuse. Bubbles. 1. Make the bubbles have random sizes . 2. Make the bubbles translucent ( semi-transparent ). 3. Automatically add bubbles to the World. Transparency. You can set the transparency of a GreenfootImage: image. setTranparency ( int value ).
E N D
Bubbles 1. Make the bubbles have random sizes. 2. Make the bubbles translucent (semi-transparent). 3. Automatically add bubbles to the World.
Transparency You can set the transparency of a GreenfootImage: image.setTranparency( int value ) opaque setTransparency(255) setTransparency(200) setTransparency(150) invisible setTransparency(100) setTransparency(50) setTransparency(0)
Add Mines to Crabgame • Add a Mine that floats down from top. • If Mine intersects a Crab or Lobster, explode! Explodes when it hits a Crab, Lobster, or Rock. Kills Animals close by.
Hint for Exercise • You can create a "DepthCharge" as subclass of of SmoothMover. • But, SmoothMover "wraps around" the edge of the world. X You get too many depth charges. Solution: remove DepthCharge when it gets to bottom of the world.
Hint for Exercise act: check if we intersect an actor if hit another actor then create explosion explode! else if y >= height of world - 2 remove me from world remove from world
Optional: Better Shockwave Advanced In the Shockwave class, explodeOthers( ) sometimes explodes (or kills) other objects that the shockwave doesn't touch! Why? explodeOthers( ) uses getIntersectingObjects( ) to look for stuff to explode. It is "true" if the images overlap. But the image of an Actor may be larger than the visible image. getIntersectingObjects( ) is true because images overlap.
Optional: Better Shockwave (2) Advanced Use getObjectsInRange(radius, clss) instead of getIntersectingObjects(). The Javadoc says: List list = getObjectsInRange(int radius, Class cls) Return all objects within range radius around this object.An object is within range if the distance between its center and this object's center is less than or equal to radius.