|
001 packagepackage is used to name the directory or folder a class is in William_Anderson;
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
008 /**
009 * This is a funs simple game I made using the Fang Engine.
010 * @authorthis is the Javadoc tag for documenting who created the source code William Anderson.
011 */
012 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 WackADot extendsextends means to customize or extend the functionality of a class GameLoop
013
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 voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
016 {open braces start code blocks and must be matched with a close brace
017 sprite.setLocation(
018 random.nextDouble(),
019 random.nextDouble());
020 }close braces end code blocks and must match an earlier open brace
021
022 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
023 {open braces start code blocks and must be matched with a close brace
024 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot))
025 {open braces start code blocks and must be matched with a close brace
026 repositionRandomly(blueDot);
027 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
028 {open braces start code blocks and must be matched with a close brace
029 dot.setColor(Color.RED);
030 score--this is the decrement operator, which decreases the variable by 1;
031 }close braces end code blocks and must match an earlier open brace
032 elseelse is what happens when the if condition is false
033 {open braces start code blocks and must be matched with a close brace
034 score--this is the decrement operator, which decreases the variable by 1;
035 }close braces end code blocks and must match an earlier open brace
036 updateScore();
037 }close braces end code blocks and must match an earlier open brace
038 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot1))
039 {open braces start code blocks and must be matched with a close brace
040 repositionRandomly(blueDot1);
041 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
042 {open braces start code blocks and must be matched with a close brace
043 dot.setColor(Color.RED);
044 score--this is the decrement operator, which decreases the variable by 1;
045 }close braces end code blocks and must match an earlier open brace
046 elseelse is what happens when the if condition is false
047 {open braces start code blocks and must be matched with a close brace
048 score--this is the decrement operator, which decreases the variable by 1;
049 }close braces end code blocks and must match an earlier open brace
050 updateScore();
051 }close braces end code blocks and must match an earlier open brace
052 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(blueDot2))
053 {open braces start code blocks and must be matched with a close brace
054 repositionRandomly(blueDot2);
055 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.BLUE))
056 {open braces start code blocks and must be matched with a close brace
057 dot.setColor(Color.RED);
058 score--this is the decrement operator, which decreases the variable by 1;
059 }close braces end code blocks and must match an earlier open brace
060 elseelse is what happens when the if condition is false
061 {open braces start code blocks and must be matched with a close brace
062 score--this is the decrement operator, which decreases the variable by 1;
063 }close braces end code blocks and must match an earlier open brace
064 updateScore();
065 }close braces end code blocks and must match an earlier open brace
066 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(redDot))
067 {open braces start code blocks and must be matched with a close brace
068 repositionRandomly(redDot);
069 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.getColor().equals(Color.RED))
070 {open braces start code blocks and must be matched with a close brace
071 dot.setColor(Color.BLUE);
072 score++this is the increment operator, which increases the variable by 1;
073
074 }close braces end code blocks and must match an earlier open brace
075 elseelse is what happens when the if condition is false
076 {open braces start code blocks and must be matched with a close brace
077 score++this is the increment operator, which increases the variable by 1;
078 }close braces end code blocks and must match an earlier open brace
079 updateScore();
080 }close braces end code blocks and must match an earlier open brace
081 }close braces end code blocks and must match an earlier open brace
082 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)
083 {open braces start code blocks and must be matched with a close brace
084 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
085 {open braces start code blocks and must be matched with a close brace
086 Point2D.Double mouse=this assignment operator makes the left side equal to the right side
087 getPlayer().getMouse().getLocation();
088 dot.setLocation(mouse);
089 handleCollisions();
090 }close braces end code blocks and must match an earlier open brace
091 }close braces end code blocks and must match an earlier open brace
092 privateprivate is used to restrict access to the current class only Sprite dot;
093 privateprivate is used to restrict access to the current class only Sprite redDot;
094 privateprivate is used to restrict access to the current class only Sprite blueDot;
095 privateprivate is used to restrict access to the current class only Sprite blueDot1;
096 privateprivate is used to restrict access to the current class only Sprite blueDot2;
097 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
098 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;
099 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;
100 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
101
102
103 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
104 {open braces start code blocks and must be matched with a close brace
105 score=this assignment operator makes the left side equal to the right side0;
106 timeLeft=this assignment operator makes the left side equal to the right side60;
107 makeSprites();
108 addSprites();
109 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
110 }close braces end code blocks and must match an earlier open brace
111 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
112 {open braces start code blocks and must be matched with a close brace
113 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
114 {open braces start code blocks and must be matched with a close brace
115 timeLeft--this is the decrement operator, which decreases the variable by 1;
116 updateTimer();
117 ifif executes the next statement only if the condition in parenthesis evaluates to true(timeLeft>0)
118 {open braces start code blocks and must be matched with a close brace
119 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
120 }close braces end code blocks and must match an earlier open brace
121 }close braces end code blocks and must match an earlier open brace
122 }close braces end code blocks and must match an earlier open brace
123
124 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
125 {open braces start code blocks and must be matched with a close brace
126 Ellipse2D.Double circle=this assignment operator makes the left side equal to the right side
127 newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
128
129 dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite(circle);
130 dot.setScale(0.1);
131 dot.setLocation(0.5, 0.5);
132 dot.setColor(Color.RED);
133
134 redDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Delorean2.jpg"));
135 redDot.setScale(.25);
136 redDot.setLocation(
137 random.nextDouble(),
138 random.nextDouble());
139 redDot.setColor(Color.RED);
140
141 blueDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
142 blueDot.setScale(0.5);
143 blueDot.setLocation(
144 random.nextDouble(),
145 random.nextDouble());
146
147 blueDot.setColor(Color.BLUE);
148
149
150 blueDot1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
151 blueDot1.setScale(0.5);
152 blueDot1.setLocation(
153 random.nextDouble(),
154 random.nextDouble());
155
156 blueDot1.setColor(Color.BLUE);
157
158
159 blueDot2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
160 blueDot2.setScale(0.5);
161 blueDot2.setLocation(
162 random.nextDouble(),
163 random.nextDouble());
164
165 blueDot2.setColor(Color.BLUE);
166
167 scoreSprite=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 togetherscore);
168 scoreSprite.setHeight(0.1);
169 scoreSprite.rightJustify();
170 scoreSprite.topJustify();
171 scoreSprite.setLocation(1, 0);
172 timerSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
173 timerSprite.leftJustify();
174 timerSprite.topJustify();
175 timerSprite.setHeight(0.1);
176 timerSprite.setLocation(0, 0);
177 }close braces end code blocks and must match an earlier open brace
178 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
179 {open braces start code blocks and must be matched with a close brace
180 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
181 }close braces end code blocks and must match an earlier open brace
182 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
183 {open braces start code blocks and must be matched with a close brace
184 canvas.addSprite(dot);
185 canvas.addSprite(redDot);
186 canvas.addSprite(blueDot);
187 canvas.addSprite(blueDot1);
188 canvas.addSprite(blueDot2);
189 canvas.addSprite(scoreSprite);
190 canvas.addSprite(timerSprite);
191 }close braces end code blocks and must match an earlier open brace
192 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
193 {open braces start code blocks and must be matched with a close brace
194 timerSprite.setText("Timer: "+adds two numbers together or concatenates Strings togethertimeLeft);
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
|