|
001
002
003 packagepackage is used to name the directory or folder a class is in ChrisHull;
004
005 importimport means to make the classes and/or packages available in this program wiki.Wiki;
006 importimport means to make the classes and/or packages available in this program fang.*;
007 /**This is my finalfinal means not changeable (often used for constants) Project a modification of Wackadot
008 * @authorthis is the Javadoc tag for documenting who created the source code Chris Hull
009 * The sounds are from Metal Gear Solid 2 , and Super Mario Brothers, I didn't make them.
010 */
011 importimport means to make the classes and/or packages available in this program java.awt.*;
012 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
013 importimport means to make the classes and/or packages available in this program Beta.*;
014
015
016
017
018
019
020 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 FinalProject extendsextends means to customize or extend the functionality of a class GameLoop
021 {open braces start code blocks and must be matched with a close brace
022
023 /** Moves the monsters face forfor is a looping structure for repeatedly executing a block of code translation*/
024 privateprivate is used to restrict access to the current class only Sprite moving;
025 /** determines type of tracker*/
026 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
027 /** Declares Track Statement*/
028 privateprivate is used to restrict access to the current class only Beta.OutlineTracker track;
029 /** Makes image move*/
030 privateprivate is used to restrict access to the current class only Sprite move;
031 /** Displays Distraction*/
032 privateprivate is used to restrict access to the current class only Sprite distraction;
033 /** Plays good sound*/
034 privateprivate is used to restrict access to the current class only Sound sound;
035 /** Plays bad sound*/
036 privateprivate is used to restrict access to the current class only Sound soundSecond;
037 /** Displays timer*/
038 privateprivate is used to restrict access to the current class only Sprite timerSprites;
039 /** Displays score*/
040 privateprivate is used to restrict access to the current class only Sprite scoreSprites;
041
042
043
044 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
045 {open braces start code blocks and must be matched with a close brace
046 sprite.setLocation(
047 random.nextDouble(),
048 random.nextDouble());
049 }close braces end code blocks and must match an earlier open brace
050
051 /**modifys Distraction with a Periodic event*/
052 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value PeriodicEvent()
053 {open braces start code blocks and must be matched with a close brace
054 distraction=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Distraction.JPG");
055 distraction.setScale(0.1);
056 distraction.setLocation(0.5, 0.4);
057 canvas.addSprite(distraction);
058
059 }close braces end code blocks and must match an earlier open brace
060
061
062
063 /**calls PeriodicEvent when the alarm goes off*/
064 classclass is a group of fields and methods used for making objects PeriodicEvent implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
065 {open braces start code blocks and must be matched with a close brace
066 /**simply calls PerodicEvent*/
067 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
068 {open braces start code blocks and must be matched with a close brace
069 distraction.setVisible(!this is the not operator, which changes true to false and false to truedistraction.isVisible());
070
071 scheduleRelative(thisthis means the current object (the implicit parameter),.1);
072 repositionRandomly(distraction);
073
074 }close braces end code blocks and must match an earlier open brace
075 }close braces end code blocks and must match an earlier open brace
076 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
077
078 {open braces start code blocks and must be matched with a close brace
079 makeSounds();
080 toggleAudible();
081 score=this assignment operator makes the left side equal to the right side0;
082 timeLeft=this assignment operator makes the left side equal to the right side30;
083 makeSprites();
084 addSprites();
085 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
086 scheduleRelative(newnew is used to create objects by calling the constructor PeriodicEvent(), 1);
087 /** Changes the text in help file*/
088 setHelpText(
089 "Touch the blue wackadot to gain points and the red to lose points<br><br>"+adds two numbers together or concatenates Strings together
090 "press 1 and 2 to hear different sounds<br><br>"+adds two numbers together or concatenates Strings together
091 "Click Start to begin");
092 moveSprite();
093 movingSprite();
094 PeriodicEvent();
095 }close braces end code blocks and must match an earlier open brace
096
097 /**tells what sound will play*/
098 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSounds()
099 {open braces start code blocks and must be matched with a close brace
100 sound=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Codec.wav"));
101 soundSecond=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Mario2.wav"));
102 }close braces end code blocks and must match an earlier open brace
103
104 /** determines how sprite will rotate*/
105 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value moveSprite()
106 {open braces start code blocks and must be matched with a close brace
107 move=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Blue.JPG"));
108 move.setScale(0.2);
109 move.setLocation(0.5, 0.4);
110 Point2D.Double direction=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Point2D.Double(0, 0);
111 ProjectileTracker pTracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(direction);
112 pTracker.setAngularVelocity(1);
113 move.setTracker(pTracker);
114 canvas.addSprite(move);
115
116 }close braces end code blocks and must match an earlier open brace
117
118 /** determines how the sprite will move*/
119 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value movingSprite()
120 {open braces start code blocks and must be matched with a close brace
121 moving=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Red.JPG"));
122 moving.setScale(0.2);
123 moving.setLocation(0.5, 1);
124 track=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Beta.OutlineTracker (.2, .5,.6 ,.5,.7);
125 track.setLooping(truetrue is the boolean value that is the opposite of false);
126 moving.setTracker(track);
127 moving.setLocation(track.getCurrentPoint());
128 canvas.addSprite(moving);
129
130 }close braces end code blocks and must match an earlier open brace
131
132
133
134 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
135 {open braces start code blocks and must be matched with a close brace
136 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(move))
137 {open braces start code blocks and must be matched with a close brace
138 repositionRandomly(move);
139 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
140 {open braces start code blocks and must be matched with a close brace
141 dot.setColor(Color.RED);
142 score++this is the increment operator, which increases the variable by 1;
143 goodsound.play();
144 }close braces end code blocks and must match an earlier open brace
145 elseelse is what happens when the if condition is false
146 {open braces start code blocks and must be matched with a close brace
147 score--this is the decrement operator, which decreases the variable by 1;
148 badsound.play();
149 }close braces end code blocks and must match an earlier open brace
150 updateScore();
151 }close braces end code blocks and must match an earlier open brace
152 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(moving))
153 {open braces start code blocks and must be matched with a close brace
154 repositionRandomly(moving);
155 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
156 {open braces start code blocks and must be matched with a close brace
157 dot.setColor(Color.BLUE);
158 score++this is the increment operator, which increases the variable by 1;
159 goodsound.play();
160 }close braces end code blocks and must match an earlier open brace
161 elseelse is what happens when the if condition is false
162 {open braces start code blocks and must be matched with a close brace
163 score--this is the decrement operator, which decreases the variable by 1;
164 badsound.play();
165 }close braces end code blocks and must match an earlier open brace
166 updateScore();
167
168 }close braces end code blocks and must match an earlier open brace
169 }close braces end code blocks and must match an earlier open brace
170
171
172 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)
173 {open braces start code blocks and must be matched with a close brace
174 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
175 {open braces start code blocks and must be matched with a close brace
176 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
177 getPlayer().getMouse().getLocation();
178 dot.setLocation(mouse);
179 handleCollisions();
180 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getKeyboard().getLastKey()==this is the comparison operator which evaluates to true if both sides are the same'1')
181 {open braces start code blocks and must be matched with a close brace
182 sound.play(0);
183 }close braces end code blocks and must match an earlier open brace
184 ifif executes the next statement only if the condition in parenthesis evaluates to true(getPlayer().getKeyboard().getLastKey()==this is the comparison operator which evaluates to true if both sides are the same'2')
185 {open braces start code blocks and must be matched with a close brace
186 soundSecond.play(1);
187 }close braces end code blocks and must match an earlier open brace
188 }close braces end code blocks and must match an earlier open brace
189 }close braces end code blocks and must match an earlier open brace
190 privateprivate is used to restrict access to the current class only Sprite dot;
191 privateprivate is used to restrict access to the current class only Sound goodsound;
192 privateprivate is used to restrict access to the current class only Sound badsound;
193 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
194 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;
195 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer timeLeft;
196 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
197
198
199
200 classclass is a group of fields and methods used for making objects TimeUpdater implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
201 {open braces start code blocks and must be matched with a close brace
202 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
203 {open braces start code blocks and must be matched with a close brace
204 timeLeft--this is the decrement operator, which decreases the variable by 1;
205 updateTimer();
206 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
207 {open braces start code blocks and must be matched with a close brace
208 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
209 }close braces end code blocks and must match an earlier open brace
210 }close braces end code blocks and must match an earlier open brace
211 }close braces end code blocks and must match an earlier open brace
212 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
213 {open braces start code blocks and must be matched with a close brace
214 goodsound =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Clap.wav"));
215 badsound =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sound(Wiki.getMedia("Boom.wav"));
216
217 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
218 dot.setScale(0.1);
219 dot.setLocation(0.5, 0.5);
220 dot.setColor(Color.RED);
221
222 timerSprites=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Timer.JPG"));
223 timerSprites.setScale(0.3);
224 timerSprites.setLocation(.15, 0.1);
225
226 scoreSprites=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Score.JPG"));
227 scoreSprites.setScale(0.25);
228 scoreSprites.setLocation(0.65, 0.1);
229
230 {open braces start code blocks and must be matched with a close brace
231 scoreSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite(" 0");
232 scoreSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite(" "+adds two numbers together or concatenates Strings togetherscore);
233 scoreSprite.setHeight(0.1);
234 scoreSprite.rightJustify();
235 scoreSprite.topJustify();
236 scoreSprite.setLocation(.9, .07);
237 timerSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite(" "+adds two numbers together or concatenates Strings togethertimeLeft);
238 timerSprite.leftJustify();
239 timerSprite.topJustify();
240 timerSprite.setHeight(0.1);
241 timerSprite.setLocation(.35, .07);
242 }close braces end code blocks and must match an earlier open brace
243 }close braces end code blocks and must match an earlier open brace
244 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
245 {open braces start code blocks and must be matched with a close brace
246 scoreSprite.setText(" "+adds two numbers together or concatenates Strings togetherscore);
247 }close braces end code blocks and must match an earlier open brace
248
249 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
250 {open braces start code blocks and must be matched with a close brace
251 canvas.addSprite(dot);
252 canvas.addSprite(scoreSprite);
253 canvas.addSprite(timerSprite);
254 canvas.addSprite(scoreSprites);
255 canvas.addSprite(timerSprites);
256 }close braces end code blocks and must match an earlier open brace
257 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
258 {open braces start code blocks and must be matched with a close brace
259 timerSprite.setText(""+adds two numbers together or concatenates Strings togethertimeLeft);
260 }close braces end code blocks and must match an earlier open brace
261 ;
262
263 }close braces end code blocks and must match an earlier open brace
|