|
001 packagepackage is used to name the directory or folder a class is in Curtis;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * Interactive PacMan.
009 * @authorthis is the Javadoc tag for documenting who created the source code Curtis
010 */
011 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 InteractiveArt extendsextends means to customize or extend the functionality of a class Game
012 {open braces start code blocks and must be matched with a close brace
013 privateprivate is used to restrict access to the current class only PieSprite pac1;
014 privateprivate is used to restrict access to the current class only OvalSprite circ1;
015 privateprivate is used to restrict access to the current class only StringSprite name, title;
016 privateprivate is used to restrict access to the current class only ImageSprite cherry, cherry2;
017 privateprivate is used to restrict access to the current class only ProjectileTransformer projectile;
018 privateprivate is used to restrict access to the current class only OutlineSprite boundary;
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 numClicks;
020
021 /**sets up the game*/
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
023 {open braces start code blocks and must be matched with a close brace
024 name();
025 cherry();
026 makePacman();
027 moveUp();
028 moveRight();
029 moveDown();
030 moveLeft();
031 helpScreen();
032 boundary();
033 numClicks=this assignment operator makes the left side equal to the right side0;
034
035 Sound theme=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Pac-man.mp3");
036 theme.play(.9);
037 theme.setVolume(.8);
038 theme.loop();
039
040 projectile=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(.1, .25);
041 cherry.setTracker(projectile);
042
043 }close braces end code blocks and must match an earlier open brace
044
045 /**Makes the cherries*/
046 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value cherry()
047 {open braces start code blocks and must be matched with a close brace
048 cherry=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("CherryCS.jpg");
049 cherry.setSize(.1);
050 cherry.setLocation(.65, .5);
051 addSprite(cherry);
052
053
054 cherry2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("CherryCS.jpg");
055 cherry2.setSize(.1);
056 cherry2.setLocation(.2, .5);
057 cherry2.setVisible(falsefalse is a value for the boolean type and means not true);
058
059 }close braces end code blocks and must match an earlier open brace
060
061 /**Makes the PacMan image*/
062 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePacman()
063 {open braces start code blocks and must be matched with a close brace
064 pac1=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor PieSprite(1, 1, 30, 315);
065 pac1.setSize(.3);
066 pac1.setLocation(.5, .5);
067 pac1.setColor(getColor("yellow"));
068 addSprite(pac1);
069
070 circ1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
071 circ1.setSize(.295);
072 circ1.setLocation(.5, .5);
073 circ1.setColor(getColor("yellow"));
074 addSprite(circ1);
075
076 schedule(newnew is used to create objects by calling the constructor Blinker(), .25);
077 }close braces end code blocks and must match an earlier open brace
078
079 /**Makes the circle blink to simulate mouth movement*/
080 classclass is a group of fields and methods used for making objects Blinker extendsextends means to customize or extend the functionality of a class TimedAction
081 {open braces start code blocks and must be matched with a close brace
082 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
083 {open braces start code blocks and must be matched with a close brace
084 booleanboolean is a type that is either true or false vis=this assignment operator makes the left side equal to the right sidecirc1.isVisible();
085 circ1.setVisible(!this is the not operator, which changes true to false and false to truevis);
086 schedule(thisthis means the current object (the implicit parameter), .3);
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 /**Name And Title*/
090 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value name()
091 {open braces start code blocks and must be matched with a close brace
092 name=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Curtis St. John");
093 name.setSize(.25);
094 name.setLocation(.85, .9);
095 name.setColor(getColor("red"));
096 addSprite(name);
097
098 title=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Interactive PacMan");
099 title.setSize(.5);
100 title.setLocation(.5, .3);
101 title.setColor(getColor("red"));
102 addSprite(title);
103 }close braces end code blocks and must match an earlier open brace
104 /**The Help Screen*/
105 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value helpScreen()
106 {open braces start code blocks and must be matched with a close brace
107 String helpText=this assignment operator makes the left side equal to the right side
108 "Press a, s, w, d,<br>"+adds two numbers together or concatenates Strings together
109 "To Move<br>"+adds two numbers together or concatenates Strings together
110 "PacMan.<br>"+adds two numbers together or concatenates Strings together
111 "Click on PacMan when his<br>"+adds two numbers together or concatenates Strings together
112 "mouth is open for a cherry<br>"+adds two numbers together or concatenates Strings together
113 "Click when closed and<br>"+adds two numbers together or concatenates Strings together
114 "PacMan DIES!.";
115 setHelpText(helpText);
116 }close braces end code blocks and must match an earlier open brace
117
118 /**Makes the boundary*/
119 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value boundary()
120 {open braces start code blocks and must be matched with a close brace
121 boundary=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 PolygonSprite(4));
122 boundary.setSize(1.2);
123 boundary.setLineThickness(.05);
124 boundary.setLocation(.5, .5);
125 addSprite(boundary);
126
127 Spinner spin;
128 spin=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
129 spin.setRotationDegrees(25);
130 boundary.addTransformer(spin);
131 }close braces end code blocks and must match an earlier open brace
132
133 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value collisions()
134 {open braces start code blocks and must be matched with a close brace
135 cherry.bounceOffOf(boundary);
136 cherry.bounceOffOf(circ1);
137 }close braces end code blocks and must match an earlier open brace
138
139 /**Moves PacMan right*/
140 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value moveRight()
141 {open braces start code blocks and must be matched with a close brace
142 OutlineTransformer right;
143 right=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.25,
144 0.5, 0.5,
145 0.8, 0.5,
146 0.5, 0.5);
147 right.setLooping(falsefalse is a value for the boolean type and means not true);
148
149 circ1.addTransformer(right);
150 circ1.setLocation(right.getCurrentPoint());
151 pac1.addTransformer(right);
152 pac1.setLocation(right.getCurrentPoint());
153 addSprite(circ1);
154 addSprite(pac1);
155 }close braces end code blocks and must match an earlier open brace
156 /**Moves PacMan left*/
157 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value moveLeft()
158 {open braces start code blocks and must be matched with a close brace
159 OutlineTransformer left;
160 left=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.25,
161 0.5, 0.5,
162 0.2, 0.5,
163 0.5, 0.5);
164 left.setLooping(falsefalse is a value for the boolean type and means not true);
165
166 circ1.addTransformer(left);
167 circ1.setLocation(left.getCurrentPoint());
168 pac1.addTransformer(left);
169 pac1.setLocation(left.getCurrentPoint());
170 addSprite(circ1);
171 addSprite(pac1);
172 }close braces end code blocks and must match an earlier open brace
173 /**Moves PacMan up*/
174 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value moveUp()
175 {open braces start code blocks and must be matched with a close brace
176 OutlineTransformer up;
177 up=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.25,
178 0.5, 0.5,
179 0.5, 0.2,
180 0.5, 0.5);
181 up.setLooping(falsefalse is a value for the boolean type and means not true);
182
183 circ1.addTransformer(up);
184 circ1.setLocation(up.getCurrentPoint());
185 pac1.addTransformer(up);
186 pac1.setLocation(up.getCurrentPoint());
187 addSprite(circ1);
188 addSprite(pac1);
189 }close braces end code blocks and must match an earlier open brace
190 /**Moves PacMan down*/
191 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value moveDown()
192 {open braces start code blocks and must be matched with a close brace
193 OutlineTransformer down;
194 down=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.25,
195 0.5, 0.5,
196 0.5, 0.8,
197 0.5, 0.5);
198 down.setLooping(falsefalse is a value for the boolean type and means not true);
199
200 circ1.addTransformer(down);
201 circ1.setLocation(down.getCurrentPoint());
202 pac1.addTransformer(down);
203 pac1.setLocation(down.getCurrentPoint());
204 addSprite(circ1);
205 addSprite(pac1);
206 }close braces end code blocks and must match an earlier open brace
207 /**Makes the title go away*/
208 classclass is a group of fields and methods used for making objects TitleLag extendsextends means to customize or extend the functionality of a class TimedAction
209 {open braces start code blocks and must be matched with a close brace
210 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
211 {open braces start code blocks and must be matched with a close brace
212 title.setVisible(falsefalse is a value for the boolean type and means not true);
213 }close braces end code blocks and must match an earlier open brace
214 }close braces end code blocks and must match an earlier open brace
215 /**Makes Cherry appear*/
216
217 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value surprise()
218 {open braces start code blocks and must be matched with a close brace
219 cherry2.setVisible(truetrue is the boolean value that is the opposite of false);
220 addSprite(cherry2);
221 }close braces end code blocks and must match an earlier open brace
222
223 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value death()
224 {open braces start code blocks and must be matched with a close brace
225 Spinner die;
226 die=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
227 die.setRotationDegrees(25);
228 pac1.addTransformer(die);
229
230 Sound death=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("PacManDies.wav");
231 death.setVolume(.8);
232 death.play(.2);
233 }close braces end code blocks and must match an earlier open brace
234
235 /**handle input and game events*/
236 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
237 {open braces start code blocks and must be matched with a close brace
238 collisions();
239
240 /**Click forfor is a looping structure for repeatedly executing a block of code cherry or death*/
241
242 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);
243 {open braces start code blocks and must be matched with a close brace
244 numClicks++this is the increment operator, which increases the variable by 1;
245 }close braces end code blocks and must match an earlier open brace
246 ifif executes the next statement only if the condition in parenthesis evaluates to true(numClicks==this is the comparison operator which evaluates to true if both sides are the same0)
247 {open braces start code blocks and must be matched with a close brace
248 cherry.setVisible(falsefalse is a value for the boolean type and means not true);
249 }close braces end code blocks and must match an earlier open brace
250
251 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(numClicks==this is the comparison operator which evaluates to true if both sides are the same1)
252 {open braces start code blocks and must be matched with a close brace
253 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 &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 &&) circ1.intersects(getClick2D()))
254 {open braces start code blocks and must be matched with a close brace
255 death();
256 }close braces end code blocks and must match an earlier open brace
257
258 elseelse is what happens when the if condition is false 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 &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 &&) pac1.intersects(getClick2D()))
259 {open braces start code blocks and must be matched with a close brace
260 surprise();
261 }close braces end code blocks and must match an earlier open brace
262 }close braces end code blocks and must match an earlier open brace
263
264 /**press a,s,d,w to move*/
265 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'd')
266 {open braces start code blocks and must be matched with a close brace
267 moveRight();
268 }close braces end code blocks and must match an earlier open brace
269
270 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'a')
271 {open braces start code blocks and must be matched with a close brace
272 moveLeft();
273 }close braces end code blocks and must match an earlier open brace
274
275 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'w')
276 {open braces start code blocks and must be matched with a close brace
277 moveUp();
278 }close braces end code blocks and must match an earlier open brace
279
280 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same's')
281 {open braces start code blocks and must be matched with a close brace
282 moveDown();
283 }close braces end code blocks and must match an earlier open brace
284 /**press aswd to of making the title go away*/
285 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'a' ||this is boolean or, meaning if either or both are true then the result is true getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'd' ||this is boolean or, meaning if either or both are true then the result is true getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same's' ||this is boolean or, meaning if either or both are true then the result is true getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'w')
286 {open braces start code blocks and must be matched with a close brace
287 schedule(newnew is used to create objects by calling the constructor TitleLag(), .5);
288 }close braces end code blocks and must match an earlier open brace
289 }close braces end code blocks and must match an earlier open brace
290 }close braces end code blocks and must match an earlier open brace
|