From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch02;
02
03
04 importimport means to make the classes and/or packages available in this program fang2.attributes.Location2D;
05 importimport means to make the classes and/or packages available in this program fang2.attributes.Vector2D;
06 importimport means to make the classes and/or packages available in this program fang2.core.Game;
07
08 /**
09 * A {open braces start code blocks and must be matched with a close brace@link BasketBallSprite}close braces end code blocks and must match an earlier open brace launcher. Starts as a line that tracks the
10 * mouse; when mouse is clicked, a {open braces start code blocks and must be matched with a close brace@link BasketBallSprite}close braces end code blocks and must match an earlier open brace is created
11 * and added to the game. The PPBS starts at the anchor end of thisthis means the current object (the implicit parameter)
12 * sprite ({open braces start code blocks and must be matched with a close brace@link #getAnchor()}close braces end code blocks and must match an earlier open brace is used), the velocity set to doubledouble is the type for numbers that can contain decimal fractions the
13 * vector represented by the line drawn by thisthis means the current object (the implicit parameter) sprite.
14 */
15 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects BasketBallLauncherSprite
16 extendsextends means to customize or extend the functionality of a class MouseTrackingLine {open braces start code blocks and must be matched with a close brace
17 /**
18 * Construct a newnew is used to create objects by calling the constructor launcher.
19 *
20 * @paramthis is the Javadoc tag for documenting the purpose of parameters x the x-coordinate of the anchor point
21 * @paramthis is the Javadoc tag for documenting the purpose of parameters y the y-coordinate of the anchor point
22 */
23 publicpublic is used to indicate unrestricted access (any other class can have access) BasketBallLauncherSprite(doubledouble is the type for numbers that can contain decimal fractions x, doubledouble is the type for numbers that can contain decimal fractions y) {open braces start code blocks and must be matched with a close brace
24 thisthis means the current object (the implicit parameter)(newnew is used to create objects by calling the constructor Location2D(x, y));
25 }close braces end code blocks and must match an earlier open brace
26
27 /**
28 * Construct a newnew is used to create objects by calling the constructor launcher.
29 *
30 * @paramthis is the Javadoc tag for documenting the purpose of parameters anchor the anchor point
31 */
32 publicpublic is used to indicate unrestricted access (any other class can have access) BasketBallLauncherSprite(Location2D anchor) {open braces start code blocks and must be matched with a close brace
33 super(anchor);
34 setColor(Game.getColor("orange"));
35 }close braces end code blocks and must match an earlier open brace
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 * @paramthis is the Javadoc tag for documenting the purpose of parameters location where the mouse is clicked (ignored)
42 * @paramthis is the Javadoc tag for documenting the purpose of parameters mouseButton which mouse button was pushed
43 */
44 @Override
45 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value mouseClickedAt(Location2D location, intint is the type for whole numbers and it is short for integer mouseButton) {open braces start code blocks and must be matched with a close brace
46 BasketBallSprite projectile =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor 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(newnew is used to create objects by calling the constructor Vector2D(270, 0.4));
53 // add new sprite to game
54 Game.getCurrentGame().addSprite(projectile);
55 // banish launcher
56 removeFromCanvas();
57 }close braces end code blocks and must match an earlier open brace
58 }close braces end code blocks and must match an earlier open brace
59
60 //Uploaded on Mon Mar 29 21:40:26 EDT 2010
|
Download/View scg/ch02/BasketBallLauncherSprite.java