|
001 packagepackage is used to name the directory or folder a class is in parameters;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007 importimport means to make the classes and/or packages available in this program java.util.*;
008
009 /**
010 * All about my game here.
011 * @authorthis is the Javadoc tag for documenting who created the source code Alyday
012 */
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 Twilight extendsextends means to customize or extend the functionality of a class GameLoop
014 {open braces start code blocks and must be matched with a close brace
015 //sets the stage to 0
016 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer stage=this assignment operator makes the left side equal to the right side0;
017 //sets up the Sprites
018 privateprivate is used to restrict access to the current class only StringSprite signature;
019
020 privateprivate is used to restrict access to the current class only StringSprite title;
021
022 privateprivate is used to restrict access to the current class only StringSprite title2;
023
024 privateprivate is used to restrict access to the current class only StringSprite clickHere=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Click Here To Start!");
025 {open braces start code blocks and must be matched with a close brace
026 clickHere.setLineHeight(0.07);
027 clickHere.setFontFamilyName("Bauhaus 93");
028 clickHere.setColor(Color.BLUE);
029 clickHere.setLocation(0.5, 0.5);
030 }close braces end code blocks and must match an earlier open brace
031 privateprivate is used to restrict access to the current class only ImageSprite dog1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Barking.jpg");
032 {open braces start code blocks and must be matched with a close brace
033 dog1.setScale(0.37);
034 dog1.setLocation(0.5, 0.75);
035 }close braces end code blocks and must match an earlier open brace
036 privateprivate is used to restrict access to the current class only ImageSprite dog2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Chihuahua.jpg");
037 {open braces start code blocks and must be matched with a close brace
038 dog2.setScale(0.37);
039 dog2.setLocation(0.5, 0.25);
040 }close braces end code blocks and must match an earlier open brace
041 privateprivate is used to restrict access to the current class only ImageSprite cat1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Cat.jpg");
042 {open braces start code blocks and must be matched with a close brace
043 cat1.setScale(0.37);
044 cat1.setLocation(0.2, 0.5);
045 }close braces end code blocks and must match an earlier open brace
046 privateprivate is used to restrict access to the current class only ImageSprite cat2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Meow.jpg");
047 {open braces start code blocks and must be matched with a close brace
048 cat2.setScale(0.37);
049 cat2.setLocation(0.8, 0.5);
050 }close braces end code blocks and must match an earlier open brace
051 privateprivate is used to restrict access to the current class only RectangleSprite button=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 0.5);
052 {open braces start code blocks and must be matched with a close brace
053 button.setScale(0.68);
054 button.setColor(newnew is used to create objects by calling the constructor Color(235,0,255));
055 button.setLocation(0.5, 0.5);
056 }close braces end code blocks and must match an earlier open brace
057 //sets up the sounds
058 privateprivate is used to restrict access to the current class only Sound bark=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound ("Doggrowl.wav");
059 privateprivate is used to restrict access to the current class only Sound highBark=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound ("Dogbark.wav");
060 privateprivate is used to restrict access to the current class only Sound meow=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound ("Catmeow2.wav");
061 privateprivate is used to restrict access to the current class only Sound otherMeow=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound ("Catyell.wav");
062 //sets up the tracker
063 privateprivate is used to restrict access to the current class only ProjectileTracker tracker1;
064 privateprivate is used to restrict access to the current class only ProjectileTracker tracker2;
065 privateprivate is used to restrict access to the current class only ProjectileTracker tracker3;
066 privateprivate is used to restrict access to the current class only ProjectileTracker tracker4;
067
068 /**sets up the game*/
069 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
070 {open braces start code blocks and must be matched with a close brace
071 setHelpText("This is a fun game that creates animal melodies. Press a,s,d, or f to play the animal sounds");
072 signature=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("by Abbie Lyday");
073 setupSignature();
074 title=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Melodic Meows and");
075 setupTitle();
076 title2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Beautiful Barks");
077 setupTitle2();
078 canvas.addSprite(signature);
079 canvas.addSprite(title);
080 canvas.addSprite(title2);
081 canvas.addSprite(button);
082 canvas.addSprite(clickHere);
083 }close braces end code blocks and must match an earlier open brace
084
085 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setupTitle2()
086 {open braces start code blocks and must be matched with a close brace
087 title2.setFontFamilyName("Curlz MT");
088 title2.setColor(newnew is used to create objects by calling the constructor Color(0,255,200));
089 title2.topJustify();
090 title2.setLineHeight(1.0);
091 title2.setWidth(0.7);
092 title2.setLocation(0.5, 0.15);
093 }close braces end code blocks and must match an earlier open brace
094
095 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setupTitle()
096 {open braces start code blocks and must be matched with a close brace
097 title.setFontFamilyName("Curlz MT");
098 title.setColor(newnew is used to create objects by calling the constructor Color(0,255,200));
099 title.topJustify();
100 title.setLineHeight(1.0);
101 title.setWidth(1.0);
102 title.setLocation(0.5, 0.01);
103 }close braces end code blocks and must match an earlier open brace
104
105 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value setupSignature()
106 {open braces start code blocks and must be matched with a close brace
107 signature.setLineHeight(0.07);
108 signature.setFontFamilyName("Blackadder ITC");
109 signature.setColor(newnew is used to create objects by calling the constructor Color(200,255,0));
110 signature.leftJustify();
111 signature.bottomJustify();
112 signature.setLocation(0.01, 1);
113 }close braces end code blocks and must match an earlier open brace
114
115 /**adds the sprites to the screen*/
116 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
117 {open braces start code blocks and must be matched with a close brace
118 canvas.addSprite (cat1);
119 canvas.addSprite (cat2);
120 canvas.addSprite (dog1);
121 canvas.addSprite (dog2);
122 }close braces end code blocks and must match an earlier open brace
123 classclass is a group of fields and methods used for making objects GoAway implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
124 {open braces start code blocks and must be matched with a close brace
125 intint is the type for whole numbers and it is short for integer timesToExecute=this assignment operator makes the left side equal to the right side50;
126
127 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
128 {open braces start code blocks and must be matched with a close brace
129 timesToExecute--this is the decrement operator, which decreases the variable by 1;
130 fade();
131 ifif executes the next statement only if the condition in parenthesis evaluates to true(timesToExecute>0 &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 &&) getPlayer().getKeyboard().getLastKey()!=this is the not equals operator which evaluates to true if both sides are different'q')
132 scheduleRelative(thisthis means the current object (the implicit parameter), 0.01);
133 elseelse is what happens when the if condition is false
134 {open braces start code blocks and must be matched with a close brace
135 canvas.removeAllSprites();
136 doStage1();
137 }close braces end code blocks and must match an earlier open brace
138 }close braces end code blocks and must match an earlier open brace
139 }close braces end code blocks and must match an earlier open brace
140 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value doStage1()
141 {open braces start code blocks and must be matched with a close brace
142 addSprites();
143 stage=this assignment operator makes the left side equal to the right side1;
144 }close braces end code blocks and must match an earlier open brace
145
146 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value fade()
147 {open braces start code blocks and must be matched with a close brace
148 Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays all=this assignment operator makes the left side equal to the right sidecanvas.getAllSprites();
149 forfor is a looping structure for repeatedly executing a block of code(Sprite single: all)
150 {open braces start code blocks and must be matched with a close brace
151 Color color=this assignment operator makes the left side equal to the right sidesingle.getColor();
152 single.setColor(newnew is used to create objects by calling the constructor Color(color.getRed(), color.getGreen(),
153 color.getBlue(),
154 Math.max(0, color.getAlpha()-4)));
155 }close braces end code blocks and must match an earlier open brace
156 }close braces end code blocks and must match an earlier open brace
157 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value beginStage0()
158 {open braces start code blocks and must be matched with a close brace
159 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
160 ifif executes the next statement only if the condition in parenthesis evaluates to true(click!=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)
161 {open braces start code blocks and must be matched with a close brace
162 scheduleRelative(newnew is used to create objects by calling the constructor GoAway(), 1);
163 stage=this assignment operator makes the left side equal to the right side-1;
164 }close braces end code blocks and must match an earlier open brace
165 }close braces end code blocks and must match an earlier open brace
166
167 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCat(Sprite cat, intint is the type for whole numbers and it is short for integer trackerNumber, Sound sound, charchar is the type for a single letter or symbol and it is short for character letter)
168 {open braces start code blocks and must be matched with a close brace
169 ProjectileTracker tracker;
170 ifif executes the next statement only if the condition in parenthesis evaluates to true(trackerNumber==this is the comparison operator which evaluates to true if both sides are the same1) tracker=this assignment operator makes the left side equal to the right sidetracker1;
171 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(trackerNumber==this is the comparison operator which evaluates to true if both sides are the same2) tracker=this assignment operator makes the left side equal to the right sidetracker2;
172 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(trackerNumber==this is the comparison operator which evaluates to true if both sides are the same3) tracker=this assignment operator makes the left side equal to the right sidetracker3;
173 elseelse is what happens when the if condition is false tracker=this assignment operator makes the left side equal to the right sidetracker4;
174 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 sameletter)
175 {open braces start code blocks and must be matched with a close brace
176 sound.play();
177 tracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(
178 random.nextDouble()-0.5,
179 random.nextDouble()-0.5);
180 ifif executes the next statement only if the condition in parenthesis evaluates to true(trackerNumber==this is the comparison operator which evaluates to true if both sides are the same1) tracker1=this assignment operator makes the left side equal to the right sidetracker;
181 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(trackerNumber==this is the comparison operator which evaluates to true if both sides are the same2) tracker2=this assignment operator makes the left side equal to the right sidetracker;
182 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(trackerNumber==this is the comparison operator which evaluates to true if both sides are the same3) tracker3=this assignment operator makes the left side equal to the right sidetracker;
183 elseelse is what happens when the if condition is false tracker4=this assignment operator makes the left side equal to the right sidetracker;
184 tracker.setAngularVelocity(1.0);
185 cat.setTracker(tracker);
186 }close braces end code blocks and must match an earlier open brace
187 ifif executes the next statement only if the condition in parenthesis evaluates to true(cat.getLocation().y>1 ||this is boolean or, meaning if either or both are true then the result is true cat.getLocation().y<0)
188 {open braces start code blocks and must be matched with a close brace
189 Point2D.Double direction=this assignment operator makes the left side equal to the right sidetracker.getVelocity();
190 direction.y*=this multiplies the variable on the left by the value on the right and stores the result in the variable-1;
191 tracker.setVelocity(direction);
192 tracker.setAngularVelocity(-tracker.getAngularVelocity()*0.95);
193 }close braces end code blocks and must match an earlier open brace
194 ifif executes the next statement only if the condition in parenthesis evaluates to true(cat.getLocation().x>1 ||this is boolean or, meaning if either or both are true then the result is true cat.getLocation().x<0)
195 {open braces start code blocks and must be matched with a close brace
196 Point2D.Double direction=this assignment operator makes the left side equal to the right sidetracker.getVelocity();
197 direction.x*=this multiplies the variable on the left by the value on the right and stores the result in the variable-1;
198 tracker.setVelocity(direction);
199 tracker.setAngularVelocity(-tracker.getAngularVelocity()*0.95);
200 }close braces end code blocks and must match an earlier open brace
201 }close braces end code blocks and must match an earlier open brace
202
203 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value beginStage1()
204 {open braces start code blocks and must be matched with a close brace
205 handleCat(dog1, 1, bark, 'a');
206 handleCat(dog2, 2, highBark, 's');
207 handleCat(cat1, 3, meow, 'd');
208 handleCat(cat2, 4, otherMeow, 'f');
209 }close braces end code blocks and must match an earlier open brace
210 /**handle input and game events*/
211 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)
212 {open braces start code blocks and must be matched with a close brace
213 ifif executes the next statement only if the condition in parenthesis evaluates to true(stage==this is the comparison operator which evaluates to true if both sides are the same0)
214 {open braces start code blocks and must be matched with a close brace
215 beginStage0();
216 }close braces end code blocks and must match an earlier open brace
217 ifif executes the next statement only if the condition in parenthesis evaluates to true(stage==this is the comparison operator which evaluates to true if both sides are the same1)
218 {open braces start code blocks and must be matched with a close brace
219 beginStage1();
220 }close braces end code blocks and must match an earlier open brace
221 }close braces end code blocks and must match an earlier open brace
222 }close braces end code blocks and must match an earlier open brace
|