|
001 packagepackage is used to name the directory or folder a class is in BlakeErskine;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007
008 /**
009 * All about my game here.
010 * @authorthis is the Javadoc tag for documenting who created the source code bErskine
011 */
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 /**a rectangle*/
015 privateprivate is used to restrict access to the current class only Sprite rectangle, ceiling, leftWall, rightWall, floor;
016 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions startYCoord, startXCoord;
017 privateprivate is used to restrict access to the current class only Sprite paddle, ball;
018 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
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 level;
020 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;
021 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;
022 privateprivate is used to restrict access to the current class only StringSprite scoreSprite, livesSprite, gameOver;
023
024 /**sets up the game*/
025 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
026 {open braces start code blocks and must be matched with a close brace
027 removeCursor();
028 makeSprites();
029 addSprites();
030 makeBricks();
031 makeceiling();
032 makeLeftWall();
033 makeRightWall();
034 makePaddle();
035 makeBall();
036 makeTracker();
037 makefloor();
038 level=this assignment operator makes the left side equal to the right side0;
039 score=this assignment operator makes the left side equal to the right side0;
040 lives=this assignment operator makes the left side equal to the right side5;
041 setHelpText ("<h1>Breakout</h1)" +adds two numbers together or concatenates Strings together
042 "<br><br>Hit bricks with the ball to remove from screen.<br><br> Enjoy!");
043
044 }close braces end code blocks and must match an earlier open brace
045
046 /**makes the sprites*/
047 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
048 {open braces start code blocks and must be matched with a close brace
049 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);
050 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");
051 scoreSprite.setScale(0.2);
052 scoreSprite.rightJustify();
053 scoreSprite.setColor(Color.BLUE);
054 scoreSprite.setLocation(.59, .85);
055 /*Adds score to the game.*/
056
057 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);
058 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");
059 livesSprite.setScale(0.19);
060 livesSprite.setColor(Color.GREEN);
061 livesSprite.setLocation(.49, .95);
062 /*Adds lives to the game.*/
063
064 gameOver=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("YOU LOSE");
065 gameOver.setScale(0.3);
066 gameOver.setColor(Color.BLUE);
067 gameOver.setLocation(.5, .5);
068 /*Lets player know that game is over.*/
069 }close braces end code blocks and must match an earlier open brace
070
071 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks()
072 {open braces start code blocks and must be matched with a close brace
073 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;
074 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;
075 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;
076 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;
077 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;
078 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;
079 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)
080 {open braces start code blocks and must be matched with a close brace
081 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;
082
083 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;
084 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;
085 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;
086 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;
087 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)
088 {open braces start code blocks and must be matched with a close brace
089 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;
090 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);
091 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);
092 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);
093 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);
094 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);
095 index++this is the increment operator, which increases the variable by 1;
096 /*Makes the bricks to add to the game.*/
097 }close braces end code blocks and must match an earlier open brace
098 }close braces end code blocks and must match an earlier open brace
099 }close braces end code blocks and must match an earlier open brace
100
101 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeceiling()
102 {open braces start code blocks and must be matched with a close brace
103 ceiling =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(20, .5);
104 ceiling.setLocation(.5, .01);
105 ceiling.setColor(Color.GREEN);
106 canvas.addSprite(ceiling);
107 /*Makes ceiling to add to the game.*/
108 }close braces end code blocks and must match an earlier open brace
109
110 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeLeftWall()
111 {open braces start code blocks and must be matched with a close brace
112 leftWall =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1, 10);
113 leftWall.setLocation(startXCoord / 4.5, .5);
114 leftWall.setColor(Color.GREEN);
115 canvas.addSprite(leftWall);
116 /*Makes left wall to add to the game.*/
117 }close braces end code blocks and must match an earlier open brace
118
119 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeRightWall()
120 {open braces start code blocks and must be matched with a close brace
121 rightWall =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1, 10);
122 rightWall.setLocation(1 - startXCoord / 4.5, .5);
123 rightWall.setColor(Color.GREEN);
124 canvas.addSprite(rightWall);
125 /*Makes right wall to add to the game.*/
126 }close braces end code blocks and must match an earlier open brace
127
128 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makefloor()
129 {open braces start code blocks and must be matched with a close brace
130 floor =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(20,.5);
131 floor.setLocation(.5, .99);
132 floor.setColor(Color.BLACK);
133 canvas.addSprite(floor);
134 /*Makes floor of the game.*/
135 }close braces end code blocks and must match an earlier open brace
136
137 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makePaddle()
138 {open braces start code blocks and must be matched with a close brace
139 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);
140 paddle.setLocation(.5, .8);
141 paddle.setScale(.25);
142 paddle.setColor(Color.BLACK);
143 canvas.addSprite(paddle);
144 /*Makes paddle to add to game.*/
145 }close braces end code blocks and must match an earlier open brace
146
147 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBall()
148 {open braces start code blocks and must be matched with a close brace
149 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);
150 ball.setLocation(.5, .7799);
151 ball.setScale(.02);
152 ball.setColor(Color.BLACK);
153 canvas.addSprite(ball);
154 /*Makes ball to add to game.*/
155 }close braces end code blocks and must match an earlier open brace
156
157 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value randomColorBound()
158 {open braces start code blocks and must be matched with a close brace
159 ball.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
160 paddle.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
161 rightWall.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
162 leftWall.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
163 ceiling.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
164 /*Makes the ball and paddle random colors.*/
165 }close braces end code blocks and must match an earlier open brace
166
167 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
168 {open braces start code blocks and must be matched with a close brace
169 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.21,-.21);
170 ball.setTracker(tracker);
171 /*Makes tracker forfor is a looping structure for repeatedly executing a block of code the ball.*/
172 }close braces end code blocks and must match an earlier open brace
173
174 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value wallBounce()
175 {open braces start code blocks and must be matched with a close brace
176 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
177 {open braces start code blocks and must be matched with a close brace
178 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());
179 tracker.bounce(normal);
180 /*Makes ball bounce off of paddle.*/
181 }close braces end code blocks and must match an earlier open brace
182
183 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightWall.intersects(ball))
184 {open braces start code blocks and must be matched with a close brace
185 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());
186 tracker.bounce(normal);
187 /*Makes ball bounce off right wall.*/
188 }close braces end code blocks and must match an earlier open brace
189
190 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftWall.intersects(ball))
191 {open braces start code blocks and must be matched with a close brace
192 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());
193 tracker.bounce(normal);
194 /*Makes ball bounce off left wall.*/
195 }close braces end code blocks and must match an earlier open brace
196
197 ifif executes the next statement only if the condition in parenthesis evaluates to true(ceiling.intersects(ball))
198 {open braces start code blocks and must be matched with a close brace
199 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(ceiling.getShape(), ball.getShape());
200 tracker.bounce(normal);
201 /*ball bounce off ceiling.*/
202 }close braces end code blocks and must match an earlier open brace
203 }close braces end code blocks and must match an earlier open brace
204
205 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value brickIntersects()
206 {open braces start code blocks and must be matched with a close brace
207 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)
208 {open braces start code blocks and must be matched with a close brace
209
210 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))
211 {open braces start code blocks and must be matched with a close brace
212 score++this is the increment operator, which increases the variable by 1;
213 score +=this increases the variable on the left by the value on the right 9;
214 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)
215 {open braces start code blocks and must be matched with a close brace
216 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());
217 tracker.bounce(normal);
218 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);
219 }close braces end code blocks and must match an earlier open brace
220
221 }close braces end code blocks and must match an earlier open brace
222 }close braces end code blocks and must match an earlier open brace
223 /*Increases score ifif executes the next statement only if the condition in parenthesis evaluates to true ball intersects brick.*/
224 updateScore();
225 }close braces end code blocks and must match an earlier open brace
226
227 /**adds the sprites to the screen*/
228 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
229 {open braces start code blocks and must be matched with a close brace
230 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
231 }close braces end code blocks and must match an earlier open brace
232 /*Adds the score.*/
233 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateLives()
234 {open braces start code blocks and must be matched with a close brace
235 livesSprite.setText("Lives: "+adds two numbers together or concatenates Strings togetherlives);
236 }close braces end code blocks and must match an earlier open brace
237 /*Adds the lives.*/
238 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
239 {open braces start code blocks and must be matched with a close brace
240 canvas.addSprite(scoreSprite);
241 canvas.addSprite(livesSprite);
242 }close braces end code blocks and must match an earlier open brace
243 /*Adds the score and lives to the game.*/
244
245 /**handle input and game events*/
246
247 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value resetGame()
248 {open braces start code blocks and must be matched with a close brace
249 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)
250 {open braces start code blocks and must be matched with a close brace
251 canvas.addSprite(gameOver);
252 }close braces end code blocks and must match an earlier open brace
253 }close braces end code blocks and must match an earlier open brace
254
255 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bonus()
256 {open braces start code blocks and must be matched with a close brace
257 ifif executes the next statement only if the condition in parenthesis evaluates to true(score==this is the comparison operator which evaluates to true if both sides are the same200)
258 {open braces start code blocks and must be matched with a close brace
259 lives=this assignment operator makes the left side equal to the right sidelives+adds two numbers together or concatenates Strings together1;
260 score=this assignment operator makes the left side equal to the right sidescore+adds two numbers together or concatenates Strings together10;
261 }close braces end code blocks and must match an earlier open brace
262 ifif executes the next statement only if the condition in parenthesis evaluates to true(score==this is the comparison operator which evaluates to true if both sides are the same400)
263 {open braces start code blocks and must be matched with a close brace
264 lives=this assignment operator makes the left side equal to the right sidelives+adds two numbers together or concatenates Strings together1;
265 score=this assignment operator makes the left side equal to the right sidescore+adds two numbers together or concatenates Strings together10;
266 }close braces end code blocks and must match an earlier open brace
267 updateLives();
268 updateScore();
269
270 }close braces end code blocks and must match an earlier open brace
271 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)
272 {open braces start code blocks and must be matched with a close brace
273 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;
274 paddle.setLocation(x,paddle.getLocation().y);
275 wallBounce();
276 brickIntersects();
277 randomColorBound(); //Jayson Helped.
278 resetGame();
279 bonus();
280 ifif executes the next statement only if the condition in parenthesis evaluates to true (lives ==this is the comparison operator which evaluates to true if both sides are the same 1 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) floor.intersects(ball))
281 {open braces start code blocks and must be matched with a close brace
282 lives--this is the decrement operator, which decreases the variable by 1;
283 }close braces end code blocks and must match an earlier open brace
284 ifif executes the next statement only if the condition in parenthesis evaluates to true(floor.intersects(ball) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) lives > 1)
285 {open braces start code blocks and must be matched with a close brace
286 lives--this is the decrement operator, which decreases the variable by 1;
287 ball.setLocation(.5,.5);
288 }close braces end code blocks and must match an earlier open brace
289 updateLives();
290 }close braces end code blocks and must match an earlier open brace
291 /*Subtract lives everytime the ball drops below the floor.*/
292 }close braces end code blocks and must match an earlier open brace
|