|
001 packagepackage is used to name the directory or folder a class is in MattC;
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 Mcrauswe
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 Breakout 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
015 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;
016 privateprivate is used to restrict access to the current class only Sprite ball, paddle;
017 privateprivate is used to restrict access to the current class only Sprite lBorder, rBorder, tBorder, bottomBorder;
018 privateprivate is used to restrict access to the current class only StringSprite livesCount, scoreBoard, gameover, winner, resetGame;
019 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
020 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, trackScore;
021
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
023 {open braces start code blocks and must be matched with a close brace
024
025 lives=this assignment operator makes the left side equal to the right side3;
026 score=this assignment operator makes the left side equal to the right side0;
027 makeBricks();
028 makeBall();
029 makePaddle();
030 makeTracker();
031 makeSprites();
032 toggleAudible();
033 pauseToggle();
034 setHelpText("Hit the ball with the paddle while trying to eliminate all bricks. You have three lives!");
035 }close braces end code blocks and must match an earlier open brace
036
037 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
038 {open braces start code blocks and must be matched with a close brace
039 makeWalls();
040
041 gameover=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("YOU LOST, HAHA!!");
042 gameover.setScale(0.6);
043 gameover.setColor(Color.RED);
044 gameover.setLocation(.5, .5);
045
046 winner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("YOU WON, GREAT JOB!!");
047 winner.setScale(0.6);
048 winner.setColor(Color.BLUE);
049 winner.setLocation(.5, .5);
050
051 }close braces end code blocks and must match an earlier open brace
052
053 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeWalls()
054 {open braces start code blocks and must be matched with a close brace
055 lBorder=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 40);
056 lBorder.setLocation(0.015, 0.5);
057 lBorder.setScale(1);
058 lBorder.setColor(Color.RED);
059 canvas.addSprite(lBorder);
060
061 rBorder=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 40);
062 rBorder.setLocation(.985, 0.5);
063 rBorder.setScale(1);
064 rBorder.setColor(Color.RED);
065 canvas.addSprite(rBorder);
066
067 tBorder=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
068 tBorder.setLocation(0.5, 0);
069 tBorder.setScale(1);
070 tBorder.setColor(Color.RED);
071 canvas.addSprite(tBorder);
072
073 bottomBorder=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
074 bottomBorder.setLocation(0.5, 1);
075 bottomBorder.setScale(1);
076 bottomBorder.setColor(Color.RED);
077 canvas.addSprite(bottomBorder);
078 }close braces end code blocks and must match an earlier open brace
079
080 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value randomColorBound()
081 {open braces start code blocks and must be matched with a close brace
082 ball.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
083 bottomBorder.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
084 lBorder.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
085 rBorder.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
086 tBorder.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
087 }close braces end code blocks and must match an earlier open brace
088
089 /**Makes the bricks*/
090 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBricks()
091 {open braces start code blocks and must be matched with a close brace
092 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;
093 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;
094 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;
095 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;
096 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;
097 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;
098 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)
099 {open braces start code blocks and must be matched with a close brace
100 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;
101
102 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;
103 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;
104 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;
105 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;
106
107 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)
108 {open braces start code blocks and must be matched with a close brace
109 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;
110 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);
111 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);
112 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);
113 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);
114 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);
115 index++this is the increment operator, which increases the variable by 1;
116 }close braces end code blocks and must match an earlier open brace
117 }close braces end code blocks and must match an earlier open brace
118 }close braces end code blocks and must match an earlier open brace
119 /**Makes the ball*/
120 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBall()
121 {open braces start code blocks and must be matched with a close brace
122 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Ellipse2D.Double(0,0,1,1);
123 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite(circle);
124 ball.setLocation(.2,.6);
125 ball.setScale(.03);
126 ball.setColor(Color.RED);
127 canvas.addSprite(ball);
128 }close braces end code blocks and must match an earlier open brace
129 /**Makes the paddle*/
130 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePaddle()
131 {open braces start code blocks and must be matched with a close brace
132 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(15, 3);
133 paddle.setColor(Color.GREEN);
134 paddle.setScale(.12);
135 paddle.setLocation(.5, .9);
136 canvas.addSprite(paddle);
137 }close braces end code blocks and must match an earlier open brace
138
139 /**Makes lives visible on game*/
140 privateprivate is used to restrict access to the current class only StringSprite makeLives;
141 {open braces start code blocks and must be matched with a close brace
142 livesCount =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 togetherlives);
143 livesCount=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Lives: 3");
144 livesCount.setLocation(0.14, .05);
145 livesCount.setColor(Color.WHITE);
146 livesCount.setScale(0.16);
147 canvas.addSprite(livesCount);
148 }close braces end code blocks and must match an earlier open brace
149 /**Makes score visible on game*/
150 privateprivate is used to restrict access to the current class only StringSprite makeScore;
151
152 {open braces start code blocks and must be matched with a close brace
153 scoreBoard =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);
154 scoreBoard =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Score: 0");
155 scoreBoard.setLocation(0.86, .05);
156 scoreBoard.setColor(Color.WHITE);
157 scoreBoard.setScale(0.175);
158 canvas.addSprite(scoreBoard);
159 }close braces end code blocks and must match an earlier open brace
160
161 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;
162
163 /**Makes ball move*/
164 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
165 {open braces start code blocks and must be matched with a close brace
166 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);
167 ball.setTracker(tracker);
168 }close braces end code blocks and must match an earlier open brace
169
170 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
171 {open braces start code blocks and must be matched with a close brace
172 scoreBoard.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
173 }close braces end code blocks and must match an earlier open brace
174 /*Adds the score.*/
175 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateLives()
176 {open braces start code blocks and must be matched with a close brace
177 livesCount.setText("Lives: "+adds two numbers together or concatenates Strings togetherlives);
178 }close braces end code blocks and must match an earlier open brace
179
180 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value resetGame()
181 {open braces start code blocks and must be matched with a close brace
182 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)
183 {open braces start code blocks and must be matched with a close brace
184 canvas.addSprite(gameover);
185 }close braces end code blocks and must match an earlier open brace
186 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 same50)
187 {open braces start code blocks and must be matched with a close brace
188 canvas.addSprite(winner);
189 }close braces end code blocks and must match an earlier open brace
190
191 }close braces end code blocks and must match an earlier open brace
192
193 /**Changes speed of ball during gameplay*/
194 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)
195 {open braces start code blocks and must be matched with a close brace
196 ifif executes the next statement only if the condition in parenthesis evaluates to true(trackScore>2)
197 {open braces start code blocks and must be matched with a close brace
198 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 different nullnull is the value used to refer to a non-existant object)
199 {open braces start code blocks and must be matched with a close brace
200 Point2D.Double velocity=this assignment operator makes the left side equal to the right sidetracker.getVelocity();
201 velocity.y+=this increases the variable on the left by the value on the right(.35*timePassed);
202 ifif executes the next statement only if the condition in parenthesis evaluates to true(velocity.y>1)
203 {open braces start code blocks and must be matched with a close brace
204 velocity.y=this assignment operator makes the left side equal to the right side1;
205 }close braces end code blocks and must match an earlier open brace
206 tracker.setVelocity(velocity);
207 }close braces end code blocks and must match an earlier open brace
208 }close braces end code blocks and must match an earlier open brace
209
210 resetGame();
211 {open braces start code blocks and must be matched with a close brace
212 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;
213 paddle.setLocation(x,paddle.getLocation().y);
214
215 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 &&) bottomBorder.intersects(ball))
216 {open braces start code blocks and must be matched with a close brace
217 lives--this is the decrement operator, which decreases the variable by 1;
218 }close braces end code blocks and must match an earlier open brace
219 ifif executes the next statement only if the condition in parenthesis evaluates to true(bottomBorder.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)
220 {open braces start code blocks and must be matched with a close brace
221 lives--this is the decrement operator, which decreases the variable by 1;
222 ball.setLocation(.5,.5);
223 }close braces end code blocks and must match an earlier open brace
224 updateLives();
225 }close braces end code blocks and must match an earlier open brace
226
227
228 bounceOffWalls();
229 hitsBricks();
230 randomColorBound();
231
232
233 }close braces end code blocks and must match an earlier open brace
234
235 /**Allows the ball to bounce of the walls and the paddle*/
236 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bounceOffWalls()
237 {open braces start code blocks and must be matched with a close brace
238 bounceOffPaddle();
239 bounceOffRight();
240 bounceOffLeft();
241 bounceOffTop();
242 }close braces end code blocks and must match an earlier open brace
243
244 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffPaddle()
245 {open braces start code blocks and must be matched with a close brace
246 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
247 {open braces start code blocks and must be matched with a close brace
248 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());
249 tracker.bounce(normal);
250 }close braces end code blocks and must match an earlier open brace
251 }close braces end code blocks and must match an earlier open brace
252
253 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffRight()
254 {open braces start code blocks and must be matched with a close brace
255 ifif executes the next statement only if the condition in parenthesis evaluates to true(rBorder.intersects(ball))
256 {open braces start code blocks and must be matched with a close brace
257 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(rBorder.getShape(), ball.getShape());
258 tracker.bounce(normal);
259 }close braces end code blocks and must match an earlier open brace
260 }close braces end code blocks and must match an earlier open brace
261
262 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffLeft()
263 {open braces start code blocks and must be matched with a close brace
264 ifif executes the next statement only if the condition in parenthesis evaluates to true(lBorder.intersects(ball))
265 {open braces start code blocks and must be matched with a close brace
266 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(lBorder.getShape(), ball.getShape());
267 tracker.bounce(normal);
268 }close braces end code blocks and must match an earlier open brace
269 }close braces end code blocks and must match an earlier open brace
270
271 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffTop()
272 {open braces start code blocks and must be matched with a close brace
273 ifif executes the next statement only if the condition in parenthesis evaluates to true(tBorder.intersects(ball))
274 {open braces start code blocks and must be matched with a close brace
275 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(tBorder.getShape(), ball.getShape());
276 tracker.bounce(normal);
277 }close braces end code blocks and must match an earlier open brace
278 }close braces end code blocks and must match an earlier open brace
279
280
281 /**Allows the ball to hit the bricks*/
282
283
284 //*Takes lives away and if you do too many will display message telling you have lost the game*/
285
286
287 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value hitsBricks()
288 {open braces start code blocks and must be matched with a close brace
289 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)
290 {open braces start code blocks and must be matched with a close brace
291 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))
292 {open braces start code blocks and must be matched with a close brace
293 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());
294 score++this is the increment operator, which increases the variable by 1;
295 scoreBoard.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
296 tracker.bounce(normal);
297 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);
298
299 }close braces end code blocks and must match an earlier open brace
300 }close braces end code blocks and must match an earlier open brace
301
302
303 }close braces end code blocks and must match an earlier open brace
304
305
306 }close braces end code blocks and must match an earlier open brace
|