scg/ch02/BasketBallLauncherSprite

From FANG

Jump to: navigation, search

01 package scg.ch02;
02 
03 
04 import fang2.attributes.Location2D;
05 import fang2.attributes.Vector2D;
06 import fang2.core.Game;
07 
08 /**
09  * A {@link BasketBallSprite} launcher. Starts as a line that tracks the
10  * mouse; when mouse is clicked, a {@link BasketBallSprite} is created
11  * and added to the game. The PPBS starts at the anchor end of this
12  * sprite ({@link #getAnchor()} is used), the velocity set to double the
13  * vector represented by the line drawn by this sprite.
14  */
15 public class BasketBallLauncherSprite
16   extends MouseTrackingLine {
17   /**
18    * Construct a new launcher.
19    *
20    @param  x  the x-coordinate of the anchor point
21    @param  y  the y-coordinate of the anchor point
22    */
23   public BasketBallLauncherSprite(double x, double y{
24     this(new Location2D(x, y));
25   }
26 
27   /**
28    * Construct a new launcher.
29    *
30    @param  anchor  the anchor point
31    */
32   public BasketBallLauncherSprite(Location2D anchor{
33     super(anchor);
34     setColor(Game.getColor("orange"));
35   }
36 
37   /**
38    * What happens when the mouse is clicked? We get a projectile from
39    * the game and get out of the game.
40    *
41    @param  location     where the mouse is clicked (ignored)
42    @param  mouseButton  which mouse button was pushed
43    */
44   @Override
45   public void mouseClickedAt(Location2D location, int mouseButton{
46     BasketBallSprite projectile = new BasketBallSprite();
47     // start the basketball at the anchor end of launcher
48     projectile.setLocation(getAnchor());
49     // launch velocity is double the length of the line
50     projectile.setVelocity(getVector().multiply(2.0));
51     // 270 degrees - straight down; 0.6 screens/second^2
52     projectile.setAcceleration(new Vector2D(2700.4));
53     // add new sprite to game
54     Game.getCurrentGame().addSprite(projectile);
55     // banish launcher
56     removeFromCanvas();
57   }
58 }
59 
60 //Uploaded on Mon Mar 29 21:40:26 EDT 2010


Download/View scg/ch02/BasketBallLauncherSprite.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