scg/ch05/SnowmanSpriteGame

From FANG

Jump to: navigation, search

01 package scg.ch05;
02 
03 import fang2.core.Game;
04 
05 /** Demonstrate how a SnowmanSprite works */
06 public class SnowmanSpriteGame
07   extends Game {
08   // two moving snowmen
09   private SnowmanSprite a;
10   private SnowmanSprite b;
11   private final double speed = 1.0;
12 
13   /**
14    * Move a according to keystrokes.
15    *
16    @param  dT  seconds since last call to advance
17    */
18   @Override
19   public void advance(double dT{
20     if (leftPressed()) {
21       a.translateX(-dT * speed);
22     } else if (rightPressed()) {
23       a.translateX(dT * speed);
24     }
25     if (a.intersects(b)) {
26       System.out.println("a hits b");
27     }
28   }
29 
30   /**
31    Set up two snowmen at different spots on the screen.
32    */
33   @Override
34   public void setup() {
35     = new SnowmanSprite();
36     a.setLocation(0.250.5);
37     a.setScale(0.5);
38     addSprite(a);
39     = new SnowmanSprite();
40     b.setScale(0.5);
41     b.setLocation(0.750.5);
42     addSprite(b);
43   }
44 }
45 
46 //Uploaded on Mon Mar 29 21:38:49 EDT 2010


Download/View scg/ch05/SnowmanSpriteGame.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