From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch05;
02
03 importimport means to make the classes and/or packages available in this program fang2.core.Game;
04
05 /** Demonstrate how a SnowmanSprite works */
06 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 SnowmanSpriteGame
07 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
08 // two moving snowmen
09 privateprivate is used to restrict access to the current class only SnowmanSprite a;
10 privateprivate is used to restrict access to the current class only SnowmanSprite b;
11 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions speed =this assignment operator makes the left side equal to the right side 1.0;
12
13 /**
14 * Move a according to keystrokes.
15 *
16 * @paramthis is the Javadoc tag for documenting the purpose of parameters dT seconds since last call to advance
17 */
18 @Override
19 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
20 ifif executes the next statement only if the condition in parenthesis evaluates to true (leftPressed()) {open braces start code blocks and must be matched with a close brace
21 a.translateX(-dT * speed);
22 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (rightPressed()) {open braces start code blocks and must be matched with a close brace
23 a.translateX(dT * speed);
24 }close braces end code blocks and must match an earlier open brace
25 ifif executes the next statement only if the condition in parenthesis evaluates to true (a.intersects(b)) {open braces start code blocks and must be matched with a close brace
26 System.out.println("a hits b");
27 }close braces end code blocks and must match an earlier open brace
28 }close braces end code blocks and must match an earlier open brace
29
30 /**
31 * Set up two snowmen at different spots on the screen.
32 */
33 @Override
34 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
35 a =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor SnowmanSprite();
36 a.setLocation(0.25, 0.5);
37 a.setScale(0.5);
38 addSprite(a);
39 b =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor SnowmanSprite();
40 b.setScale(0.5);
41 b.setLocation(0.75, 0.5);
42 addSprite(b);
43 }close braces end code blocks and must match an earlier open brace
44 }close braces end code blocks and must match an earlier open brace
45
46 //Uploaded on Mon Mar 29 21:38:49 EDT 2010
|
Download/View scg/ch05/SnowmanSpriteGame.java