|
001 packagepackage is used to name the directory or folder a class is in mkim;
002 //start auto-imports
003 importimport means to make the classes and/or packages available in this program java.util.*;
004 //end auto-imports
005
006 importimport means to make the classes and/or packages available in this program fang.*;
007 importimport means to make the classes and/or packages available in this program java.awt.*;
008 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
009 importimport means to make the classes and/or packages available in this program java.lang.Object.*;
010 /**
011 * All about my game.
012 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
013 */
014 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 Game
015 {open braces start code blocks and must be matched with a close brace
016 /** lives set*/
017 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer startlives=this assignment operator makes the left side equal to the right side3;
018 /**ovalSprite make circles*/
019 privateprivate is used to restrict access to the current class only OvalSprite ball, ball2;
020 /** square wall*/
021 privateprivate is used to restrict access to the current class only RectangleSprite rwall1, rwall2;
022 /**rectangle bricks*/
023 privateprivate is used to restrict access to the current class only RectangleSprite bricks;
024 /** text stuff*/
025 privateprivate is used to restrict access to the current class only StringSprite score, lives, gameOver, gameWin;
026 /**arrays of brick*/
027 privateprivate is used to restrict access to the current class only ArrayList<Sprite> allBricks;
028 /**arrays of powerup*/
029 privateprivate is used to restrict access to the current class only ArrayList<OvalSprite> powerUps;
030 /** outline of sprite*/
031 privateprivate is used to restrict access to the current class only OutlineSprite paddle, paddle2, wall1, wall2, wall3, wall4;
032 /** balll bounce setting transformer*/
033 privateprivate is used to restrict access to the current class only ProjectileTransformer projectile, projectile2, projectile3;
034 /**set remainingBlock to a intint is the type for whole numbers and it is short for integer*/
035 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer remainingBrick;
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 setup()
038 {open braces start code blocks and must be matched with a close brace
039 bricks();
040 makePaddle();
041 makeBall();
042 makeWall();
043 helps();
044 score();
045 lives();
046 roundWalls();
047
048 projectile=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.1, 0.5);
049 ball.setTracker(projectile);
050 projectile=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.1, 0.6);
051 ball2.setTracker(projectile);
052 }close braces end code blocks and must match an earlier open brace
053 /**make help*/
054 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value helps()
055 {open braces start code blocks and must be matched with a close brace
056 String helpText=this assignment operator makes the left side equal to the right side
057 "get 100 points to get extra ball.<br>"+adds two numbers together or concatenates Strings together
058 "good luck";
059 setHelpText(helpText);
060 }close braces end code blocks and must match an earlier open brace
061 /**random color*/
062 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value randomColorBound()
063 {open braces start code blocks and must be matched with a close brace
064 ball.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
065 ball2.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
066 rwall1.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
067 rwall2.setColor(newnew is used to create objects by calling the constructor Color(random.nextInt()));
068 }close braces end code blocks and must match an earlier open brace
069 /**array of bricks (got it from example code)*/
070 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bricks()
071 {open braces start code blocks and must be matched with a close brace
072 allBricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
073 intint is the type for whole numbers and it is short for integer bricksAcross=this assignment operator makes the left side equal to the right side11;
074 intint is the type for whole numbers and it is short for integer bricksDown=this assignment operator makes the left side equal to the right side6;
075 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<bricksDown;j++this is the increment operator, which increases the variable by 1)
076 {open braces start code blocks and must be matched with a close brace
077 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 side1;i<=this evaluates to true if the left side is not more than the right sidebricksAcross;i++this is the increment operator, which increases the variable by 1)
078 {open braces start code blocks and must be matched with a close brace
079 bricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2,1);
080 bricks.setSize(0.9/bricksAcross);
081 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side.5/bricksAcross+adds two numbers together or concatenates Strings together1.0/bricksAcross*(i-1);
082 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side.5/16+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.0)/16;
083 bricks.setLocation(x, y);
084 bricks.setColor(Palette.getColor("Blue"));
085 addSprite(bricks);
086 allBricks.add(bricks);
087 }close braces end code blocks and must match an earlier open brace
088 }close braces end code blocks and must match an earlier open brace
089 }close braces end code blocks and must match an earlier open brace
090 /**make two paddles*/
091 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePaddle()
092 {open braces start code blocks and must be matched with a close brace
093 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 1, 0));
094 paddle.setSize(0.25);
095 paddle.setLineThickness(0.2);
096 paddle.setLocation(0.5,0.9);
097 paddle.setColor(Palette.getColor("green"));
098 addSprite(paddle);
099 }close braces end code blocks and must match an earlier open brace
100 /**make balls*/
101 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBall()
102 {open braces start code blocks and must be matched with a close brace
103 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);
104 ball.setSize(0.05);
105 ball.setLocation(0.5,0.6);
106 ball.setColor(Palette.getColor("yellow"));
107 addSprite(ball);
108
109 ball2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,1);
110 ball2.setSize(0.05);
111 ball2.setLocation(0.5,0.6);
112 ball2.setColor(Palette.getColor("yellow"));
113 ball2.setVisible(falsefalse is a value for the boolean type and means not true);
114 }close braces end code blocks and must match an earlier open brace
115 /** make walls on the side*/
116 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeWall()
117 {open braces start code blocks and must be matched with a close brace
118 wall1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 0, 1));
119 wall1.setSize(2);
120 wall1.setLocation(0,0);
121 wall1.setColor(Palette.getColor("red"));
122 addSprite(wall1);
123
124 wall2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 0, 1));
125 wall2.setSize(2);
126 wall2.setLocation(1,0);
127 wall2.setColor(Palette.getColor("red"));
128 addSprite(wall2);
129
130 wall3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 1, 0));
131 wall3.setSize(2);
132 wall3.setLocation(0,0);
133 wall3.setColor(Palette.getColor("red"));
134 addSprite(wall3);
135
136 wall4=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 1, 0));
137 wall4.setSize(1);
138 wall4.setLocation(0,1);
139 wall4.setColor(Palette.getColor("black"));
140 addSprite(wall4);
141 }close braces end code blocks and must match an earlier open brace
142 /**make squares on the right and left side*/
143 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value roundWalls()
144 {open braces start code blocks and must be matched with a close brace
145 rwall1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 1);
146 rwall1.setSize(.2);
147 rwall1.setLocation(1, .6);
148 rwall1.setColor(Palette.getColor("white"));
149 addSprite(rwall1);
150
151 rwall2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 1);
152 rwall2.setSize(.2);
153 rwall2.setLocation(0, .6);
154 rwall2.setColor(Palette.getColor("white"));
155 addSprite(rwall2);
156 }close braces end code blocks and must match an earlier open brace
157 /**when the ball hits the blocks changes color and than dissapear*/
158 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleBallblockCollision()
159 {open braces start code blocks and must be matched with a close brace
160 forfor is a looping structure for repeatedly executing a block of code(Sprite single: allBricks)
161 {open braces start code blocks and must be matched with a close brace
162 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.isVisible()==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 &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 &&) single.intersects(ball))
163 {open braces start code blocks and must be matched with a close brace
164 ball.bounceOffOf(single);
165 ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(single.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Red")
166 {open braces start code blocks and must be matched with a close brace
167 single.setVisible(falsefalse is a value for the boolean type and means not true);
168 intint is the type for whole numbers and it is short for integer startscore =this assignment operator makes the left side equal to the right side getScore();
169 setScore(startscore+adds two numbers together or concatenates Strings together10);
170 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
171 }close braces end code blocks and must match an earlier open brace
172 ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(single.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Blue")
173 single.setColor(getColor("Red"));
174 }close braces end code blocks and must match an earlier open brace
175 }close braces end code blocks and must match an earlier open brace
176 }close braces end code blocks and must match an earlier open brace
177 /**when the second ball hits the blocks changes color and than dissapear*/
178 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleBalltwoblockCollision()
179 {open braces start code blocks and must be matched with a close brace
180 forfor is a looping structure for repeatedly executing a block of code(Sprite single: allBricks)
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(single.isVisible()==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 &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 &&) single.intersects(ball2))
183 {open braces start code blocks and must be matched with a close brace
184 ball2.bounceOffOf(single);
185 ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(single.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Red")
186 {open braces start code blocks and must be matched with a close brace
187 single.setVisible(falsefalse is a value for the boolean type and means not true);
188 intint is the type for whole numbers and it is short for integer startscore =this assignment operator makes the left side equal to the right side getScore();
189 setScore(startscore+adds two numbers together or concatenates Strings together10);
190 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
191 }close braces end code blocks and must match an earlier open brace
192 ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(single.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Blue")
193 single.setColor(getColor("Red"));
194 }close braces end code blocks and must match an earlier open brace
195 }close braces end code blocks and must match an earlier open brace
196 }close braces end code blocks and must match an earlier open brace
197 /**block remaining*/
198 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer blocksLeft()
199 {open braces start code blocks and must be matched with a close brace
200 remainingBrick=this assignment operator makes the left side equal to the right side0;
201 forfor is a looping structure for repeatedly executing a block of code(Sprite single: allBricks)
202 {open braces start code blocks and must be matched with a close brace
203 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.isVisible()==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)
204 {open braces start code blocks and must be matched with a close brace
205 remainingBrick++this is the increment operator, which increases the variable by 1;
206 }close braces end code blocks and must match an earlier open brace
207 }close braces end code blocks and must match an earlier open brace
208 returnreturn means to provide the result of the method and/or cease execution of the method immediately remainingBrick;
209 }close braces end code blocks and must match an earlier open brace
210 /**set score on the bottom*/
211 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value score()
212 {open braces start code blocks and must be matched with a close brace
213 setScore(0);
214 score=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 togethergetScore());
215 score.setLocation(0.7, 0.95);
216 score.setSize(0.15);
217 score.setColor(getColor("white"));
218 score.rightJustify();
219 addSprite(score);
220 }close braces end code blocks and must match an earlier open brace
221 /**set lives*/
222 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value lives()
223 {open braces start code blocks and must be matched with a close brace
224 setLives(3);
225 lives=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 togethergetLives());
226 lives.setLocation(0.1, 0.95);
227 lives.setSize(0.15);
228 lives.setColor(getColor("white"));
229 lives.leftJustify();
230 addSprite(lives);
231 }close braces end code blocks and must match an earlier open brace
232 /**game over text and pause the game*/
233 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value showGameOver()
234 {open braces start code blocks and must be matched with a close brace
235 lives.setVisible(falsefalse is a value for the boolean type and means not true);
236 score.setVisible(falsefalse is a value for the boolean type and means not true);
237 bricks.setVisible(falsefalse is a value for the boolean type and means not true);
238 ball.setVisible(falsefalse is a value for the boolean type and means not true);
239 paddle.setVisible(falsefalse is a value for the boolean type and means not true);
240 pause();
241 gameOver =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("GAME OVER");
242 gameOver.setSize(.9);
243 gameOver.setColor(getColor("green"));
244 gameOver.setLocation(.5, .5);
245 addSprite(gameOver);
246 setLives(0);
247 }close braces end code blocks and must match an earlier open brace
248 /**set winning message pause the game*/
249 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value showGameWin()
250 {open braces start code blocks and must be matched with a close brace
251 paddle.setVisible(falsefalse is a value for the boolean type and means not true);
252 ball.setVisible(falsefalse is a value for the boolean type and means not true);
253 pause();
254 gameWin =this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You Win");
255 gameWin.setSize(.9);
256 gameWin.setColor(getColor("green"));
257 gameWin.setLocation(0.5, 0.5);
258 addSprite(gameWin);
259 }close braces end code blocks and must match an earlier open brace
260 /** ifif executes the next statement only if the condition in parenthesis evaluates to true it goes down y coordinate greater than.98 and ball is not visible
261 you loose a life and ifif executes the next statement only if the condition in parenthesis evaluates to true life is less than 1 shows the game over
262 (got help from derrick) */
263 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value looseBall()
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(ball.getLocation().y>0.98)
266 {open braces start code blocks and must be matched with a close brace
267 ball.setLocation(0.5, 0.5);
268 startlives =this assignment operator makes the left side equal to the right side getLives();
269 setLives(startlives-1);
270 lives.setText("Lives:"+adds two numbers together or concatenates Strings togethergetLives());
271 }close braces end code blocks and must match an earlier open brace
272 ifif executes the next statement only if the condition in parenthesis evaluates to true (getLives()<1)
273 {open braces start code blocks and must be matched with a close brace
274 showGameOver();
275 }close braces end code blocks and must match an earlier open brace
276 }close braces end code blocks and must match an earlier open brace
277 /**makes the paddle move left and right when mouse moves*/
278 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value movePaddle()
279 {open braces start code blocks and must be matched with a close brace
280 paddle.setX(getMouseX());
281 }close braces end code blocks and must match an earlier open brace
282 /**tells where to bounce off from*/
283 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
284 {open braces start code blocks and must be matched with a close brace
285 ball.bounceOffOf(paddle);
286 ball.bounceOffOf(wall1);
287 ball.bounceOffOf(wall2);
288 ball.bounceOffOf(wall3);
289 ball.bounceOffOf(rwall1);
290 ball.bounceOffOf(rwall2);
291
292 ball2.bounceOffOf(paddle);
293 ball2.bounceOffOf(wall1);
294 ball2.bounceOffOf(wall2);
295 ball2.bounceOffOf(wall3);
296 ball2.bounceOffOf(rwall1);
297 ball2.bounceOffOf(rwall2);
298 }close braces end code blocks and must match an earlier open brace
299 /**doubledouble is the type for numbers that can contain decimal fractions paddle at point 50 extra ball when score is reaches 100*/
300 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value power()
301 {open braces start code blocks and must be matched with a close brace
302 ifif executes the next statement only if the condition in parenthesis evaluates to true(getScore()>=this evaluates to true if the left side is not less than the right side100)
303 {open braces start code blocks and must be matched with a close brace
304 ball2.setVisible(truetrue is the boolean value that is the opposite of false);
305 addSprite(ball2);
306 }close braces end code blocks and must match an earlier open brace
307 }close braces end code blocks and must match an earlier open brace
308 /**handle input and game events*/
309 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
310 {open braces start code blocks and must be matched with a close brace
311 movePaddle();
312 handleCollisions();
313 handleBallblockCollision();
314 handleBalltwoblockCollision();
315 randomColorBound();
316 looseBall();
317 power();
318 ifif executes the next statement only if the condition in parenthesis evaluates to true(blocksLeft()<=this evaluates to true if the left side is not more than the right side0)
319 {open braces start code blocks and must be matched with a close brace
320 showGameWin();
321 }close braces end code blocks and must match an earlier open brace
322 }close braces end code blocks and must match an earlier open brace
323 }close braces end code blocks and must match an earlier open brace
|