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