intro/ProjectileBounceExample

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 ProjectileBounceExample 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     boundary=new OutlineSprite(new PolygonSprite(5));
21     boundary.setSize(0.9);
22     boundary.setLineThickness(0.2);
23     boundary.setLocation(0.50.5);
24     addSprite(boundary);
25 
26     ball=new OvalSprite(0.10.1);
27     ball.setLocation(0.50.5);
28     addSprite(ball);
29 
30     projectile=new ProjectileTransformer(0.10.25);
31     ball.setTracker(projectile);
32   }
33 
34   private void handleCollisions()
35   {
36     if(ball.intersects(boundary))
37     {
38       Vector2D vector=projectile.getVector2D();
39       vector.turnDegrees(180);
40       projectile.setVector2D(vector);
41     }
42   }
43 
44   /**handle input and game events*/
45   public void advance()
46   {
47     handleCollisions();
48   }
49 }


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