|
001 packagepackage is used to name the directory or folder a class is in Curtis;
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
010 /**
011 * Curtis St. John.
012 * Last Defense */
013 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 FinalProj extendsextends means to customize or extend the functionality of a class Game
014 {open braces start code blocks and must be matched with a close brace
015 privateprivate is used to restrict access to the current class only ImageSprite earth, earth2, earth3, earth4;
016 privateprivate is used to restrict access to the current class only ImageSprite hero, enemy1, enemy2, enemy3, boss, flame;
017 privateprivate is used to restrict access to the current class only OutlineSprite wall1, wall2, wall3, wall4;
018 privateprivate is used to restrict access to the current class only OvalSprite missle;
019 privateprivate is used to restrict access to the current class only ArrayList<Sprite> blueBullet;
020 privateprivate is used to restrict access to the current class only ArrayList<Sprite> violetBullet;
021 privateprivate is used to restrict access to the current class only StringSprite score, lose, win, lvl2, lvl3, kill;
022 privateprivate is used to restrict access to the current class only ProjectileTransformer projectile1, projectile2, projectile3;
023 privateprivate is used to restrict access to the current class only ProjectileTransformer projectile4, bulletTransformer, missleTransformer;
024
025 /**sets up the game*/
026 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
027 {open braces start code blocks and must be matched with a close brace
028 earthBacking();
029 heroShip();
030 movingFlame();
031 ufoShip();
032 bossShip();
033 invsWall();
034 score();
035 helpText();
036
037 blueBullet=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
038 violetBullet=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
039 /**Projectile transformers to make the enemy ships move*/
040 projectile1 =this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(1, .15);
041 projectile2 =this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(2, .15);
042 projectile3 =this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(3, .15);
043 projectile4 =this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(2, 0.0);
044 enemy1.setTracker(projectile1);
045 enemy2.setTracker(projectile2);
046 enemy3.setTracker(projectile3);
047 boss.setTracker(projectile4);
048 }close braces end code blocks and must match an earlier open brace
049 /**Creates the earth to rotate around also earth damage forfor is a looping structure for repeatedly executing a block of code lives*/
050 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value earthBacking()
051 {open braces start code blocks and must be matched with a close brace
052 earth=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Earth.jpeg");
053 earth.setScale(.65);
054 earth.setLocation(.5, 1.13);
055 earth.setVisible(truetrue is the boolean value that is the opposite of false);
056
057 earth2=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Earth2.JPG");
058 earth2.setScale(.65);
059 earth2.setLocation(.5, 1.13);
060 earth2.setVisible(falsefalse is a value for the boolean type and means not true);
061
062 earth3=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Earth3.JPG");
063 earth3.setScale(.65);
064 earth3.setLocation(.5, 1.13);
065 earth3.setVisible(falsefalse is a value for the boolean type and means not true);
066
067 earth4=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("Earth4.JPG");
068 earth4.setScale(.65);
069 earth4.setLocation(.5, 1.13);
070 earth4.setVisible(falsefalse is a value for the boolean type and means not true);
071
072 addSprite(earth4);
073 addSprite(earth3);
074 addSprite(earth2);
075 addSprite(earth);
076 }close braces end code blocks and must match an earlier open brace
077 /**Makes the hero ship*/
078 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value heroShip()
079 {open braces start code blocks and must be matched with a close brace
080 hero=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("SpaceshipCS.gif");
081 hero.setScale(.15);
082 hero.setLocation(.5, .8);
083 addSprite(hero);
084 }close braces end code blocks and must match an earlier open brace
085 /**Makes the exaust flame forfor is a looping structure for repeatedly executing a block of code the hero ship*/
086 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value movingFlame()
087 {open braces start code blocks and must be matched with a close brace
088 flame=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("FlameCS.GIF");
089 flame.setScale(.1);
090 flame.setRotation(15.7);
091 flame.setLocation(.5, .9);
092 addSprite(flame);
093 }close braces end code blocks and must match an earlier open brace
094 /**Makes 3 enemy ships (same picture)*/
095 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value ufoShip()
096 {open braces start code blocks and must be matched with a close brace
097 enemy1=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("UfoCS.gif");
098 enemy1.setScale(.15);
099 enemy1.setLocation(.5, .1);
100 addSprite(enemy1);
101
102 enemy2=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("UfoCS.gif");
103 enemy2.setScale(.15);
104 enemy2.setLocation(.2, .1);
105
106
107 enemy3=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("UfoCS.gif");
108 enemy3.setScale(.15);
109 enemy3.setLocation(.8, .1);
110
111 }close braces end code blocks and must match an earlier open brace
112 /**Makes the boss ship*/
113 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bossShip()
114 {open braces start code blocks and must be matched with a close brace
115 boss=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite("BossCS.gif");
116 boss.setScale(.6);
117 boss.setLocation(.5, .1);
118 addSprite(boss);
119
120 }close braces end code blocks and must match an earlier open brace
121 /**Makes a boundary forfor is a looping structure for repeatedly executing a block of code the enemy ships to bounce of off*/
122 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value invsWall()
123 {open braces start code blocks and must be matched with a close brace
124 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));
125 wall1.setSize(2);
126 wall1.setLocation(0, 0);
127 wall1.setVisible(falsefalse is a value for the boolean type and means not true);
128 addSprite(wall1);
129
130 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));
131 wall2.setSize(2);
132 wall2.setLocation(1, 0);
133 wall2.setVisible(falsefalse is a value for the boolean type and means not true);
134 addSprite(wall2);
135
136 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));
137 wall3.setSize(2);
138 wall3.setLocation(0, 1);
139 wall3.setVisible(falsefalse is a value for the boolean type and means not true);
140 addSprite(wall3);
141
142 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));
143 wall4.setSize(2);
144 wall4.setLocation(0, 0);
145 wall4.setVisible(falsefalse is a value for the boolean type and means not true);
146 addSprite(wall4);
147 }close braces end code blocks and must match an earlier open brace
148 /**Keeps enemies on screen by bouncing off of invisible walls*/
149 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bounceEnemy()
150 {open braces start code blocks and must be matched with a close brace
151 enemy1.bounceOffOf(wall1);
152 enemy2.bounceOffOf(wall1);
153 enemy3.bounceOffOf(wall1);
154
155 enemy1.bounceOffOf(wall2);
156 enemy2.bounceOffOf(wall2);
157 enemy3.bounceOffOf(wall2);
158
159 enemy1.bounceOffOf(wall3);
160 enemy2.bounceOffOf(wall3);
161 enemy3.bounceOffOf(wall3);
162
163 enemy1.bounceOffOf(wall4);
164 enemy2.bounceOffOf(wall4);
165 enemy3.bounceOffOf(wall4);
166
167 boss.bounceOffOf(wall1);
168 boss.bounceOffOf(wall2);
169 }close braces end code blocks and must match an earlier open brace
170
171 /**Keeps Score in game*/
172 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value score()
173 {open braces start code blocks and must be matched with a close brace
174 setScore(0);
175 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());
176 score.setLocation(0.25, 0.95);
177 score.setSize(0.15);
178 score.setColor(getColor("white"));
179 score.rightJustify();
180 addSprite(score);
181 }close braces end code blocks and must match an earlier open brace
182
183 /**Help Text*/
184 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value helpText()
185 {open braces start code blocks and must be matched with a close brace
186 String helpText=this assignment operator makes the left side equal to the right side
187 "Click to shoot<br>"+adds two numbers together or concatenates Strings together
188 "Don't try moving because you can't<br>"+adds two numbers together or concatenates Strings together
189 "Your ship is the last barrier between the earth's life and death situation<br>"+adds two numbers together or concatenates Strings together
190 "As your score grows the Mother ship will add more enemies!<br>"+adds two numbers together or concatenates Strings together
191 "Good Luck";
192 setHelpText(helpText);
193 }close braces end code blocks and must match an earlier open brace
194
195 /**Creates a message forfor is a looping structure for repeatedly executing a block of code when you lose*/
196 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value fail()
197 {open braces start code blocks and must be matched with a close brace
198 lose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("You Lose");
199 lose.setLocation(.5, .5);
200 lose.setSize(.8);
201 lose.setColor(getColor("White"));
202 addSprite(lose);
203 }close braces end code blocks and must match an earlier open brace
204
205 /**Creates a message forfor is a looping structure for repeatedly executing a block of code when you win*/
206 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value victory()
207 {open braces start code blocks and must be matched with a close brace
208 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Victory is Yours!");
209 win.setLocation(.5, .5);
210 win.setSize(.6);
211 win.setColor(getColor("White"));
212 addSprite(win);
213 }close braces end code blocks and must match an earlier open brace
214
215 /**Creates a message forfor is a looping structure for repeatedly executing a block of code when the level changes to 2*/
216 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value levelTwo()
217 {open braces start code blocks and must be matched with a close brace
218 lvl2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Level 2");
219 lvl2.setLocation(.5, .5);
220 lvl2.setSize(.6);
221 lvl2.setColor(getColor("White"));
222 addSprite(lvl2);
223 }close braces end code blocks and must match an earlier open brace
224
225 /**Creates a message forfor is a looping structure for repeatedly executing a block of code when the level changes to 3*/
226 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value levelThree()
227 {open braces start code blocks and must be matched with a close brace
228 lvl3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Level 3");
229 lvl3.setLocation(.5, .5);
230 lvl3.setSize(.6);
231 lvl3.setColor(getColor("White"));
232 addSprite(lvl3);
233 }close braces end code blocks and must match an earlier open brace
234
235 /**Creates a message forfor is a looping structure for repeatedly executing a block of code to alert player to destroy boss*/
236 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value killBoss()
237 {open braces start code blocks and must be matched with a close brace
238 kill=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite ("Destroy the Boss!!!");
239 kill.setLocation(.5, .5);
240 kill.setSize(.6);
241 kill.setColor(getColor("White"));
242 addSprite(kill);
243 }close braces end code blocks and must match an earlier open brace
244
245 /**Handles hero bullets*/
246 privateprivate is used to restrict access to the current class only Sprite heroBullet()
247 {open braces start code blocks and must be matched with a close brace
248 forfor is a looping structure for repeatedly executing a block of code(Sprite single: blueBullet)
249 {open braces start code blocks and must be matched with a close brace
250 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 samefalsefalse is a value for the boolean type and means not true)
251 {open braces start code blocks and must be matched with a close brace
252 returnreturn means to provide the result of the method and/or cease execution of the method immediately single;
253 }close braces end code blocks and must match an earlier open brace
254 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.getLocation().y<0)
255 {open braces start code blocks and must be matched with a close brace
256 returnreturn means to provide the result of the method and/or cease execution of the method immediately single;
257 }close braces end code blocks and must match an earlier open brace
258 }close braces end code blocks and must match an earlier open brace
259
260 Sprite bullet=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(0, 0, 0, 1);
261 bullet.setSize(0.1);
262 bullet.setVisible(falsefalse is a value for the boolean type and means not true);
263 bullet.setColor(getColor("cyan"));
264
265 ProjectileTransformer bulletTransformer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0, -0.9);
266 bullet.addTransformer(bulletTransformer);
267
268 addSprite(bullet);
269 blueBullet.add(bullet);
270
271 returnreturn means to provide the result of the method and/or cease execution of the method immediately bullet;
272 }close braces end code blocks and must match an earlier open brace
273
274 privateprivate is used to restrict access to the current class only Sprite bossBullet()
275 {open braces start code blocks and must be matched with a close brace
276 forfor is a looping structure for repeatedly executing a block of code(Sprite singl3: violetBullet)
277 {open braces start code blocks and must be matched with a close brace
278 ifif executes the next statement only if the condition in parenthesis evaluates to true(singl3.isVisible()==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)
279 {open braces start code blocks and must be matched with a close brace
280 returnreturn means to provide the result of the method and/or cease execution of the method immediately singl3;
281 }close braces end code blocks and must match an earlier open brace
282 ifif executes the next statement only if the condition in parenthesis evaluates to true(singl3.getLocation().y>1)
283 {open braces start code blocks and must be matched with a close brace
284 returnreturn means to provide the result of the method and/or cease execution of the method immediately singl3;
285 }close braces end code blocks and must match an earlier open brace
286 }close braces end code blocks and must match an earlier open brace
287
288 missle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 2);
289 missle.setSize(.2);
290 missle.setVisible(falsefalse is a value for the boolean type and means not true);
291 missle.setColor(getColor("red"));
292
293 ProjectileTransformer missleTransformer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0, .08);
294 missle.addTransformer(missleTransformer);
295
296 addSprite(missle);
297 violetBullet.add(missle);
298
299 returnreturn means to provide the result of the method and/or cease execution of the method immediately missle;
300
301 }close braces end code blocks and must match an earlier open brace
302
303 /**Allows you to shoot by clicking*/
304 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value heroShoot()
305 {open braces start code blocks and must be matched with a close brace
306 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=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)
307 {open braces start code blocks and must be matched with a close brace
308 Sprite available=this assignment operator makes the left side equal to the right sideheroBullet();
309 available.setLocation(hero.getX(), hero.getY()-hero.getSize()/2);
310 available.setVisible(truetrue is the boolean value that is the opposite of false);
311 }close braces end code blocks and must match an earlier open brace
312 }close braces end code blocks and must match an earlier open brace
313
314 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bossShoot()
315 {open braces start code blocks and must be matched with a close brace
316 forfor is a looping structure for repeatedly executing a block of code(Sprite bullet: blueBullet)
317 {open braces start code blocks and must be matched with a close brace
318 ifif executes the next statement only if the condition in parenthesis evaluates to true(boss.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 &&) bullet.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 &&) boss.intersects(bullet) &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 &&) !this is the not operator, which changes true to false and false to trueenemy1.isVisible())
319 {open braces start code blocks and must be matched with a close brace
320 Sprite availabl3=this assignment operator makes the left side equal to the right sidebossBullet();
321 availabl3.setLocation(boss.getX(), boss.getY()-boss.getSize()/2);
322 availabl3.setVisible(truetrue is the boolean value that is the opposite of false);
323 }close braces end code blocks and must match an earlier open brace
324 }close braces end code blocks and must match an earlier open brace
325 }close braces end code blocks and must match an earlier open brace
326
327
328 /**Shooting enemies adds 25 to score, boss adds 50, missle adds 20*/
329 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleBulletEnemyCollision()
330 {open braces start code blocks and must be matched with a close brace
331 forfor is a looping structure for repeatedly executing a block of code(Sprite bullet: blueBullet)
332 {open braces start code blocks and must be matched with a close brace
333 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy1.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 &&) bullet.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 &&) enemy1.intersects(bullet))
334 {open braces start code blocks and must be matched with a close brace
335 enemy1.setVisible(falsefalse is a value for the boolean type and means not true);
336 bullet.setVisible(falsefalse is a value for the boolean type and means not true);
337 enemy1.setLocation(.5, .1);
338 enemy1.setVisible(truetrue is the boolean value that is the opposite of false);
339
340 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();
341 setScore(startscore+adds two numbers together or concatenates Strings together25);
342 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
343 }close braces end code blocks and must match an earlier open brace
344 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy2.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 &&) bullet.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 &&) enemy2.intersects(bullet))
345 {open braces start code blocks and must be matched with a close brace
346 enemy2.setVisible(falsefalse is a value for the boolean type and means not true);
347 bullet.setVisible(falsefalse is a value for the boolean type and means not true);
348 enemy2.setLocation(.2, .1);
349 enemy2.setVisible(truetrue is the boolean value that is the opposite of false);
350
351 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();
352 setScore(startscore+adds two numbers together or concatenates Strings together25);
353 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
354 }close braces end code blocks and must match an earlier open brace
355 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy3.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 &&) bullet.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 &&) enemy3.intersects(bullet))
356 {open braces start code blocks and must be matched with a close brace
357 enemy3.setVisible(falsefalse is a value for the boolean type and means not true);
358 bullet.setVisible(falsefalse is a value for the boolean type and means not true);
359 enemy3.setLocation(.8, .1);
360 enemy3.setVisible(truetrue is the boolean value that is the opposite of false);
361
362 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();
363 setScore(startscore+adds two numbers together or concatenates Strings together25);
364 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
365 }close braces end code blocks and must match an earlier open brace
366 ifif executes the next statement only if the condition in parenthesis evaluates to true(boss.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 &&) bullet.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 &&) boss.intersects(bullet) &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 &&) !this is the not operator, which changes true to false and false to trueenemy1.isVisible())
367 {open braces start code blocks and must be matched with a close brace
368 bullet.setVisible(falsefalse is a value for the boolean type and means not true);
369
370 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();
371 setScore(startscore+adds two numbers together or concatenates Strings together50);
372 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
373 }close braces end code blocks and must match an earlier open brace
374 ifif executes the next statement only if the condition in parenthesis evaluates to true(missle!=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 &&) missle.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 &&) bullet.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 &&) missle.intersects(bullet) &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 &&) !this is the not operator, which changes true to false and false to trueenemy1.isVisible())
375 {open braces start code blocks and must be matched with a close brace
376 bullet.setVisible(falsefalse is a value for the boolean type and means not true);
377 missle.setVisible(falsefalse is a value for the boolean type and means not true);
378
379 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();
380 setScore(startscore+adds two numbers together or concatenates Strings together20);
381 score.setText("Score:"+adds two numbers together or concatenates Strings togethergetScore());
382 }close braces end code blocks and must match an earlier open brace
383 }close braces end code blocks and must match an earlier open brace
384 }close braces end code blocks and must match an earlier open brace
385
386 /**Adds damage to the earth when hero is hit by enemy 1*/
387 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleHeroEnemy1Collision()
388 {open braces start code blocks and must be matched with a close brace
389 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy1.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 &&) enemy1.intersects(hero) &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 &&) earth.isVisible())
390 {open braces start code blocks and must be matched with a close brace
391 enemy1.setVisible(falsefalse is a value for the boolean type and means not true);
392 earth.setVisible(falsefalse is a value for the boolean type and means not true);
393 earth2.setVisible(truetrue is the boolean value that is the opposite of false);
394 enemy1.setLocation(.8, .1);
395 enemy1.setVisible(truetrue is the boolean value that is the opposite of false);
396 }close braces end code blocks and must match an earlier open brace
397
398 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy1.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 &&) enemy1.intersects(hero) &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 &&) earth2.isVisible())
399 {open braces start code blocks and must be matched with a close brace
400 enemy1.setVisible(falsefalse is a value for the boolean type and means not true);
401 earth2.setVisible(falsefalse is a value for the boolean type and means not true);
402 earth3.setVisible(truetrue is the boolean value that is the opposite of false);
403 enemy1.setLocation(.5, .1);
404 enemy1.setVisible(truetrue is the boolean value that is the opposite of false);
405 }close braces end code blocks and must match an earlier open brace
406
407 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy1.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 &&) enemy1.intersects(hero) &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 &&) earth3.isVisible())
408 {open braces start code blocks and must be matched with a close brace
409 enemy1.setVisible(falsefalse is a value for the boolean type and means not true);
410 earth3.setVisible(falsefalse is a value for the boolean type and means not true);
411 earth4.setVisible(truetrue is the boolean value that is the opposite of false);
412 hero.setVisible(falsefalse is a value for the boolean type and means not true);
413 flame.setVisible(falsefalse is a value for the boolean type and means not true);
414 enemy1.setLocation(.5, .1);
415 enemy1.setVisible(truetrue is the boolean value that is the opposite of false);
416 fail();
417 }close braces end code blocks and must match an earlier open brace
418 }close braces end code blocks and must match an earlier open brace
419
420 /**Adds damage to the earth when hero is hit by enemy 2*/
421 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleHeroEnemy2Collision()
422 {open braces start code blocks and must be matched with a close brace
423 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy2.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 &&) enemy2.intersects(hero) &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 &&) earth.isVisible())
424 {open braces start code blocks and must be matched with a close brace
425 enemy2.setVisible(falsefalse is a value for the boolean type and means not true);
426 earth.setVisible(falsefalse is a value for the boolean type and means not true);
427 earth2.setVisible(truetrue is the boolean value that is the opposite of false);
428 enemy2.setLocation(.8, .1);
429 enemy2.setVisible(truetrue is the boolean value that is the opposite of false);
430 }close braces end code blocks and must match an earlier open brace
431
432 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy2.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 &&) enemy2.intersects(hero) &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 &&) earth2.isVisible())
433 {open braces start code blocks and must be matched with a close brace
434 enemy2.setVisible(falsefalse is a value for the boolean type and means not true);
435 earth2.setVisible(falsefalse is a value for the boolean type and means not true);
436 earth3.setVisible(truetrue is the boolean value that is the opposite of false);
437 enemy2.setLocation(.5, .1);
438 enemy2.setVisible(truetrue is the boolean value that is the opposite of false);
439 }close braces end code blocks and must match an earlier open brace
440
441 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy2.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 &&) enemy2.intersects(hero) &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 &&) earth3.isVisible())
442 {open braces start code blocks and must be matched with a close brace
443 enemy2.setVisible(falsefalse is a value for the boolean type and means not true);
444 earth3.setVisible(falsefalse is a value for the boolean type and means not true);
445 earth4.setVisible(truetrue is the boolean value that is the opposite of false);
446 hero.setVisible(falsefalse is a value for the boolean type and means not true);
447 flame.setVisible(falsefalse is a value for the boolean type and means not true);
448 enemy2.setLocation(.5, .1);
449 enemy2.setVisible(truetrue is the boolean value that is the opposite of false);
450 fail();
451 }close braces end code blocks and must match an earlier open brace
452 }close braces end code blocks and must match an earlier open brace
453
454 /**Adds damage to the earth when hero is hit by enemy 3*/
455 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleHeroEnemy3Collision()
456 {open braces start code blocks and must be matched with a close brace
457 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy3.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 &&) enemy3.intersects(hero) &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 &&) earth.isVisible())
458 {open braces start code blocks and must be matched with a close brace
459 enemy3.setVisible(falsefalse is a value for the boolean type and means not true);
460 earth.setVisible(falsefalse is a value for the boolean type and means not true);
461 earth2.setVisible(truetrue is the boolean value that is the opposite of false);
462 enemy3.setLocation(.8, .1);
463 enemy3.setVisible(truetrue is the boolean value that is the opposite of false);
464 }close braces end code blocks and must match an earlier open brace
465
466 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy3.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 &&) enemy3.intersects(hero) &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 &&) earth2.isVisible())
467 {open braces start code blocks and must be matched with a close brace
468 enemy3.setVisible(falsefalse is a value for the boolean type and means not true);
469 earth2.setVisible(falsefalse is a value for the boolean type and means not true);
470 earth3.setVisible(truetrue is the boolean value that is the opposite of false);
471 enemy3.setLocation(.5, .1);
472 enemy3.setVisible(truetrue is the boolean value that is the opposite of false);
473 }close braces end code blocks and must match an earlier open brace
474
475 ifif executes the next statement only if the condition in parenthesis evaluates to true(enemy3.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 &&) enemy3.intersects(hero) &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 &&) earth3.isVisible())
476 {open braces start code blocks and must be matched with a close brace
477 enemy3.setVisible(falsefalse is a value for the boolean type and means not true);
478 earth3.setVisible(falsefalse is a value for the boolean type and means not true);
479 earth4.setVisible(truetrue is the boolean value that is the opposite of false);
480 hero.setVisible(falsefalse is a value for the boolean type and means not true);
481 flame.setVisible(falsefalse is a value for the boolean type and means not true);
482 enemy3.setLocation(.5, .1);
483 enemy3.setVisible(truetrue is the boolean value that is the opposite of false);
484 fail();
485 }close braces end code blocks and must match an earlier open brace
486 }close braces end code blocks and must match an earlier open brace
487
488 /**Adds damage to the earth when hero is hit by boss bullet*/
489 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleHeroBossCollision()
490 {open braces start code blocks and must be matched with a close brace
491 ifif executes the next statement only if the condition in parenthesis evaluates to true(missle!=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 &&) missle.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 &&) missle.intersects(hero) &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 &&) earth.isVisible())
492 {open braces start code blocks and must be matched with a close brace
493 missle.setVisible(falsefalse is a value for the boolean type and means not true);
494 earth.setVisible(falsefalse is a value for the boolean type and means not true);
495 earth2.setVisible(truetrue is the boolean value that is the opposite of false);
496 }close braces end code blocks and must match an earlier open brace
497
498 ifif executes the next statement only if the condition in parenthesis evaluates to true(missle!=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 &&) missle.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 &&) missle.intersects(hero) &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 &&) earth2.isVisible())
499 {open braces start code blocks and must be matched with a close brace
500 missle.setVisible(falsefalse is a value for the boolean type and means not true);
501 earth2.setVisible(falsefalse is a value for the boolean type and means not true);
502 earth3.setVisible(truetrue is the boolean value that is the opposite of false);
503 }close braces end code blocks and must match an earlier open brace
504
505 ifif executes the next statement only if the condition in parenthesis evaluates to true(missle!=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 &&) missle.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 &&) missle.intersects(hero) &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 &&) earth3.isVisible())
506 {open braces start code blocks and must be matched with a close brace
507 missle.setVisible(falsefalse is a value for the boolean type and means not true);
508 earth3.setVisible(falsefalse is a value for the boolean type and means not true);
509 earth4.setVisible(truetrue is the boolean value that is the opposite of false);
510 hero.setVisible(falsefalse is a value for the boolean type and means not true);
511 flame.setVisible(falsefalse is a value for the boolean type and means not true);
512 fail();
513 }close braces end code blocks and must match an earlier open brace
514 }close braces end code blocks and must match an earlier open brace
515
516 classclass is a group of fields and methods used for making objects Level2Delay extendsextends means to customize or extend the functionality of a class TimedAction
517 {open braces start code blocks and must be matched with a close brace
518 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
519 {open braces start code blocks and must be matched with a close brace
520 lvl2.setVisible(falsefalse is a value for the boolean type and means not true);
521 }close braces end code blocks and must match an earlier open brace
522 }close braces end code blocks and must match an earlier open brace
523
524 classclass is a group of fields and methods used for making objects Level3Delay extendsextends means to customize or extend the functionality of a class TimedAction
525 {open braces start code blocks and must be matched with a close brace
526 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
527 {open braces start code blocks and must be matched with a close brace
528 lvl3.setVisible(falsefalse is a value for the boolean type and means not true);
529 }close braces end code blocks and must match an earlier open brace
530 }close braces end code blocks and must match an earlier open brace
531
532 /**Levels achieved depending on your score*/
533 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value levelUp()
534 {open braces start code blocks and must be matched with a close brace
535 ifif executes the next statement only if the condition in parenthesis evaluates to true (getScore() ==this is the comparison operator which evaluates to true if both sides are the same 300)
536 {open braces start code blocks and must be matched with a close brace
537 addSprite(enemy2);
538
539 }close braces end code blocks and must match an earlier open brace
540 ifif executes the next statement only if the condition in parenthesis evaluates to true (getScore() ==this is the comparison operator which evaluates to true if both sides are the same 800)
541 {open braces start code blocks and must be matched with a close brace
542 addSprite(enemy3);
543
544 }close braces end code blocks and must match an earlier open brace
545 ifif executes the next statement only if the condition in parenthesis evaluates to true (getScore() ==this is the comparison operator which evaluates to true if both sides are the same 1475)
546 {open braces start code blocks and must be matched with a close brace
547 enemy2.setVisible(falsefalse is a value for the boolean type and means not true);
548 enemy3.setVisible(falsefalse is a value for the boolean type and means not true);
549 }close braces end code blocks and must match an earlier open brace
550
551 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 side 1500)
552 {open braces start code blocks and must be matched with a close brace
553 enemy1.setVisible(falsefalse is a value for the boolean type and means not true);
554
555 }close braces end code blocks and must match an earlier open brace
556
557 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 side 3000)
558 {open braces start code blocks and must be matched with a close brace
559 boss.setVisible(falsefalse is a value for the boolean type and means not true);
560 victory();
561 }close braces end code blocks and must match an earlier open brace
562 }close braces end code blocks and must match an earlier open brace
563
564 /**handle input and game events*/
565 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
566 {open braces start code blocks and must be matched with a close brace
567 handleBulletEnemyCollision();
568 handleHeroEnemy1Collision();
569 handleHeroEnemy2Collision();
570 handleHeroEnemy3Collision();
571 handleHeroBossCollision();
572 bounceEnemy();
573 heroShoot();
574 levelUp();
575 bossShoot();
576 //schedule(new Level2Delay(), 1.0);
577 //schedule(new Level3Delay(), 1.0);
578 }close braces end code blocks and must match an earlier open brace
579 }close braces end code blocks and must match an earlier open brace
|