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