From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch02;
02
03 importimport means to make the classes and/or packages available in this program fang2.core.Game;
04 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
05
06 /**
07 * Throw a basketball sprite. BasketBallLauncher knows about
08 * BasketBallSprite so we just add the launcher. When the mouse is
09 * clicked, the launcher launches a basket ball along the given line
10 * (gravity and bouncing change its course).
11 */
12 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 BasketBall
13 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
14 /**
15 * Setup the sprites (and anything elseelse is what happens when the if condition is false) necessary forfor is a looping structure for repeatedly executing a block of code our game.
16 */
17 @Override
18 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
19 // width, height (in screens); location is (x, y), in screens
20 RectangleSprite rectangleBottom =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.25, 0.05);
21 rectangleBottom.setLocation(0.625, 0.475);
22 addSprite(rectangleBottom);
23
24 RectangleSprite rectangleBackboard =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.05, 0.4);
25 rectangleBackboard.setLocation(0.75, 0.3);
26 addSprite(rectangleBackboard);
27
28 RectangleSprite rectangleFrontboard =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.05,
29 0.2);
30 rectangleFrontboard.setLocation(0.50, 0.4);
31 addSprite(rectangleFrontboard);
32
33 // location of the anchor point (launch point, too)
34 BasketBallLauncherSprite launcher =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor BasketBallLauncherSprite(0.05, 0.5);
35 addSprite(launcher);
36 }close braces end code blocks and must match an earlier open brace
37 }close braces end code blocks and must match an earlier open brace
38
39 //Uploaded on Mon Mar 29 21:42:37 EDT 2010
|
Download/View scg/ch02/BasketBall.java