|
01 packagepackage is used to name the directory or folder a class is in scg.ch06;
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 * The PongPaddle, a paddle forfor is a looping structure for repeatedly executing a block of code playing pong. This classclass is a group of fields and methods used for making objects uses {open braces start code blocks and must be matched with a close brace@link
08 * fang2.core.Game#getCurrentGame() Game.getCurrentGame}close braces end code blocks and must match an earlier open brace to get the current
09 * game so that it can provide access to the player's key presses.
10 */
11 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 PongPaddle
12 extendsextends means to customize or extend the functionality of a class RectangleSprite {open braces start code blocks and must be matched with a close brace
13 /**
14 * Velocity, in screens/second, with which the paddle moves in the x
15 * and y directions; the velocity only applies when the appropriate
16 * arrow keys are pressed.
17 */
18 doubledouble is the type for numbers that can contain decimal fractions deltaX;
19 doubledouble is the type for numbers that can contain decimal fractions deltaY;
20
21 /**
22 * Construct a newnew is used to create objects by calling the constructor PongPaddle instance. The size and initial velocity
23 * are specified as parameters to the constructor.
24 *
25 * @paramthis is the Javadoc tag for documenting the purpose of parameters width width, in screens, of the paddle
26 * @paramthis is the Javadoc tag for documenting the purpose of parameters height height, in screens, of the paddle
27 * @paramthis is the Javadoc tag for documenting the purpose of parameters deltaX horizontal velocity, in screens per second
28 * @paramthis is the Javadoc tag for documenting the purpose of parameters deltaY vertical velocity, in screens per second
29 */
30 publicpublic is used to indicate unrestricted access (any other class can have access) PongPaddle(doubledouble is the type for numbers that can contain decimal fractions width, doubledouble is the type for numbers that can contain decimal fractions height, doubledouble is the type for numbers that can contain decimal fractions deltaX,
31 doubledouble is the type for numbers that can contain decimal fractions deltaY) {open braces start code blocks and must be matched with a close brace
32 super(width, height);
33 thisthis means the current object (the implicit parameter).deltaX =this assignment operator makes the left side equal to the right side deltaX;// scope hole
34 thisthis means the current object (the implicit parameter).deltaY =this assignment operator makes the left side equal to the right side deltaY;// scope hole
35 }close braces end code blocks and must match an earlier open brace
36
37 /**
38 * Advance the paddle one frame. The paddle will move according to its
39 * velocity (as set in the constructor or {open braces start code blocks and must be matched with a close brace@link #setVelocity}close braces end code blocks and must match an earlier open brace) ifif executes the next statement only if the condition in parenthesis evaluates to true the
40 * appropriate arrow key is pressed. That is, ifif executes the next statement only if the condition in parenthesis evaluates to true the up arrow is
41 * pressed, the paddle will move with the negative {open braces start code blocks and must be matched with a close brace@code deltaY}close braces end code blocks and must match an earlier open brace
42 * velocity; ifif executes the next statement only if the condition in parenthesis evaluates to true the down arrow is pressed, it will move with the
43 * positive {open braces start code blocks and must be matched with a close brace@code deltaY}close braces end code blocks and must match an earlier open brace.
44 *
45 * @paramthis is the Javadoc tag for documenting the purpose of parameters deltaT time elapsed since last call to advance
46 */
47 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 deltaT) {open braces start code blocks and must be matched with a close brace
48 ifif executes the next statement only if the condition in parenthesis evaluates to true (Game.getCurrentGame().upPressed()) {open braces start code blocks and must be matched with a close brace
49 translateY(-deltaY * deltaT);
50 }close braces end code blocks and must match an earlier open brace
51 ifif executes the next statement only if the condition in parenthesis evaluates to true (Game.getCurrentGame().downPressed()) {open braces start code blocks and must be matched with a close brace
52 translateY(deltaY * deltaT);
53 }close braces end code blocks and must match an earlier open brace
54 ifif executes the next statement only if the condition in parenthesis evaluates to true (Game.getCurrentGame().leftPressed()) {open braces start code blocks and must be matched with a close brace
55 translateX(-deltaX * deltaT);
56 }close braces end code blocks and must match an earlier open brace
57 ifif executes the next statement only if the condition in parenthesis evaluates to true (Game.getCurrentGame().rightPressed()) {open braces start code blocks and must be matched with a close brace
58 translateX(deltaX * deltaT);
59 }close braces end code blocks and must match an earlier open brace
60 bounceOffEdges();
61 }close braces end code blocks and must match an earlier open brace
62
63 /**
64 * "Bounce" the paddle off of the edges. While there might be
65 * reasonable gameplay in actually bouncing the paddle, in thisthis means the current object (the implicit parameter) game
66 * all that happens is that ifif executes the next statement only if the condition in parenthesis evaluates to true the paddle moves off the screen in any
67 * direction, it is pushed back onto the screen. The push is done by
68 * moving the location the minimal amount to put all of the paddle on
69 * the screen.
70 */
71 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffEdges() {open braces start code blocks and must be matched with a close brace
72 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMinY() < 0.0) {open braces start code blocks and must be matched with a close brace
73 translateY(0.0 - getMinY());
74 }close braces end code blocks and must match an earlier open brace
75 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMaxY() > 1.0) {open braces start code blocks and must be matched with a close brace
76 translateY(1.0 - getMaxY());
77 }close braces end code blocks and must match an earlier open brace
78 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMinX() < 0.0) {open braces start code blocks and must be matched with a close brace
79 translateX(0.0 - getMinX());
80 }close braces end code blocks and must match an earlier open brace
81 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMaxX() > 1.0) {open braces start code blocks and must be matched with a close brace
82 translateX(1.0 - getMaxX());
83 }close braces end code blocks and must match an earlier open brace
84 }close braces end code blocks and must match an earlier open brace
85
86 /**
87 * Set the current velocity of the paddle
88 *
89 * @paramthis is the Javadoc tag for documenting the purpose of parameters deltaX the newnew is used to create objects by calling the constructor horizontal velocity
90 * @paramthis is the Javadoc tag for documenting the purpose of parameters deltaY the newnew is used to create objects by calling the constructor vertical velocity
91 */
92 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setVelocity(doubledouble is the type for numbers that can contain decimal fractions deltaX, doubledouble is the type for numbers that can contain decimal fractions deltaY) {open braces start code blocks and must be matched with a close brace
93 thisthis means the current object (the implicit parameter).deltaX =this assignment operator makes the left side equal to the right side deltaX;
94 thisthis means the current object (the implicit parameter).deltaY =this assignment operator makes the left side equal to the right side deltaY;
95 }close braces end code blocks and must match an earlier open brace
96 }close braces end code blocks and must match an earlier open brace
97
98 //Uploaded on Mon Mar 29 21:41:41 EDT 2010
|