|
001 packagepackage is used to name the directory or folder a class is in HemendraPavitra;
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 Ppullay,Hpullay
011 * Enhancements:
012 * 1. Curved Walls
013 * 2. Timer: Adds 30 seconds at score equal at 40
014 * 3. Two balls: Added on the second level
015 * 4. Second Level: Two ball playing at the same time and a fifth row
016 * 5. Sound when ball hits bricks
017 */
018 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
019 {open braces start code blocks and must be matched with a close brace
020 /**a rectangle*/
021 privateprivate is used to restrict access to the current class only Sprite rectangle, topCeiling, leftWall, leftWall1, rightWall,rightWall1, gameFloor;
022 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions startYCoord, startXCoord;
023 privateprivate is used to restrict access to the current class only Sprite paddle, ball, ball2;
024 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
025 privateprivate is used to restrict access to the current class only ProjectileTracker tracker1;
026 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer level;
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, glevel=this assignment operator makes the left side equal to the right side1;
029 privateprivate is used to restrict access to the current class only StringSprite scoreSprite, livesSprite, gameOver, youWin,txtBonusLives;
030 Sound tick=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Mouse1.wav"));
031 Sound boo=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Boo.wav"));
032 Sound applause=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Applause2.wav"));
033 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer timeLeft=this assignment operator makes the left side equal to the right side200;
034 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
035
036 /**sets up the game*/
037 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
038 {open braces start code blocks and must be matched with a close brace
039 removeCursor();
040 makeSprites();
041 addSprites();
042 makeBricks();
043 maketopCeiling();
044 makeLeftWall();
045 makeLeftWall1();
046 makeRightWall();
047 makeRightWall1();
048 makePaddle();
049 makeBall();
050 makeBall2();
051 makeTracker();
052 makeGameFloor();
053 addTime();
054 score=this assignment operator makes the left side equal to the right side0;
055 lives=this assignment operator makes the left side equal to the right side5;
056 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
057 setHelpText ("<h1>Breakout</h1)" +adds two numbers together or concatenates Strings together
058 "<br><br>Hit bricks with the ball to remove from screen.<br><br> Enjoy!");
059
060 }close braces end code blocks and must match an earlier open brace
061
062 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
063 {open braces start code blocks and must be matched with a close brace
064 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
065 {open braces start code blocks and must be matched with a close brace
066 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 same57)
067 {open braces start code blocks and must be matched with a close brace
068 timeLeft=this assignment operator makes the left side equal to the right sidetimeLeft;
069 }close braces end code blocks and must match an earlier open brace
070 timeLeft--this is the decrement operator, which decreases the variable by 1;
071 updateTimer();
072 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
073 {open braces start code blocks and must be matched with a close brace
074 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
075 }close braces end code blocks and must match an earlier open brace
076 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft==this is the comparison operator which evaluates to true if both sides are the same0)
077 {open braces start code blocks and must be matched with a close brace
078 canvas.addSprite(gameOver);
079 }close braces end code blocks and must match an earlier open brace
080 }close braces end code blocks and must match an earlier open brace
081 }close braces end code blocks and must match an earlier open brace
082
083 /**makes the sprites*/
084 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
085 {open braces start code blocks and must be matched with a close brace
086 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);
087 scoreSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score: 0");
088 scoreSprite.setScale(0.2);
089 scoreSprite.rightJustify();
090 scoreSprite.setColor(Color.GREEN);
091 scoreSprite.setLocation(.9, .95);
092 /*Adds score to the game.*/
093
094 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);
095 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");
096 livesSprite.setScale(0.18);
097 livesSprite.setColor(Color.GREEN);
098 livesSprite.setLocation(.2, .95);
099 /*Adds lives to the game.*/
100
101 gameOver=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Game Over: You Lose!!");
102 gameOver.setScale(0.3);
103 gameOver.setColor(Color.RED);
104 gameOver.setLocation(.5, .5);
105 /*Lets player know that game is over.*/
106
107 youWin=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Winner!!");
108 youWin.setScale(0.3);
109 youWin.setColor(Color.RED);
110 youWin.setLocation(.5, .5);
111 /*Lets player know that they won the game.*/
112
113 txtBonusLives=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Bonus Lives & Points!!");
114 txtBonusLives.setScale(0.3);
115 txtBonusLives.setColor(Color.RED);
116 txtBonusLives.setLocation(.5, .90);
117 /**Lets player know when they receive bonus lives and points*/
118
119 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);
120 timerSprite.setScale(.23);
121 timerSprite.setColor(Color.GREEN);
122 timerSprite.setLocation(.5, .96);
123 /**Lets player know how much time they have left*/
124 }close braces end code blocks and must match an earlier open brace
125
126 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks()
127 {open braces start code blocks and must be matched with a close brace
128 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;
129 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) arrays56]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
130 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 side4;
131 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;
132 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;
133 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;
134 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)
135 {open braces start code blocks and must be matched with a close brace
136 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;
137
138 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 side14;
139 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;
140 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;
141 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;
142 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)
143 {open braces start code blocks and must be matched with a close brace
144 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;
145 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);
146 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);
147 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);
148 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.RED);
149 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);
150 index++this is the increment operator, which increases the variable by 1;
151 /*Makes the bricks to add to the game.*/
152 }close braces end code blocks and must match an earlier open brace
153 }close braces end code blocks and must match an earlier open brace
154 }close braces end code blocks and must match an earlier open brace
155
156 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks2()
157 {open braces start code blocks and must be matched with a close brace
158 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;
159 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) arrays70]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
160 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;
161 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;
162 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;
163 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;
164 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)
165 {open braces start code blocks and must be matched with a close brace
166 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;
167
168 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 side14;
169 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;
170 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;
171 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;
172 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)
173 {open braces start code blocks and must be matched with a close brace
174 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;
175 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);
176 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);
177 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);
178 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);
179 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);
180 index++this is the increment operator, which increases the variable by 1;
181 /*Makes the bricks to add to the game.*/
182 }close braces end code blocks and must match an earlier open brace
183 }close braces end code blocks and must match an earlier open brace
184 }close braces end code blocks and must match an earlier open brace
185
186 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value maketopCeiling()
187 {open braces start code blocks and must be matched with a close brace
188 topCeiling =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(20, 1);
189 topCeiling.setLocation(.5, .001);
190 topCeiling.setColor(Color.RED);
191 canvas.addSprite(topCeiling);
192 /*Makes ceiling to add to the game.*/
193 }close braces end code blocks and must match an earlier open brace
194
195 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeLeftWall()
196 {open braces start code blocks and must be matched with a close brace
197 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);
198 leftWall.setLocation(startXCoord / 4.5, .12);
199 leftWall.setColor(Color.RED);
200 canvas.addSprite(leftWall);
201 /*Makes left wall to add to the game.*/
202 }close braces end code blocks and must match an earlier open brace
203
204 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeLeftWall1()
205 {open braces start code blocks and must be matched with a close brace
206 leftWall1 =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);
207 leftWall1.setLocation(startXCoord / 4.5, .88);
208 leftWall1.setColor(Color.RED);
209 canvas.addSprite(leftWall1);
210 /*Makes second left wall to add to the game.*/
211 }close braces end code blocks and must match an earlier open brace
212
213 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeRightWall()
214 {open braces start code blocks and must be matched with a close brace
215 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);
216 rightWall.setLocation(1 - startXCoord / 4.5, .12);
217 rightWall.setColor(Color.RED);
218 canvas.addSprite(rightWall);
219 /*Makes right wall to add to the game.*/
220 }close braces end code blocks and must match an earlier open brace
221
222 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeRightWall1()
223 {open braces start code blocks and must be matched with a close brace
224 rightWall1 =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);
225 rightWall1.setLocation(1 - startXCoord / 4.5, .88);
226 rightWall1.setColor(Color.RED);
227 canvas.addSprite(rightWall1);
228 /*Makes right wall to add to the game.*/
229 }close braces end code blocks and must match an earlier open brace
230
231 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeGameFloor()
232 {open braces start code blocks and must be matched with a close brace
233 gameFloor =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);
234 gameFloor.setLocation(.5, .99);
235 gameFloor.setColor(Color.BLACK);
236 canvas.addSprite(gameFloor);
237 /*Makes floor to add to the game.*/
238 }close braces end code blocks and must match an earlier open brace
239
240 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makePaddle()
241 {open braces start code blocks and must be matched with a close brace
242 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);
243 paddle.setLocation(.5, .8);
244 paddle.setScale(.15);
245 paddle.setColor(Color.BLACK);
246 canvas.addSprite(paddle);
247 tick.play();
248 /*Makes paddle to add to game.*/
249 }close braces end code blocks and must match an earlier open brace
250
251 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBall()
252 {open braces start code blocks and must be matched with a close brace
253 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);
254 ball.setLocation(.5, .7799);
255 ball.setScale(.02);
256 ball.setColor(Color.BLACK);
257 canvas.addSprite(ball);
258 /*Makes ball to add to game.*/
259 }close braces end code blocks and must match an earlier open brace
260
261 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBall2()
262 {open braces start code blocks and must be matched with a close brace
263 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);
264 ball2.setLocation(.5, .7799);
265 ball2.setScale(.02);
266 ball2.setColor(Color.BLACK);
267 /*Makes ball to add to game.*/
268 }close braces end code blocks and must match an earlier open brace
269
270 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
271 {open braces start code blocks and must be matched with a close brace
272 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
273 }close braces end code blocks and must match an earlier open brace
274
275 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value randomColorBound()
276 {open braces start code blocks and must be matched with a close brace
277 ball.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
278 paddle.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
279 ball2.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
280 /*Makes the ball and paddle random colors.*/
281 }close braces end code blocks and must match an earlier open brace
282
283 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
284 {open braces start code blocks and must be matched with a close brace
285 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.30,-.30);
286 ball.setTracker(tracker);
287 tracker1=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);
288 ball2.setTracker(tracker1);
289 /*Makes tracker forfor is a looping structure for repeatedly executing a block of code the ball.*/
290 }close braces end code blocks and must match an earlier open brace
291
292 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value wallBounce()
293 {open braces start code blocks and must be matched with a close brace
294 ifif executes the next statement only if the condition in parenthesis evaluates to true(ball.intersects(ball2))
295 {open braces start code blocks and must be matched with a close brace
296 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());
297 tracker.bounce(normal);
298 tick.play();
299 /*Makes ball bounce off of paddle.*/
300 }close braces end code blocks and must match an earlier open brace
301 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
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(), ball.getShape());
304 tracker.bounce(normal);
305 tick.play();
306 /*Makes ball bounce off of paddle.*/
307 }close braces end code blocks and must match an earlier open brace
308
309 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightWall.intersects(ball))
310 {open braces start code blocks and must be matched with a close brace
311 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());
312 tracker.bounce(normal);
313 tick.play();
314 /*Makes ball bounce off right wall.*/
315 }close braces end code blocks and must match an earlier open brace
316
317
318 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightWall1.intersects(ball))
319 {open braces start code blocks and must be matched with a close brace
320 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(rightWall1.getShape(), ball.getShape());
321 tracker.bounce(normal);
322 tick.play();
323 /*Makes ball bounce off right wall.*/
324 }close braces end code blocks and must match an earlier open brace
325
326 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftWall.intersects(ball))
327 {open braces start code blocks and must be matched with a close brace
328 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());
329 tracker.bounce(normal);
330 tick.play();
331 /*Makes ball bounce off left wall.*/
332 }close braces end code blocks and must match an earlier open brace
333
334 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftWall1.intersects(ball))
335 {open braces start code blocks and must be matched with a close brace
336 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(leftWall1.getShape(), ball.getShape());
337 tracker.bounce(normal);
338 tick.play();
339 /*Makes ball bounce off left wall.*/
340 }close braces end code blocks and must match an earlier open brace
341
342 ifif executes the next statement only if the condition in parenthesis evaluates to true(topCeiling.intersects(ball))
343 {open braces start code blocks and must be matched with a close brace
344 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(topCeiling.getShape(), ball.getShape());
345 tracker.bounce(normal);
346 tick.play();
347 /*Makes ball bounce off of top ceiling.*/
348 }close braces end code blocks and must match an earlier open brace
349 }close braces end code blocks and must match an earlier open brace
350 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value ballBounce2()
351 {open braces start code blocks and must be matched with a close brace
352 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball2))
353 {open braces start code blocks and must be matched with a close brace
354 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());
355 tracker1.bounce(normal);
356 tick.play();
357 /*Makes ball bounce off of paddle.*/
358 }close braces end code blocks and must match an earlier open brace
359
360 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightWall.intersects(ball2))
361 {open braces start code blocks and must be matched with a close brace
362 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());
363 tracker1.bounce(normal);
364 tick.play();
365 /*Makes ball bounce off right wall.*/
366 }close braces end code blocks and must match an earlier open brace
367
368
369 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightWall1.intersects(ball2))
370 {open braces start code blocks and must be matched with a close brace
371 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(rightWall1.getShape(), ball2.getShape());
372 tracker1.bounce(normal);
373 tick.play();
374 /*Makes ball bounce off right wall.*/
375 }close braces end code blocks and must match an earlier open brace
376
377 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftWall.intersects(ball2))
378 {open braces start code blocks and must be matched with a close brace
379 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());
380 tracker1.bounce(normal);
381 tick.play();
382 /*Makes ball bounce off left wall.*/
383 }close braces end code blocks and must match an earlier open brace
384
385 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftWall1.intersects(ball2))
386 {open braces start code blocks and must be matched with a close brace
387 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(leftWall1.getShape(), ball2.getShape());
388 tracker1.bounce(normal);
389 tick.play();
390 /*Makes ball bounce off left wall.*/
391 }close braces end code blocks and must match an earlier open brace
392
393 ifif executes the next statement only if the condition in parenthesis evaluates to true(topCeiling.intersects(ball2))
394 {open braces start code blocks and must be matched with a close brace
395 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(topCeiling.getShape(), ball2.getShape());
396 tracker1.bounce(normal);
397 tick.play();
398 /*Makes ball bounce off of top ceiling.*/
399 }close braces end code blocks and must match an earlier open brace
400 }close braces end code blocks and must match an earlier open brace
401
402 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value brickIntersects() //help from Blake.
403 {open braces start code blocks and must be matched with a close brace
404 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)
405 {open braces start code blocks and must be matched with a close brace
406 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))
407 {open braces start code blocks and must be matched with a close brace
408 score++this is the increment operator, which increases the variable by 1;
409 tick.play();
410 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 same0)
411 {open braces start code blocks and must be matched with a close brace
412 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());
413 tracker.bounce(normal);
414 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);
415 }close braces end code blocks and must match an earlier open brace
416 elseelse is what happens when the if condition is false
417 {open braces start code blocks and must be matched with a close brace
418 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());
419 tracker.bounce(normal);
420 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);
421 }close braces end code blocks and must match an earlier open brace
422 }close braces end code blocks and must match an earlier open brace
423 }close braces end code blocks and must match an earlier open brace
424 /*Increases score ifif executes the next statement only if the condition in parenthesis evaluates to true ball intersects brick.*/
425 updateScore();
426 }close braces end code blocks and must match an earlier open brace
427
428 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value brickIntersects2() //help from Blake.
429 {open braces start code blocks and must be matched with a close brace
430 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)
431 {open braces start code blocks and must be matched with a close brace
432 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))
433 {open braces start code blocks and must be matched with a close brace
434 score++this is the increment operator, which increases the variable by 1;
435 tick.play();
436 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 same0)
437 {open braces start code blocks and must be matched with a close brace
438 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());
439 tracker1.bounce(normal);
440 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);
441 }close braces end code blocks and must match an earlier open brace
442 elseelse is what happens when the if condition is false
443 {open braces start code blocks and must be matched with a close brace
444 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());
445 tracker1.bounce(normal);
446 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);
447 }close braces end code blocks and must match an earlier open brace
448 }close braces end code blocks and must match an earlier open brace
449 }close braces end code blocks and must match an earlier open brace
450 /*Increases score ifif executes the next statement only if the condition in parenthesis evaluates to true ball intersects brick.*/
451 updateScore();
452 }close braces end code blocks and must match an earlier open brace
453
454 /**adds the sprites to the screen*/
455 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
456 {open braces start code blocks and must be matched with a close brace
457 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
458 }close braces end code blocks and must match an earlier open brace
459 /*Adds the score.*/
460 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateLives()
461 {open braces start code blocks and must be matched with a close brace
462 livesSprite.setText("Lives: "+adds two numbers together or concatenates Strings togetherlives);
463 }close braces end code blocks and must match an earlier open brace
464 /*Adds the lives.*/
465 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
466 {open braces start code blocks and must be matched with a close brace
467 canvas.addSprite(scoreSprite);
468 canvas.addSprite(livesSprite);
469 canvas.addSprite(timerSprite);
470 }close braces end code blocks and must match an earlier open brace
471 /*Adds the score and lives to the game.*/
472
473 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value youLose()
474 {open braces start code blocks and must be matched with a close brace
475 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) ||this is boolean or, meaning if either or both are true then the result is true (timeLeft==this is the comparison operator which evaluates to true if both sides are the same0))
476 {open braces start code blocks and must be matched with a close brace
477 canvas.addSprite(gameOver);
478 canvas.removeSprite(ball);
479 }close braces end code blocks and must match an earlier open brace
480 }close braces end code blocks and must match an earlier open brace
481 /**Let's you know that Game is over once the number of lives is equal to zero or time is equal to zero.*/
482 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value winGame()
483 {open braces start code blocks and must be matched with a close brace
484 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 same127)
485 {open braces start code blocks and must be matched with a close brace
486 canvas.addSprite(youWin);
487 canvas.removeSprite(ball);
488 canvas.removeSprite(paddle);
489 applause.play();
490 }close braces end code blocks and must match an earlier open brace
491 }close braces end code blocks and must match an earlier open brace
492 /*gives play a bonus life ifif executes the next statement only if the condition in parenthesis evaluates to true they achieve a score of 20*/
493
494 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addTime()
495 {open braces start code blocks and must be matched with a close brace
496 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 same45 &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 &&) timeLeft<35)
497 {open braces start code blocks and must be matched with a close brace
498 timeLeft=this assignment operator makes the left side equal to the right sidetimeLeft+adds two numbers together or concatenates Strings together35;
499 }close braces end code blocks and must match an earlier open brace
500 }close braces end code blocks and must match an earlier open brace
501
502 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bonusLives()
503 {open braces start code blocks and must be matched with a close brace
504 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 same57 &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 &&) glevel==this is the comparison operator which evaluates to true if both sides are the same1)
505 {open braces start code blocks and must be matched with a close brace
506 glevel=this assignment operator makes the left side equal to the right side2;
507 makeBricks2();
508 canvas.addSprite(ball2);
509 }close braces end code blocks and must match an earlier open brace
510 /**Adds the second ball to the game at level two*/
511 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 same40)
512 {open braces start code blocks and must be matched with a close brace
513 lives=this assignment operator makes the left side equal to the right sidelives+adds two numbers together or concatenates Strings together2;
514 score=this assignment operator makes the left side equal to the right sidescore+adds two numbers together or concatenates Strings together1;
515 canvas.addSprite(txtBonusLives);
516 applause.play();
517 }close braces end code blocks and must match an earlier open brace
518 /**Adds life and score to game whilewhile is a looping structure for executing code repeatedly playing a sound and adding text letting player knows they received a bonus*/
519 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 same45)
520 {open braces start code blocks and must be matched with a close brace
521 canvas.removeSprite(txtBonusLives);
522 }close braces end code blocks and must match an earlier open brace
523 updateLives();
524 /**Removes text letting player know that they have received a bonus*/
525 }close braces end code blocks and must match an earlier open brace
526
527 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)
528 {open braces start code blocks and must be matched with a close brace
529 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
530 {open braces start code blocks and must be matched with a close brace
531 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;
532 paddle.setLocation(x,paddle.getLocation().y);
533 wallBounce();
534 ballBounce2();
535 brickIntersects();
536 brickIntersects2();
537 randomColorBound(); //Got help from Jayson.
538 bonusLives();
539 addTime();
540 youLose();
541 winGame();
542 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')
543 {open braces start code blocks and must be matched with a close brace
544 score=this assignment operator makes the left side equal to the right side57;
545 canvas.removeSprite(bricks); //got help from Blake.
546 }close braces end code blocks and must match an earlier open brace
547 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'g')
548 {open braces start code blocks and must be matched with a close brace
549 score=this assignment operator makes the left side equal to the right side127;
550 canvas.removeSprite(bricks); //got help from Blake.
551 canvas.removeSprite(ball);
552 canvas.removeSprite(ball2);
553 }close braces end code blocks and must match an earlier open brace
554 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 &&) gameFloor.intersects(ball))
555 {open braces start code blocks and must be matched with a close brace
556 lives--this is the decrement operator, which decreases the variable by 1;
557 boo.play();
558 }close braces end code blocks and must match an earlier open brace
559 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 &&) gameFloor.intersects(ball2))
560 {open braces start code blocks and must be matched with a close brace
561 lives--this is the decrement operator, which decreases the variable by 1;
562 boo.play();
563 }close braces end code blocks and must match an earlier open brace
564 ifif executes the next statement only if the condition in parenthesis evaluates to true(gameFloor.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)
565 {open braces start code blocks and must be matched with a close brace
566 lives--this is the decrement operator, which decreases the variable by 1;
567 boo.play();
568 ball.setLocation(.5,.4);
569 }close braces end code blocks and must match an earlier open brace
570 ifif executes the next statement only if the condition in parenthesis evaluates to true(gameFloor.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 &&) lives > 1)
571 {open braces start code blocks and must be matched with a close brace
572 lives--this is the decrement operator, which decreases the variable by 1;
573 boo.play();
574 ball2.setLocation(.6,.5);
575 }close braces end code blocks and must match an earlier open brace
576
577 updateLives();
578 }close braces end code blocks and must match an earlier open brace
579
580 }close braces end code blocks and must match an earlier open brace
581 /*Subtract lives everytime the ball drops below the floor.*/
582 }close braces end code blocks and must match an earlier open brace
|