|
001 //package wackadot;
002 packagepackage is used to name the directory or folder a class is in Jayson.wackadot;
003
004 importimport means to make the classes and/or packages available in this program wiki.Wiki;
005 importimport means to make the classes and/or packages available in this program fang.*;
006 importimport means to make the classes and/or packages available in this program java.awt.*;
007 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
008
009 /**This is a fun, simple game I made using
010 * the FANG Engine.
011 * @authorthis is the Javadoc tag for documenting who created the source code Jayson Park
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 Wackadot 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 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[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 args)
016 {open braces start code blocks and must be matched with a close brace
017 Wackadot wack =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Wackadot();
018 wack.runAsApplication();
019 }close braces end code blocks and must match an earlier open brace
020
021 privateprivate is used to restrict access to the current class only 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 dots =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays7]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
022 privateprivate is used to restrict access to the current class only Color[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 colors =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Color[brackets are typically used to declare, initialize and index (indicate which element of) arrays6]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
023 privateprivate is used to restrict access to the current class only ImageSprite[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 stars =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays10]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
024 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
025 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;
026 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;
027 privateprivate is used to restrict access to the current class only StringSprite timerSprite;
028 Sound plus;
029 Sound minus;
030
031 //Pregame variable setting.
032 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
033 {open braces start code blocks and must be matched with a close brace
034 score =this assignment operator makes the left side equal to the right side 0;
035 timeLeft =this assignment operator makes the left side equal to the right side 60;
036 makeSprites();
037 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
038 plus =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("Arrow.wav"));
039 minus =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("Boom1.wav"));
040 }close braces end code blocks and must match an earlier open brace
041
042 //Updates timer every second
043 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
044 {open braces start code blocks and must be matched with a close brace
045 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
046 {open braces start code blocks and must be matched with a close brace
047 timeLeft--this is the decrement operator, which decreases the variable by 1;
048 updateTimer();
049 ifif executes the next statement only if the condition in parenthesis evaluates to true (timeLeft > 0)
050 {open braces start code blocks and must be matched with a close brace
051 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
052 }close braces end code blocks and must match an earlier open brace
053 }close braces end code blocks and must match an earlier open brace
054 }close braces end code blocks and must match an earlier open brace
055
056 //Creation of Sprites, sets the colors, shapes, etc.
057 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
058 {open braces start code blocks and must be matched with a close brace
059 Ellipse2D.Double circle =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Ellipse2D.Double(0, 0, 1, 1);
060 makeStars();
061 makeColors();
062 makeMouseDot(circle);
063 doubledouble is the type for numbers that can contain decimal fractions scaleDot =this assignment operator makes the left side equal to the right side 0;
064 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i < dots.length; i++this is the increment operator, which increases the variable by 1)
065 {open braces start code blocks and must be matched with a close brace
066 ifif executes the next statement only if the condition in parenthesis evaluates to true (i %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
067 scaleDot =this assignment operator makes the left side equal to the right side .15;
068 elseelse is what happens when the if condition is false
069 scaleDot =this assignment operator makes the left side equal to the right side .1;
070 otherDots(circle, colors[brackets are typically used to declare, initialize and index (indicate which element of) arraysi - 1]brackets are typically used to declare, initialize and index (indicate which element of) arrays, i, scaleDot);
071 }close braces end code blocks and must match an earlier open brace
072 makeScoreTimer();
073 }close braces end code blocks and must match an earlier open brace
074
075 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeStars()
076 {open braces start code blocks and must be matched with a close brace
077 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i < stars.length; i++this is the increment operator, which increases the variable by 1)
078 {open braces start code blocks and must be matched with a close brace
079 stars[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Star1.gif"));
080 stars[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(random.nextDouble(), random.nextDouble());
081 stars[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(.10);
082 canvas.addSprite(stars[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
083 }close braces end code blocks and must match an earlier open brace
084 }close braces end code blocks and must match an earlier open brace
085 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeScoreTimer()
086 {open braces start code blocks and must be matched with a close brace
087 scoreSprite =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Score: " +adds two numbers together or concatenates Strings together score);
088 scoreSprite.setHeight(0.1);
089 scoreSprite.rightJustify();
090 scoreSprite.topJustify();
091 scoreSprite.setLocation(1, 0);
092 canvas.addSprite(scoreSprite);
093 timerSprite =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Timer: " +adds two numbers together or concatenates Strings together timeLeft);
094 timerSprite.leftJustify();
095 timerSprite.topJustify();
096 timerSprite.setHeight(0.1);
097 timerSprite.setLocation(0, 0);
098 canvas.addSprite(timerSprite);
099 }close braces end code blocks and must match an earlier open brace
100
101 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeMouseDot(Ellipse2D.Double circle)
102 {open braces start code blocks and must be matched with a close brace
103 dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Sprite(circle);
104 dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(0.1);
105 dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(0.5, 0.5);
106 dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.RED);
107 canvas.addSprite(dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
108 }close braces end code blocks and must match an earlier open brace
109
110 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value otherDots(Ellipse2D.Double circle, Color dotColor, intint is the type for whole numbers and it is short for integer dotNum, doubledouble is the type for numbers that can contain decimal fractions scale)
111 {open braces start code blocks and must be matched with a close brace
112 dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysdotNum]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 1);
113 dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysdotNum]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(scale);
114 dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysdotNum]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(random.nextDouble(), random.nextDouble());
115 dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysdotNum]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(dotColor);
116 canvas.addSprite(dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysdotNum]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
117 }close braces end code blocks and must match an earlier open brace
118
119 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeColors()
120 {open braces start code blocks and must be matched with a close brace
121 colors[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side Color.RED;
122 colors[brackets are typically used to declare, initialize and index (indicate which element of) arrays1]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side Color.BLUE;
123 colors[brackets are typically used to declare, initialize and index (indicate which element of) arrays2]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side Color.GREEN;
124 colors[brackets are typically used to declare, initialize and index (indicate which element of) arrays3]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side Color.PINK;
125 colors[brackets are typically used to declare, initialize and index (indicate which element of) arrays4]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side Color.WHITE;
126 colors[brackets are typically used to declare, initialize and index (indicate which element of) arrays5]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side Color.YELLOW;
127 }close braces end code blocks and must match an earlier open brace
128
129 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
130 {open braces start code blocks and must be matched with a close brace
131 scoreSprite.setText("Score: " +adds two numbers together or concatenates Strings together score);
132 }close braces end code blocks and must match an earlier open brace
133
134 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
135 {open braces start code blocks and must be matched with a close brace
136 sprite.setLocation(random.nextDouble(), random.nextDouble());
137 }close braces end code blocks and must match an earlier open brace
138
139 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)
140 {open braces start code blocks and must be matched with a close brace
141 ifif executes the next statement only if the condition in parenthesis evaluates to true (timeLeft > 0)
142 {open braces start code blocks and must be matched with a close brace
143 Point2D.Double mouse =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getLocation();
144 dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(mouse);
145 handleCollisions();
146 }close braces end code blocks and must match an earlier open brace
147 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 'r')
148 {open braces start code blocks and must be matched with a close brace
149 score =this assignment operator makes the left side equal to the right side 0;
150 timeLeft =this assignment operator makes the left side equal to the right side 60;
151 updateTimer();
152 updateScore();
153 }close braces end code blocks and must match an earlier open brace
154 }close braces end code blocks and must match an earlier open brace
155
156 //Method to update the timer in the display.
157 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
158 {open braces start code blocks and must be matched with a close brace
159 timerSprite.setText("Timer: " +adds two numbers together or concatenates Strings together timeLeft);
160 }close braces end code blocks and must match an earlier open brace
161
162 //Method that holds all of the collisions with the mouse and the Sprites on screen.
163 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
164 {open braces start code blocks and must be matched with a close brace
165 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i < dots.length; i++this is the increment operator, which increases the variable by 1)
166 {open braces start code blocks and must be matched with a close brace
167 ifif executes the next statement only if the condition in parenthesis evaluates to true (dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays))
168 {open braces start code blocks and must be matched with a close brace
169 repositionRandomly(dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
170 ifif executes the next statement only if the condition in parenthesis evaluates to true (dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getColor().equals(dots[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getColor()))
171 {open braces start code blocks and must be matched with a close brace
172 ifif executes the next statement only if the condition in parenthesis evaluates to true (i ==this is the comparison operator which evaluates to true if both sides are the same 6)
173 dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(colors[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
174 elseelse is what happens when the if condition is false
175 dots[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(colors[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
176 score++this is the increment operator, which increases the variable by 1;
177 plus.play();
178 }close braces end code blocks and must match an earlier open brace
179 elseelse is what happens when the if condition is false
180 {open braces start code blocks and must be matched with a close brace
181 score--this is the decrement operator, which decreases the variable by 1;
182 minus.play();
183 }close braces end code blocks and must match an earlier open brace
184 updateScore();
185 }close braces end code blocks and must match an earlier open brace
186 }close braces end code blocks and must match an earlier open brace
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
190
|