|
001 packagepackage is used to name the directory or folder a class is in GBell;
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 * Based on the well-known game "Breakout."
010 * @authorthis is the Javadoc tag for documenting who created the source code Gbell
011 */
012 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
013 {open braces start code blocks and must be matched with a close brace
014 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;
015 privateprivate is used to restrict access to the current class only Sprite leftBorder, rightBorder, topBorder, floor;
016 privateprivate is used to restrict access to the current class only Sprite paddle, paddleBase;
017 privateprivate is used to restrict access to the current class only Sprite ball;
018 privateprivate is used to restrict access to the current class only ProjectileTracker tracker, tracker2;
019 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer lives, score, trackScore, bricksLeft, difficulty;
020 privateprivate is used to restrict access to the current class only StringSprite gameover, restart, livesText, scoreText, win, start;
021 privateprivate is used to restrict access to the current class only Color color =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Color(150, 150, 150);
022 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false dead =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
023 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false gravity =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
024 privateprivate is used to restrict access to the current class only Point2D.Double initVelocity;
025 privateprivate is used to restrict access to the current class only StringSprite easy, hard, directions;
026
027 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
028 {open braces start code blocks and must be matched with a close brace
029 directions=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click to choose your difficulty.");
030 directions.setColor(Color.GREEN);
031 directions.setLocation(.5, .2);
032 directions.setScale(.9);
033 canvas.addSprite(directions);
034
035 easy=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Easy");
036 easy.setLocation(.25, .5);
037 easy.setScale(.3);
038 easy.setColor(Color.BLUE);
039 canvas.addSprite(easy);
040
041 hard=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Hard");
042 hard.setColor(Color.RED);
043 hard.setLocation(.75, .5);
044 hard.setScale(.3);
045 canvas.addSprite(hard);
046
047 toggleAudible();
048 pauseToggle();
049 difficulty=this assignment operator makes the left side equal to the right side-1;
050 }close braces end code blocks and must match an earlier open brace
051 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value lead()
052 {open braces start code blocks and must be matched with a close brace
053 gravity=this assignment operator makes the left side equal to the right sidefalsefalse is a value for the boolean type and means not true;
054 }close braces end code blocks and must match an earlier open brace
055 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)
056 {open braces start code blocks and must be matched with a close brace
057 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
058 ifif executes the next statement only if the condition in parenthesis evaluates to true(click!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &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 &&) easy.intersects(click))
059 {open braces start code blocks and must be matched with a close brace
060 difficulty=this assignment operator makes the left side equal to the right side0;
061 lives=this assignment operator makes the left side equal to the right side5;
062 canvas.removeAllSprites();
063 beginGame();
064 }close braces end code blocks and must match an earlier open brace
065
066 ifif executes the next statement only if the condition in parenthesis evaluates to true(click!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &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 &&) hard.intersects(click))
067 {open braces start code blocks and must be matched with a close brace
068 difficulty=this assignment operator makes the left side equal to the right side1;
069 lives=this assignment operator makes the left side equal to the right side3;
070 canvas.removeAllSprites();
071 beginGame();
072 }close braces end code blocks and must match an earlier open brace
073 ifif executes the next statement only if the condition in parenthesis evaluates to true(difficulty==this is the comparison operator which evaluates to true if both sides are the same1)
074 {open braces start code blocks and must be matched with a close brace
075 ifif executes the next statement only if the condition in parenthesis evaluates to true(tracker!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object)
076 {open braces start code blocks and must be matched with a close brace
077 ifif executes the next statement only if the condition in parenthesis evaluates to true(trackScore>4)
078 {open braces start code blocks and must be matched with a close brace
079 paddle.setColor(Color.BLUE);
080 ball.setColor(Color.BLUE);
081 gravity=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
082 }close braces end code blocks and must match an earlier open brace
083
084
085 ifif executes the next statement only if the condition in parenthesis evaluates to true(trackScore>12 &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 &&) gravity==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
086 {open braces start code blocks and must be matched with a close brace
087 paddle.setScale(.11);
088 paddleBase.setScale(.11);
089 paddleBase.setLocation(.5, .96);
090 paddle.setColor(Color.WHITE);
091 ball.setColor(Color.WHITE);
092 gravity=this assignment operator makes the left side equal to the right sidefalsefalse is a value for the boolean type and means not true;
093 }close braces end code blocks and must match an earlier open brace
094 ifif executes the next statement only if the condition in parenthesis evaluates to true(trackScore>20 &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 &&) gravity==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true)
095 {open braces start code blocks and must be matched with a close brace
096 gravity=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
097 }close braces end code blocks and must match an earlier open brace
098
099 ifif executes the next statement only if the condition in parenthesis evaluates to true(gravity==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false)
100 {open braces start code blocks and must be matched with a close brace
101 Point2D.Double velocity=this assignment operator makes the left side equal to the right sidetracker.getVelocity();
102 velocity.y+=this increases the variable on the left by the value on the right(.65*timePassed);
103 ifif executes the next statement only if the condition in parenthesis evaluates to true(velocity.y>1)
104 {open braces start code blocks and must be matched with a close brace
105 velocity.y=this assignment operator makes the left side equal to the right side1;
106 }close braces end code blocks and must match an earlier open brace
107 tracker.setVelocity(velocity);
108 }close braces end code blocks and must match an earlier open brace
109 }close braces end code blocks and must match an earlier open brace
110 }close braces end code blocks and must match an earlier open brace
111 ifif executes the next statement only if the condition in parenthesis evaluates to true(difficulty!=this is the not equals operator which evaluates to true if both sides are different-1)
112 {open braces start code blocks and must be matched with a close brace
113 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;
114 paddle.setLocation(x,paddle.getLocation().y);
115 paddleBase.setLocation(x,paddleBase.getLocation().y);
116
117 bounceOffWalls();
118 hitsBricks();
119 clickCommand();
120 playerDies();
121 }close braces end code blocks and must match an earlier open brace
122 }close braces end code blocks and must match an earlier open brace
123
124 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value beginGame()
125 {open braces start code blocks and must be matched with a close brace
126 score=this assignment operator makes the left side equal to the right side0;
127 bricksLeft=this assignment operator makes the left side equal to the right side50;
128 trackScore=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) arrays50]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
130 makeSprites();
131 makeBricks();
132 }close braces end code blocks and must match an earlier open brace
133
134 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
135 {open braces start code blocks and must be matched with a close brace
136 lead();
137 makeBall();
138 makePaddle();
139 makeTracker();
140 makeLivesAndScore();
141 makeBorders();
142 }close braces end code blocks and must match an earlier open brace
143 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBricks()
144 {open braces start code blocks and must be matched with a close brace
145 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;
146 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;
147 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side0.1;
148 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side.3;
149 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;
150 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)
151 {open braces start code blocks and must be matched with a close brace
152 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;
153
154 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;
155 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;
156 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;
157 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;
158
159 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)
160 {open braces start code blocks and must be matched with a close brace
161 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;
162 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.4, 1.25);
163 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(.085);
164 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);
165 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);
166 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);
167 index++this is the increment operator, which increases the variable by 1;
168 }close braces end code blocks and must match an earlier open brace
169 }close braces end code blocks and must match an earlier open brace
170 }close braces end code blocks and must match an earlier open brace
171
172 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBorders()
173 {open braces start code blocks and must be matched with a close brace
174 makeFloor();
175 makeLeftBorder();
176 makeRightBorder();
177 makeTopBorder();
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 makeLeftBorder()
181 {open braces start code blocks and must be matched with a close brace
182 leftBorder=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 40);
183 leftBorder.setLocation(0.015, 0.5);
184 leftBorder.setScale(1);
185 leftBorder.setColor(color);
186 canvas.addSprite(leftBorder);
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 makeRightBorder()
190 {open braces start code blocks and must be matched with a close brace
191 rightBorder=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 40);
192 rightBorder.setLocation(.985, 0.5);
193 rightBorder.setScale(1);
194 rightBorder.setColor(color);
195 canvas.addSprite(rightBorder);
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 makeTopBorder()
199 {open braces start code blocks and must be matched with a close brace
200 topBorder=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
201 topBorder.setLocation(0.5, 0);
202 topBorder.setScale(1);
203 topBorder.setColor(color);
204 canvas.addSprite(topBorder);
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 makeFloor()
208 {open braces start code blocks and must be matched with a close brace
209 floor=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
210 floor.setLocation(0.5, .96);
211 floor.setScale(1);
212 floor.setColor(Color.BLACK);
213 canvas.addSprite(floor);
214 }close braces end code blocks and must match an earlier open brace
215
216 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBall()
217 {open braces start code blocks and must be matched with a close brace
218 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
219 ball.setColor(Color.GREEN);
220 ball.setScale(.04);
221 ball.setLocation(.5, .8);
222 canvas.addSprite(ball);
223 }close braces end code blocks and must match an earlier open brace
224
225 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePaddle()
226 {open braces start code blocks and must be matched with a close brace
227 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(15, 2);
228 paddle.setColor(Color.GREEN);
229 paddle.setScale(.2);
230 paddle.setLocation(.5, .9);
231
232
233 paddleBase=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(15, 15);
234 paddleBase.setColor(Color.BLACK);
235 paddleBase.setScale(.2);
236 paddleBase.setLocation(.5, .99);
237 canvas.addSprite(paddleBase);
238 canvas.addSprite(paddle);
239 }close braces end code blocks and must match an earlier open brace
240
241 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
242 {open braces start code blocks and must be matched with a close brace
243 tracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(0.25, -.25);
244 ball.setTracker(tracker);
245 initVelocity=this assignment operator makes the left side equal to the right sidetracker.getVelocity();
246 }close braces end code blocks and must match an earlier open brace
247
248 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeLivesAndScore()
249 {open braces start code blocks and must be matched with a close brace
250 livesText =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Lives: " +adds two numbers together or concatenates Strings together lives);
251 livesText.setLocation(0.86, .05);
252 livesText.setColor(Color.WHITE);
253 livesText.setScale(0.16);
254 canvas.addSprite(livesText);
255
256 scoreText =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Score: "+adds two numbers together or concatenates Strings togetherscore);
257 scoreText.setLocation(0.14, .05);
258 scoreText.setColor(Color.WHITE);
259 scoreText.setScale(0.175);
260 canvas.addSprite(scoreText);
261 }close braces end code blocks and must match an earlier open brace
262
263 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value clickCommand()
264 {open braces start code blocks and must be matched with a close brace
265 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getMouse().getClickLocation()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object &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 &&) dead ==this is the comparison operator which evaluates to true if both sides are the same truetrue is the boolean value that is the opposite of false)
266 {open braces start code blocks and must be matched with a close brace
267 dead =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
268 resetGame();
269 }close braces end code blocks and must match an earlier open brace
270 }close braces end code blocks and must match an earlier open brace
271
272 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value playerDies()
273 {open braces start code blocks and must be matched with a close brace
274 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 &&) ball.isVisible())
275 {open braces start code blocks and must be matched with a close brace
276 ifif executes the next statement only if the condition in parenthesis evaluates to true(lives>0)
277 {open braces start code blocks and must be matched with a close brace
278 dead=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
279 lives--this is the decrement operator, which decreases the variable by 1;
280 ball.setLocation(0,0);
281 livesText.setText("Lives: " +adds two numbers together or concatenates Strings together lives);
282 canvas.removeSprite(ball, paddle);
283 ball.setTracker(nullnull is the value used to refer to a non-existant object);
284 restart=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click to restart game.");
285 restart.setLocation(0.5, 0.5);
286 restart.setScale(.5);
287 restart.setColor(Color.WHITE);
288 canvas.addSprite(restart);
289 gravity=this assignment operator makes the left side equal to the right sidefalsefalse is a value for the boolean type and means not true;
290 tracker.setVelocity(initVelocity);
291 }close braces end code blocks and must match an earlier open brace
292
293 elseelse is what happens when the if condition is false
294 {open braces start code blocks and must be matched with a close brace
295 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");
296 gameover.setLocation(0.5, 0.5);
297 gameover.setScale(.4);
298 gameover.setColor(Color.WHITE);
299 canvas.addSprite(gameover);
300 canvas.removeSprite(ball, paddle);
301 ball.setTracker(nullnull is the value used to refer to a non-existant object);
302 startGame();
303 }close braces end code blocks and must match an earlier open brace
304 }close braces end code blocks and must match an earlier open brace
305 }close braces end code blocks and must match an earlier open brace
306
307 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value resetGame()
308 {open braces start code blocks and must be matched with a close brace
309 canvas.removeSprite (paddle, ball, scoreText, livesText, restart);
310 trackScore=this assignment operator makes the left side equal to the right side0;
311 makeSprites();
312
313 }close braces end code blocks and must match an earlier open brace
314
315 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bounceOffWalls()
316 {open braces start code blocks and must be matched with a close brace
317 bounceOffPaddle();
318 bounceOffRight();
319 bounceOffLeft();
320 bounceOffTop();
321 }close braces end code blocks and must match an earlier open brace
322
323 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffPaddle()
324 {open braces start code blocks and must be matched with a close brace
325 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
326 {open braces start code blocks and must be matched with a close brace
327 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());
328 tracker.bounce(normal);
329 }close braces end code blocks and must match an earlier open brace
330 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddleBase.intersects(ball))
331 {open braces start code blocks and must be matched with a close brace
332 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(paddleBase.getShape(), ball.getShape());
333 tracker.bounce(normal);
334 }close braces end code blocks and must match an earlier open brace
335 }close braces end code blocks and must match an earlier open brace
336
337 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffRight()
338 {open braces start code blocks and must be matched with a close brace
339 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightBorder.intersects(ball))
340 {open braces start code blocks and must be matched with a close brace
341 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(rightBorder.getShape(), ball.getShape());
342 tracker.bounce(normal);
343 }close braces end code blocks and must match an earlier open brace
344 }close braces end code blocks and must match an earlier open brace
345
346 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffLeft()
347 {open braces start code blocks and must be matched with a close brace
348 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftBorder.intersects(ball))
349 {open braces start code blocks and must be matched with a close brace
350 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(leftBorder.getShape(), ball.getShape());
351 tracker.bounce(normal);
352 }close braces end code blocks and must match an earlier open brace
353 }close braces end code blocks and must match an earlier open brace
354
355 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffTop()
356 {open braces start code blocks and must be matched with a close brace
357 ifif executes the next statement only if the condition in parenthesis evaluates to true(topBorder.intersects(ball))
358 {open braces start code blocks and must be matched with a close brace
359 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(topBorder.getShape(), ball.getShape());
360 tracker.bounce(normal);
361 }close braces end code blocks and must match an earlier open brace
362 }close braces end code blocks and must match an earlier open brace
363
364 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value hitsBricks()
365 {open braces start code blocks and must be matched with a close brace
366 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)
367 {open braces start code blocks and must be matched with a close brace
368 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))
369 {open braces start code blocks and must be matched with a close brace
370 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());
371 score++this is the increment operator, which increases the variable by 1;
372 bricksLeft--this is the decrement operator, which decreases the variable by 1;
373 scoreText.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
374 trackScore++this is the increment operator, which increases the variable by 1;
375 tracker.bounce(normal);
376 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);
377 ifif executes the next statement only if the condition in parenthesis evaluates to true(bricksLeft==this is the comparison operator which evaluates to true if both sides are the same0)
378 {open braces start code blocks and must be matched with a close brace
379 canvas.removeAllSprites();
380 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Congratulations\nYou Win!");
381 win.setLocation(0.5, 0.5);
382 win.setScale(.4);
383 win.setColor(Color.WHITE);
384 canvas.addSprite(win);
385
386 }close braces end code blocks and must match an earlier open brace
387 }close braces end code blocks and must match an earlier open brace
388 }close braces end code blocks and must match an earlier open brace
389 }close braces end code blocks and must match an earlier open brace
390 }close braces end code blocks and must match an earlier open brace
|