|
001 packagepackage is used to name the directory or folder a class is in Derrick;
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 * All about my game.
009 * @authorthis is the Javadoc tag for documenting who created the source code Derrick Dixon
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 AssignmentSixIneractiveArt 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
014 privateprivate is used to restrict access to the current class only Sound ding, shipsound;
015 privateprivate is used to restrict access to the current class only OutlineSprite boundary, forcefield;
016 privateprivate is used to restrict access to the current class only ProjectileTransformer projectile;
017 privateprivate is used to restrict access to the current class only OvalSprite shot;
018 privateprivate is used to restrict access to the current class only String helpbox;
019 privateprivate is used to restrict access to the current class only ImageSprite car, spaceship, sun;
020 privateprivate is used to restrict access to the current class only RectangleSprite background;
021 privateprivate is used to restrict access to the current class only StringSprite title, artistname;
022
023 //**Makes forcefield for spaceship blink*/
024 classclass is a group of fields and methods used for making objects ForcefieldBlinker extendsextends means to customize or extend the functionality of a class TimedAction
025 {open braces start code blocks and must be matched with a close brace
026 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
027 {open braces start code blocks and must be matched with a close brace
028 booleanboolean is a type that is either true or false vis=this assignment operator makes the left side equal to the right sideforcefield.isVisible();
029 forcefield.setVisible(!this is the not operator, which changes true to false and false to truevis);
030 schedule(thisthis means the current object (the implicit parameter), 0.5);
031 }close braces end code blocks and must match an earlier open brace
032 }close braces end code blocks and must match an earlier open brace
033 /**Makes and adds boundary forfor is a looping structure for repeatedly executing a block of code shot and forcefield spaceship*/
034 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddBoundary()
035 {open braces start code blocks and must be matched with a close brace
036 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 RectangleSprite(2,2));
037 boundary.setSize(1.0);
038
039 boundary.setColor(Palette.getColor("WHITE"));
040 boundary.setLineThickness(0.0001);
041 boundary.setLocation(0.5, 0.5);
042 addSprite(boundary);
043
044 forcefield=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 RectangleSprite(2,1));
045 forcefield.setSize(0.45);
046 forcefield.setColor(Palette.getColor("Blue"));
047 forcefield.setLineThickness(0.15);
048 forcefield.setLocation(0.5, 0.2);
049 addSprite(forcefield);
050
051
052 Spinner spinshield;
053 spinshield=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
054 spinshield.setRotationDegrees(45);
055
056 forcefield.addTransformer(spinshield);
057
058 }close braces end code blocks and must match an earlier open brace
059 /**Makes Sounds I used ding twice Because I could not find another sound to use*/
060 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddSound()
061 {open braces start code blocks and must be matched with a close brace
062 ding=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("DingLower.wav");
063
064 shipsound=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("DingLower.wav");
065 shipsound.setVolume(0.05);
066 shipsound.loop();
067
068
069
070 }close braces end code blocks and must match an earlier open brace
071 /**Makes shot fired, color and size*/
072 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddShot()
073
074 {open braces start code blocks and must be matched with a close brace
075 shot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
076 shot.setSize(0.025);
077 shot.setColor(Palette.getColor("BLACK"));
078 shot.setLocation(0.5, 0.305);
079 addSprite(shot);
080
081
082 }close braces end code blocks and must match an earlier open brace
083 /** The in java the game background is black so in order forfor is a looping structure for repeatedly executing a block of code me to
084 make the background and the images in my art not clash I changed the background
085 thisthis means the current object (the implicit parameter) method also makes and creates the car image*/
086 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddCarBackground()
087 {open braces start code blocks and must be matched with a close brace
088 background=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 2);
089 background.setColor(Palette.getColor("WHITE"));
090 background.setSize(1.0);
091 background.setLocation(0.5, 0.5);
092 addSprite(background);
093
094 car=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Car123.jpg");
095 car.setSize(0.10);
096 car.setLocation(0.5, 0.80);
097 addSprite(car);
098
099 }close braces end code blocks and must match an earlier open brace
100 /**Here I add a spinner and an image of a spinner.
101 the image is spun by the spinner*/
102 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddSpaceship()
103 {open braces start code blocks and must be matched with a close brace
104 spaceship=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Spaceship.jpg");
105 spaceship.setSize(0.4);
106 spaceship.setLocation(0.5, 0.2);
107 addSprite(spaceship);
108
109 Spinner spinship;
110 spinship=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
111 spinship.setRotationDegrees(45);
112
113 spaceship.addTransformer(spinship);
114 }close braces end code blocks and must match an earlier open brace
115 /**Creates caption in help box*/
116 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddGetHelp()
117 {open braces start code blocks and must be matched with a close brace
118 String helpbox=this assignment operator makes the left side equal to the right side
119 "Press start to begin.<br>"+adds two numbers together or concatenates Strings together
120 "Click on a location to move the car.<br>"+adds two numbers together or concatenates Strings together
121 "Press r to change the color of shot fired";
122
123 setHelpText(helpbox);
124 }close braces end code blocks and must match an earlier open brace
125 /**Creates String sprite with artist name and title*/
126 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddStrings()
127 {open braces start code blocks and must be matched with a close brace
128 artistname=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Derrick");
129 artistname.setColor(Palette.getColor("Yellow Green"));
130 artistname.setSize(0.50);
131 artistname.setLocation(0.5, 0.25);
132 addSprite(artistname);
133
134 title=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("U.F.O.");
135 title.setColor(Palette.getColor("Black"));
136 title.setSize(0.50);
137 title.setLocation(0.50, 0.75);
138 addSprite(title);
139 }close braces end code blocks and must match an earlier open brace
140
141 /**makes and creates sun as well as its movement */
142 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddSun()
143 {open braces start code blocks and must be matched with a close brace
144 sun=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("sun.gif");
145 sun.setSize(0.10);
146
147 addSprite(sun);
148
149 OutlineTransformer transformer;
150 transformer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.25,
151 0.1, 0.1,
152 0.5, -0.25,
153 1.0, 0.25,
154 0.99, 0.25,
155 0.5, -0.25,
156 0.1, 0.1);
157 transformer.setLooping(truetrue is the boolean value that is the opposite of false);
158
159 sun.addTransformer(transformer);
160 sun.setLocation(transformer.getCurrentPoint());
161 addSprite(sun);
162 }close braces end code blocks and must match an earlier open brace
163 /**sets up the game*/
164 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
165 {open braces start code blocks and must be matched with a close brace
166 makeAndAddSound();
167 makeAndAddGetHelp();
168 makeAndAddCarBackground();
169 makeAndAddSun();
170 makeAndAddSpaceship();
171 makeAndAddShot();
172 makeAndAddBoundary();
173 makeAndAddStrings();
174 schedule(newnew is used to create objects by calling the constructor ForcefieldBlinker(), 1);
175 playSoundImmediately();
176
177
178 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.25);
179 shot.setTracker(projectile);
180 }close braces end code blocks and must match an earlier open brace
181 /**Here we tell the shot what to bounce off of*/
182 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
183 {open braces start code blocks and must be matched with a close brace
184 shot.bounceOffOf(boundary);
185 shot.bounceOffOf(forcefield);
186 }close braces end code blocks and must match an earlier open brace
187 /**Causes a delay in the color change of the shot fired*/
188 classclass is a group of fields and methods used for making objects DelayedResponse extendsextends means to customize or extend the functionality of a class TimedAction
189 {open braces start code blocks and must be matched with a close brace
190 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
191
192 {open braces start code blocks and must be matched with a close brace
193 shot.setColor(Palette.getColor("Red"));
194
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 /**handle input and game events*/
198 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
199 {open braces start code blocks and must be matched with a close brace
200
201 handleCollisions();
202 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)
203 {open braces start code blocks and must be matched with a close brace
204
205
206 title.setVisible(falsefalse is a value for the boolean type and means not true);
207 artistname.setVisible(falsefalse is a value for the boolean type and means not true);
208 car.setLocation(getClick2D());
209 ding.play();
210
211 }close braces end code blocks and must match an earlier open brace
212 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'r')
213 {open braces start code blocks and must be matched with a close brace
214 schedule(newnew is used to create objects by calling the constructor DelayedResponse(), 2.5);
215 }close braces end code blocks and must match an earlier open brace
216
217 }close braces end code blocks and must match an earlier open brace
218 }close braces end code blocks and must match an earlier open brace
|