|
001 packagepackage is used to name the directory or folder a class is in Blake;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007
008 /**
009 * All about my game here.
010 * @authorthis is the Javadoc tag for documenting who created the source code bErskine
011 * Enhancements
012 * 1. Level Added
013 * 2. Curved Walla
014 * 3. Pause between levels
015 * 4. Cheats
016 * 5. Two Balls
017 * Also got help from Hemendra and Jayson
018 */
019 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 Breakout2 extendsextends means to customize or extend the functionality of a class GameLoop
020 {open braces start code blocks and must be matched with a close brace
021 /**a rectangle*/
022 privateprivate is used to restrict access to the current class only Sprite ceiling, leftWall, rightWall, floor;
023 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions startYCoord, startXCoord;
024 privateprivate is used to restrict access to the current class only Sprite paddle, ball, ball2;
025 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
026 privateprivate is used to restrict access to the current class only ProjectileTracker tracker2;
027 privateprivate is used to restrict access to the current class only Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays bricks;
028 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer score, lives, numBricksAcross, level=this assignment operator makes the left side equal to the right side1, timeLeft;
029 privateprivate is used to restrict access to the current class only StringSprite timerSprite, scoreSprite, livesSprite, gameOver;
030
031 /**sets up the game*/
032 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
033 {open braces start code blocks and must be matched with a close brace
034 timeLeft=this assignment operator makes the left side equal to the right side10;
035 removeCursor();
036 makeSprites();
037 addSprites();
038 makeceiling();
039 makeLeftWall();
040 makeRightWall();
041 makePaddle();
042 makeBall();
043 makeBall2();
044 makeTracker();
045 makeTracker2();
046 makefloor();
047 makeBricks1();
048 score=this assignment operator makes the left side equal to the right side0;
049 lives=this assignment operator makes the left side equal to the right side5;
050 setHelpText ("<h1>Breakout</h1)" +adds two numbers together or concatenates Strings together
051 "<br><br>Hit bricks with the ball to remove from screen.<br><br> Enjoy!");
052
053 }close braces end code blocks and must match an earlier open brace
054
055 classclass is a group of fields and methods used for making objects TimeUpdater implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
056 {open braces start code blocks and must be matched with a close brace
057 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
058 {open braces start code blocks and must be matched with a close brace
059 timeLeft--this is the decrement operator, which decreases the variable by 1;
060 updateTimer();
061 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
062 {open braces start code blocks and must be matched with a close brace
063 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
064 }close braces end code blocks and must match an earlier open brace
065 elseelse is what happens when the if condition is false
066 {open braces start code blocks and must be matched with a close brace
067 makeBricks2();
068
069 }close braces end code blocks and must match an earlier open brace
070 }close braces end code blocks and must match an earlier open brace
071 }close braces end code blocks and must match an earlier open brace
072
073 /**makes the sprites*/
074 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
075 {open braces start code blocks and must be matched with a close brace
076 scoreSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score: "+adds two numbers together or concatenates Strings togetherscore);
077 scoreSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score: 700");
078 scoreSprite.setScale(0.2);
079 scoreSprite.rightJustify();
080 scoreSprite.setColor(Color.BLUE);
081 scoreSprite.setLocation(.89, .85);
082 /*Adds score to the game.*/
083
084 livesSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Lives: "+adds two numbers together or concatenates Strings togetherlives);
085 livesSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Lives: 5");
086 livesSprite.setScale(0.19);
087 livesSprite.setColor(Color.GREEN);
088 livesSprite.setLocation(.19, .85);
089 /*Adds lives to the game.*/
090
091
092
093
094 gameOver=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("YOU LOSE");
095 gameOver.setScale(0.3);
096 gameOver.setColor(Color.BLUE);
097 gameOver.setLocation(.5, .5);
098 /*Lets player know that game is over.*/
099
100 timerSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
101 timerSprite.leftJustify();
102 timerSprite.topJustify();
103 timerSprite.setHeight(0.1);
104 timerSprite.setLocation(0, 0);
105
106
107 }close braces end code blocks and must match an earlier open brace
108
109 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks1()
110 {open braces start code blocks and must be matched with a close brace
111 intint is the type for whole numbers and it is short for integer index=this assignment operator makes the left side equal to the right side0;
112 bricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays25]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
113 intint is the type for whole numbers and it is short for integer numBricksHigh=this assignment operator makes the left side equal to the right side5;
114 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side.25;
115 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side1-startLocationY;
116 doubledouble is the type for numbers that can contain decimal fractions distanceHigh=this assignment operator makes the left side equal to the right sideendLocationY-startLocationY;
117 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer j=this assignment operator makes the left side equal to the right side0; j<numBricksHigh; j++this is the increment operator, which increases the variable by 1)
118 {open braces start code blocks and must be matched with a close brace
119 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sidej*distanceHigh/(numBricksHigh-1)+adds two numbers together or concatenates Strings togetherstartLocationY;
120
121 intint is the type for whole numbers and it is short for integer numBricksAcross=this assignment operator makes the left side equal to the right side5;
122 doubledouble is the type for numbers that can contain decimal fractions startLocationX=this assignment operator makes the left side equal to the right side0.1;
123 doubledouble is the type for numbers that can contain decimal fractions endLocationX=this assignment operator makes the left side equal to the right side1-startLocationX;
124 doubledouble is the type for numbers that can contain decimal fractions distanceAcross=this assignment operator makes the left side equal to the right sideendLocationX-startLocationX;
125 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<numBricksAcross; i++this is the increment operator, which increases the variable by 1)
126 {open braces start code blocks and must be matched with a close brace
127 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidei*distanceAcross/(numBricksAcross-1)+adds two numbers together or concatenates Strings togetherstartLocationX;
128 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 1);
129 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.055);
130 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(x,y/3.5);
131 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.BLUE);
132 canvas.addSprite(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
133 index++this is the increment operator, which increases the variable by 1;
134 /*Makes the bricks to add to the game.*/
135 }close braces end code blocks and must match an earlier open brace
136 }close braces end code blocks and must match an earlier open brace
137 }close braces end code blocks and must match an earlier open brace
138
139 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks2()
140 {open braces start code blocks and must be matched with a close brace
141 intint is the type for whole numbers and it is short for integer index=this assignment operator makes the left side equal to the right side0;
142 bricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays80]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
143 intint is the type for whole numbers and it is short for integer numBricksHigh=this assignment operator makes the left side equal to the right side8;
144 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side.25;
145 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side1-startLocationY;
146 doubledouble is the type for numbers that can contain decimal fractions distanceHigh=this assignment operator makes the left side equal to the right sideendLocationY-startLocationY;
147 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer j=this assignment operator makes the left side equal to the right side0; j<numBricksHigh; j++this is the increment operator, which increases the variable by 1)
148 {open braces start code blocks and must be matched with a close brace
149 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sidej*distanceHigh/(numBricksHigh-1)+adds two numbers together or concatenates Strings togetherstartLocationY;
150
151 intint is the type for whole numbers and it is short for integer numBricksAcross=this assignment operator makes the left side equal to the right side10;
152 doubledouble is the type for numbers that can contain decimal fractions startLocationX=this assignment operator makes the left side equal to the right side0.1;
153 doubledouble is the type for numbers that can contain decimal fractions endLocationX=this assignment operator makes the left side equal to the right side1-startLocationX;
154 doubledouble is the type for numbers that can contain decimal fractions distanceAcross=this assignment operator makes the left side equal to the right sideendLocationX-startLocationX;
155 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<numBricksAcross; i++this is the increment operator, which increases the variable by 1)
156 {open braces start code blocks and must be matched with a close brace
157 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidei*distanceAcross/(numBricksAcross-1)+adds two numbers together or concatenates Strings togetherstartLocationX;
158 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 1);
159 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.025);
160 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(x,y/3.5);
161 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.BLUE);
162 canvas.addSprite(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
163 index++this is the increment operator, which increases the variable by 1;
164 /*Makes the bricks to add to the game.*/
165 }close braces end code blocks and must match an earlier open brace
166 }close braces end code blocks and must match an earlier open brace
167 }close braces end code blocks and must match an earlier open brace
168
169
170
171 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeceiling()
172 {open braces start code blocks and must be matched with a close brace
173 ceiling =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(20, .5);
174 ceiling.setLocation(.5, .01);
175 ceiling.setColor(Color.GREEN);
176 canvas.addSprite(ceiling);
177 /*Makes ceiling to add to the game.*/
178 }close braces end code blocks and must match an earlier open brace
179
180 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeLeftWall()
181 {open braces start code blocks and must be matched with a close brace
182 leftWall =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 10);
183 leftWall.setLocation(startXCoord / 4.5, .5);
184 leftWall.setColor(Color.GREEN);
185 canvas.addSprite(leftWall);
186 /*Makes left wall to add to the game.*/
187 }close braces end code blocks and must match an earlier open brace
188
189 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeRightWall()
190 {open braces start code blocks and must be matched with a close brace
191 rightWall =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 10);
192 rightWall.setLocation(1 - startXCoord / 4.5, .5);
193 rightWall.setColor(Color.GREEN);
194 canvas.addSprite(rightWall);
195 /*Makes right wall to add to the game.*/
196 }close braces end code blocks and must match an earlier open brace
197
198 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makefloor()
199 {open braces start code blocks and must be matched with a close brace
200 floor =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(20,.5);
201 floor.setLocation(.5, .99);
202 floor.setColor(Color.RED);
203 canvas.addSprite(floor);
204 /*Makes floor of the game.*/
205 }close braces end code blocks and must match an earlier open brace
206
207 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makePaddle()
208 {open braces start code blocks and must be matched with a close brace
209 paddle =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(5, .5);
210 paddle.setLocation(.5, .8);
211 paddle.setScale(.25);
212 paddle.setColor(Color.BLACK);
213 canvas.addSprite(paddle);
214 /*Makes paddle to add to game.*/
215 }close braces end code blocks and must match an earlier open brace
216
217 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBall()
218 {open braces start code blocks and must be matched with a close brace
219 ball =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 1);
220 ball.setLocation(.5, .5599);
221 ball.setScale(.02);
222 ball.setColor(Color.BLACK);
223 canvas.addSprite(ball);
224 /*Makes ball to add to game.*/
225 }close braces end code blocks and must match an earlier open brace
226
227 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBall2()
228 {open braces start code blocks and must be matched with a close brace
229 ball2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 1);
230 ball2.setLocation(.5, .7799);
231 ball2.setScale(.02);
232 ball2.setColor(Color.BLACK);
233
234 /*Makes ball to add to game.*/
235 }close braces end code blocks and must match an earlier open brace
236
237
238 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value randomColorBound()
239 {open braces start code blocks and must be matched with a close brace
240 ball.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
241 ball2.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
242 paddle.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
243 rightWall.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
244 leftWall.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
245 ceiling.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
246 /*Makes the ball and paddle random colors.*/
247 }close braces end code blocks and must match an earlier open brace
248
249 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
250 {open braces start code blocks and must be matched with a close brace
251 tracker=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ProjectileTracker(0.25,-.25);
252 ball.setTracker(tracker);
253
254 /*Makes tracker forfor is a looping structure for repeatedly executing a block of code the ball.*/
255 }close braces end code blocks and must match an earlier open brace
256
257 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker2()
258 {open braces start code blocks and must be matched with a close brace
259 tracker2=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ProjectileTracker(0.25,-.25);
260 ball2.setTracker(tracker2);
261
262 /*Makes tracker forfor is a looping structure for repeatedly executing a block of code the ball.*/
263 }close braces end code blocks and must match an earlier open brace
264
265 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value wallBounce()
266 {open braces start code blocks and must be matched with a close brace
267 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
268 {open braces start code blocks and must be matched with a close brace
269 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(paddle.getShape(), ball.getShape());
270 tracker.bounce(normal);
271 /*Makes ball bounce off of paddle.*/
272 }close braces end code blocks and must match an earlier open brace
273
274 ifif executes the next statement only if the condition in parenthesis evaluates to true((rightWall.intersects(ball)))
275 {open braces start code blocks and must be matched with a close brace
276 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(rightWall.getShape(), ball.getShape());
277 tracker.bounce(normal);
278 /*Makes ball bounce off right wall.*/
279 }close braces end code blocks and must match an earlier open brace
280
281 ifif executes the next statement only if the condition in parenthesis evaluates to true((leftWall.intersects(ball)))
282 {open braces start code blocks and must be matched with a close brace
283 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(leftWall.getShape(), ball.getShape());
284 tracker.bounce(normal);
285 /*Makes ball bounce off left wall.*/
286 }close braces end code blocks and must match an earlier open brace
287
288 ifif executes the next statement only if the condition in parenthesis evaluates to true((ceiling.intersects(ball)))
289 {open braces start code blocks and must be matched with a close brace
290 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(ceiling.getShape(), ball.getShape());
291 tracker.bounce(normal);
292 /*ball bounce off ceiling.*/
293 }close braces end code blocks and must match an earlier open brace
294
295 }close braces end code blocks and must match an earlier open brace
296
297
298 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value wallBounce2()
299 {open braces start code blocks and must be matched with a close brace
300
301 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball2))
302 {open braces start code blocks and must be matched with a close brace
303 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(paddle.getShape(), ball2.getShape());
304 tracker2.bounce(normal);
305 /*Makes ball bounce off of paddle.*/
306 }close braces end code blocks and must match an earlier open brace
307
308 ifif executes the next statement only if the condition in parenthesis evaluates to true((rightWall.intersects(ball2)))
309 {open braces start code blocks and must be matched with a close brace
310 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(rightWall.getShape(), ball2.getShape());
311 tracker2.bounce(normal);
312 /*Makes ball bounce off right wall.*/
313 }close braces end code blocks and must match an earlier open brace
314
315 ifif executes the next statement only if the condition in parenthesis evaluates to true((leftWall.intersects(ball2)))
316 {open braces start code blocks and must be matched with a close brace
317 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(leftWall.getShape(), ball2.getShape());
318 tracker2.bounce(normal);
319 /*Makes ball bounce off left wall.*/
320 }close braces end code blocks and must match an earlier open brace
321
322 ifif executes the next statement only if the condition in parenthesis evaluates to true((ceiling.intersects(ball2)))
323 {open braces start code blocks and must be matched with a close brace
324 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(ceiling.getShape(), ball2.getShape());
325 tracker2.bounce(normal);
326 /*ball bounce off ceiling.*/
327 }close braces end code blocks and must match an earlier open brace
328 }close braces end code blocks and must match an earlier open brace
329
330 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value brickIntersects()
331 {open braces start code blocks and must be matched with a close brace
332
333 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<bricks.length; i++this is the increment operator, which increases the variable by 1)
334 {open braces start code blocks and must be matched with a close brace
335
336 ifif executes the next statement only if the condition in parenthesis evaluates to true((bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(ball) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) canvas.containsSprite(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays)))
337 {open braces start code blocks and must be matched with a close brace
338 score++this is the increment operator, which increases the variable by 1;
339 score +=this increases the variable on the left by the value on the right 9;
340 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same1)
341 {open braces start code blocks and must be matched with a close brace
342 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getShape(), ball.getShape());
343 tracker.bounce(normal);
344 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(falsefalse is a value for the boolean type and means not true);
345 }close braces end code blocks and must match an earlier open brace
346 elseelse is what happens when the if condition is false
347 {open braces start code blocks and must be matched with a close brace
348 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getShape(), ball.getShape());
349 tracker.bounce(normal);
350 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(falsefalse is a value for the boolean type and means not true);
351
352 }close braces end code blocks and must match an earlier open brace
353
354 }close braces end code blocks and must match an earlier open brace
355 }close braces end code blocks and must match an earlier open brace
356
357
358 }close braces end code blocks and must match an earlier open brace
359
360 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value brickIntersects2()
361 {open braces start code blocks and must be matched with a close brace
362
363 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<bricks.length; i++this is the increment operator, which increases the variable by 1)
364 {open braces start code blocks and must be matched with a close brace
365
366 ifif executes the next statement only if the condition in parenthesis evaluates to true((bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.isVisible() &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(ball2) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) canvas.containsSprite(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays)))
367 {open braces start code blocks and must be matched with a close brace
368 score++this is the increment operator, which increases the variable by 1;
369 score +=this increases the variable on the left by the value on the right 9;
370 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same2)
371 {open braces start code blocks and must be matched with a close brace
372 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getShape(), ball2.getShape());
373 tracker2.bounce(normal);
374 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(falsefalse is a value for the boolean type and means not true);
375 }close braces end code blocks and must match an earlier open brace
376 elseelse is what happens when the if condition is false
377 {open braces start code blocks and must be matched with a close brace
378 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getShape(), ball2.getShape());
379 tracker2.bounce(normal);
380 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setVisible(falsefalse is a value for the boolean type and means not true);
381
382 }close braces end code blocks and must match an earlier open brace
383
384 }close braces end code blocks and must match an earlier open brace
385 }close braces end code blocks and must match an earlier open brace
386
387
388 }close braces end code blocks and must match an earlier open brace
389
390
391
392
393
394 /**adds the Sprites to the screen*/
395 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
396 {open braces start code blocks and must be matched with a close brace
397 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
398 }close braces end code blocks and must match an earlier open brace
399 /*Adds the score.*/
400 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateLives()
401 {open braces start code blocks and must be matched with a close brace
402 livesSprite.setText("Lives: "+adds two numbers together or concatenates Strings togetherlives);
403 }close braces end code blocks and must match an earlier open brace
404 /*Adds the lives.*/
405
406 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
407 {open braces start code blocks and must be matched with a close brace
408 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
409 }close braces end code blocks and must match an earlier open brace
410
411 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
412 {open braces start code blocks and must be matched with a close brace
413 canvas.addSprite(scoreSprite);
414 canvas.addSprite(livesSprite);
415
416 }close braces end code blocks and must match an earlier open brace
417 /*Adds the score and lives to the game.*/
418
419 /**handle input and game events*/
420
421 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value resetGame()
422 {open braces start code blocks and must be matched with a close brace
423 ifif executes the next statement only if the condition in parenthesis evaluates to true(lives==this is the comparison operator which evaluates to true if both sides are the same0)
424 {open braces start code blocks and must be matched with a close brace
425 canvas.addSprite(gameOver);
426 }close braces end code blocks and must match an earlier open brace
427 }close braces end code blocks and must match an earlier open brace
428
429 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bonus()
430 {open braces start code blocks and must be matched with a close brace
431 ifif executes the next statement only if the condition in parenthesis evaluates to true(score==this is the comparison operator which evaluates to true if both sides are the same260 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) level==this is the comparison operator which evaluates to true if both sides are the same1)
432 {open braces start code blocks and must be matched with a close brace
433 level=this assignment operator makes the left side equal to the right side2;
434 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(),0);
435 canvas.addSprite(ball2);
436 }close braces end code blocks and must match an earlier open brace
437 ifif executes the next statement only if the condition in parenthesis evaluates to true(score==this is the comparison operator which evaluates to true if both sides are the same200)
438 {open braces start code blocks and must be matched with a close brace
439 lives=this assignment operator makes the left side equal to the right sidelives+adds two numbers together or concatenates Strings together1;
440 score=this assignment operator makes the left side equal to the right sidescore+adds two numbers together or concatenates Strings together10;
441 }close braces end code blocks and must match an earlier open brace
442 ifif executes the next statement only if the condition in parenthesis evaluates to true(score==this is the comparison operator which evaluates to true if both sides are the same400)
443 {open braces start code blocks and must be matched with a close brace
444 lives=this assignment operator makes the left side equal to the right sidelives+adds two numbers together or concatenates Strings together1;
445 score=this assignment operator makes the left side equal to the right sidescore+adds two numbers together or concatenates Strings together10;
446 }close braces end code blocks and must match an earlier open brace
447 updateLives();
448 updateScore();
449
450
451
452
453 }close braces end code blocks and must match an earlier open brace
454 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advanceFrame(doubledouble is the type for numbers that can contain decimal fractions timePassed)
455 {open braces start code blocks and must be matched with a close brace
456
457 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getLocation().x;
458 paddle.setLocation(x,paddle.getLocation().y);
459 wallBounce();
460 wallBounce2();
461 brickIntersects();
462 brickIntersects2();
463 randomColorBound(); //Jayson Helped.
464 resetGame();
465 bonus();
466 /*Game Cheat.*/
467 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getKeyboard().getLastKey()==this is the comparison operator which evaluates to true if both sides are the same'v')
468 {open braces start code blocks and must be matched with a close brace
469 score=this assignment operator makes the left side equal to the right side260;
470 canvas.removeSprite(bricks);
471
472 }close braces end code blocks and must match an earlier open brace
473
474 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getKeyboard().getLastKey()==this is the comparison operator which evaluates to true if both sides are the same'l')
475 {open braces start code blocks and must be matched with a close brace
476 lives=this assignment operator makes the left side equal to the right sidelives+adds two numbers together or concatenates Strings together1;
477 }close braces end code blocks and must match an earlier open brace
478
479 ifif executes the next statement only if the condition in parenthesis evaluates to true (lives ==this is the comparison operator which evaluates to true if both sides are the same 1 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) floor.intersects(ball))
480 {open braces start code blocks and must be matched with a close brace
481 lives--this is the decrement operator, which decreases the variable by 1;
482 }close braces end code blocks and must match an earlier open brace
483 ifif executes the next statement only if the condition in parenthesis evaluates to true(floor.intersects(ball) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) lives > 1)
484 {open braces start code blocks and must be matched with a close brace
485 lives--this is the decrement operator, which decreases the variable by 1;
486 ball.setLocation(.5,.6);
487 }close braces end code blocks and must match an earlier open brace
488 updateLives();
489
490 }close braces end code blocks and must match an earlier open brace
491 /*Subtract lives everytime the ball drops below the floor.*/
492 }close braces end code blocks and must match an earlier open brace
|