scg/ch05/SnowmanSprite

From FANG

Jump to: navigation, search

01 package scg.ch05;
02 
03 import java.awt.geom.Rectangle2D;
04 
05 import fang2.core.Game;
06 import fang2.core.Sprite;
07 import fang2.sprites.CompositeSprite;
08 import fang2.sprites.OvalSprite;
09 
10 // FANG Demonstration program: CompositeSprite
11 public class SnowmanSprite
12   extends CompositeSprite {
13   // add three circles to snowman, add snowman to scene
14   public SnowmanSprite() {
15     OvalSprite head = new OvalSprite(0.30.3);
16     head.setColor(Game.getColor("SCGRed"));
17     head.setLocation(0, -0.25);
18     addSprite(head);
19 
20     OvalSprite middle = new OvalSprite(0.40.4);
21     middle.setColor(Game.getColor("SCGRed"));
22     middle.setLocation(0.00.0);
23     addSprite(middle);
24 
25     OvalSprite bottom = new OvalSprite(0.50.5);
26     bottom.setColor(Game.getColor("SCGRed"));
27     bottom.setLocation(00.35);
28     addSprite(bottom);
29   }
30 
31   // spin the snowman about 4 times a minute; see how everything
32   // moves relative to (0.0, 0.0) ON snowman.
33   public void advance(double secondsSinceLastCall{
34     rotateDegrees(24.0 * secondsSinceLastCall);
35   }
36 
37   @Override
38   public boolean intersects(Sprite sprite{
39     Rectangle2D spriteBounds = sprite.getBounds2D().Rectangle2D();
40     Rectangle2D bounds = getBounds2D().Rectangle2D();
41     if (!bounds.intersects(spriteBounds)) {
42       return false;
43     }
44     return true;
45   }
46 }
47 
48 //Uploaded on Mon Mar 29 21:42:17 EDT 2010


Download/View scg/ch05/SnowmanSprite.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games