intro/Bounce

From ggc

Jump to: navigation, search

01 package intro;
02 
03 import fang.*;
04 import java.awt.*;
05 import java.awt.geom.*;
06 
07 /**
08  * All about my game.
09  @author My Name Here
10  */
11 public class Bounce extends Game
12 {
13   private OutlineSprite boundary;
14   private OvalSprite ball;
15   private ProjectileTransformer projectile;
16 
17   /**sets up the game*/
18   public void setup()
19   {
20     makeAndAddBoundary();
21 
22     makeAndAddBall();
23 
24     projectile=new ProjectileTransformer(0.10.25);
25     ball.setTracker(projectile);
26   }
27 
28   private void makeAndAddBall()
29   {
30     ball=new OvalSprite(0.10.1);
31     ball.setLocation(0.50.5);
32     addSprite(ball);
33   }
34 
35   private void makeAndAddBoundary()
36   {
37     boundary=new OutlineSprite(new PolygonSprite(5));
38     boundary.setSize(0.9);
39     boundary.setLineThickness(0.2);
40     boundary.setLocation(0.50.5);
41     addSprite(boundary);
42   }
43 
44   private void handleCollisions()
45   {
46     ball.bounceOffOf(boundary);
47   }
48 
49   /**handle input and game events*/
50   public void advance()
51   {
52     handleCollisions();
53   }
54 
55 }


Download/View intro/Bounce.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