From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch04;
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.OvalSprite;
05 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
06
07 /** NewtonsApple pre-prototype */
08 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 NewtonsAppleAdvance
09 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
10 // An OvalSprite field to name the apple
11 privateprivate is used to restrict access to the current class only OvalSprite apple;
12 // A RectangleSprite field to name newton
13 privateprivate is used to restrict access to the current class only RectangleSprite newton;
14
15 /**
16 * Update the game state: only game state here is where the apple is;
17 * let it fall each frame. Velocity is 0.10 screen/second.
18 */
19 @Override
20 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 secondsSinceLastCall) {open braces start code blocks and must be matched with a close brace
21 apple.translateY(0.10 * secondsSinceLastCall);
22 }close braces end code blocks and must match an earlier open brace
23
24 // First pass at defining the sprites for the game
25 @Override
26 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
27 apple =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.10, 0.10);
28 apple.setColor(getColor("red"));
29 apple.setLocation(0.50, 0.00);
30
31 newton =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.10, 0.10);
32 newton.setColor(getColor("green"));
33 newton.setLocation(0.50, 0.90);
34
35 addSprite(newton);
36 addSprite(apple);
37 }close braces end code blocks and must match an earlier open brace
38 }close braces end code blocks and must match an earlier open brace
39
40 //Uploaded on Mon Mar 29 21:41:53 EDT 2010
|
Download/View scg/ch04/NewtonsAppleAdvance.java