|
001 packagepackage is used to name the directory or folder a class is in matt_mitrovich_kcie_green;
002 //start auto-imports
003 importimport means to make the classes and/or packages available in this program java.util.*;
004 //end auto-imports
005
006 importimport means to make the classes and/or packages available in this program fang.*;
007 importimport means to make the classes and/or packages available in this program java.awt.*;
008 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
009
010 /**
011 * All about my game.
012 * @authornull My Name Here
013 */
014 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 Breakout2 extendsextends means to customize or extend the functionality of a class Game
015 {open braces start code blocks and must be matched with a close brace
016 privateprivate is used to restrict access to the current class only ArrayList<Sprite> alltargets;
017 privateprivate is used to restrict access to the current class only ImageSprite ball;
018 privateprivate is used to restrict access to the current class only ProjectileTransformer sonicTransformer;
019 privateprivate is used to restrict access to the current class only RectangleSprite paddle, obsticle;
020 privateprivate is used to restrict access to the current class only OutlineSprite boundry, boundry2,boundry3;
021 privateprivate is used to restrict access to the current class only StringSprite points, lives;
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 setLife=this assignment operator makes the left side equal to the right side3;
023
024 /**sets up the game*/
025 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
026 {open braces start code blocks and must be matched with a close brace
027
028 makeBricks();
029 makeBall();
030 makePaddle();
031 boundry();
032 blinkyThing();
033 pointTracker();
034 lives();
035 helpScreen();
036 }close braces end code blocks and must match an earlier open brace
037 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value helpScreen()
038 {open braces start code blocks and must be matched with a close brace
039
040 {open braces start code blocks and must be matched with a close brace
041 String helpText=this assignment operator makes the left side equal to the right side
042 " welcome to the sonic edition of brick breaker<br>"+adds two numbers together or concatenates Strings together
043 " move the paddle to destroy the bricks<br>"+adds two numbers together or concatenates Strings together
044 " if your ball goes away hit R to respawn the ball<br>"+adds two numbers together or concatenates Strings together
045 " if your ball goes away again hit T to respawn the ball<br>"+adds two numbers together or concatenates Strings together
046 " if your ball goes away a last time hit Y to respawn the ball<br>";
047 setHelpText(helpText);
048 }close braces end code blocks and must match an earlier open brace
049
050
051 }close braces end code blocks and must match an earlier open brace
052 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks()
053 {open braces start code blocks and must be matched with a close brace
054 //*had Dr.Jenkins help us with this and referenced space invaders
055 alltargets=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
056 intint is the type for whole numbers and it is short for integer targetsAcross=this assignment operator makes the left side equal to the right side10;
057 intint is the type for whole numbers and it is short for integer targetsDown=this assignment operator makes the left side equal to the right side4;
058 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 n=this assignment operator makes the left side equal to the right side0; n<targetsDown; n++this is the increment operator, which increases the variable by 1)
059 {open braces start code blocks and must be matched with a close brace
060 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 m=this assignment operator makes the left side equal to the right side1; m<=this evaluates to true if the left side is not more than the right sidetargetsAcross; m++this is the increment operator, which increases the variable by 1)
061 {open braces start code blocks and must be matched with a close brace
062 //* Referenced Array code from jam/SpaceInvaders*/
063 ImageSprite targets=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Goal_ring.jpg");
064 targets.setSize(.7/ targetsAcross);
065 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side0.5/targetsAcross+adds two numbers together or concatenates Strings together1.0/targetsAcross*(m-1);
066 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.5/targetsAcross+adds two numbers together or concatenates Strings together(n+adds two numbers together or concatenates Strings together0.0)/targetsAcross;
067 targets.setLocation(x, y);
068 addSprite(targets);
069
070 alltargets.add(targets)
071 ;
072 }close braces end code blocks and must match an earlier open brace
073 }close braces end code blocks and must match an earlier open brace
074 }close braces end code blocks and must match an earlier open brace
075 /** adds three boundry lines that are small skinny and black so it appears that they are not there when the game starts*/
076 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value boundry()
077 {open braces start code blocks and must be matched with a close brace
078 boundry=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 0, 2));
079 boundry.setSize(2);
080 boundry.setLocation(0,0);
081 boundry.setColor(Palette.getColor("black"));
082 addSprite(boundry);
083
084 boundry2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 0, 2));
085 boundry2.setSize(2);
086 boundry2.setLocation(1,0);
087 boundry2.setColor(Palette.getColor("Black"));
088 addSprite(boundry2);
089
090 boundry3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor LineSprite(0, 0, 2, 0));
091 boundry3.setSize(2);
092 boundry3.setLocation(0,0);
093 boundry3.setColor(Palette.getColor("black"));
094 addSprite(boundry3);
095
096 }close braces end code blocks and must match an earlier open brace
097 /** adds the ball*/
098 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBall()
099 {open braces start code blocks and must be matched with a close brace
100
101 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Ssth.png");
102 ball.setSize(0.09);
103 ball.setLocation(0.5, 0.70);
104 ball.setVisible(truetrue is the boolean value that is the opposite of false);
105 addSprite(ball);
106 sonicTransformer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.3, 0.3);
107 ball.setTracker(sonicTransformer);
108 }close braces end code blocks and must match an earlier open brace
109 /**adds the paddle and makes it spin forfor is a looping structure for repeatedly executing a block of code an extra challenge*/
110 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePaddle()
111 {open braces start code blocks and must be matched with a close brace
112
113 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(0.8,0.3);
114 paddle.setSize(0.15);
115 paddle.setLocation(0.5,0.9);
116 paddle.setColor(getColor("Green"));
117 addSprite(paddle);
118
119 Spinner spinner;
120 spinner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
121 spinner.setRotationDegrees(100);
122 paddle.addTransformer(spinner);
123 }close braces end code blocks and must match an earlier open brace
124
125 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value paddleMovement()
126 {open braces start code blocks and must be matched with a close brace
127 paddle.setX(getMouseX());
128 }close braces end code blocks and must match an earlier open brace
129 /**handels what the ball bounces off of*/
130 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bounceing()
131 {open braces start code blocks and must be matched with a close brace
132 ball.bounceOffOf(paddle);
133 ball.bounceOffOf(boundry);
134 ball.bounceOffOf(boundry2);
135 ball.bounceOffOf(boundry3);
136 ball.bounceOffOf(obsticle);
137 pointsWithCollision();
138
139
140 }close braces end code blocks and must match an earlier open brace
141 /** thisthis means the current object (the implicit parameter) adds a square in the middle of the screen that spins and acts as an obsticle*/
142 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value blinkyThing()
143 {open braces start code blocks and must be matched with a close brace
144
145 obsticle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1,1);
146 obsticle.setSize(0.07);
147 obsticle.setLocation(0.5, 0.6);
148 addSprite(obsticle);
149
150
151 Spinner spinner;
152 spinner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
153 spinner.setRotationDegrees(45);
154 obsticle.addTransformer(spinner);
155 }close braces end code blocks and must match an earlier open brace
156
157 /**looked at space invaders fook thisthis means the current object (the implicit parameter) code tried to make it work on own still cant get it but havent copied it to make it work because
158 its not mine but i did use the basic code forfor is a looping structure for repeatedly executing a block of code the string from space invaders*/
159 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value lives()
160 {open braces start code blocks and must be matched with a close brace
161
162 setLives(3);
163 lives =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Lives: "+adds two numbers together or concatenates Strings togethergetLives());
164 lives.setSize(0.20);
165 lives.leftJustify();
166 lives.setLocation(.1, .9);
167 lives.setColor(getColor("White"));
168 addSprite(lives);
169 }close braces end code blocks and must match an earlier open brace
170 /**forfor is a looping structure for repeatedly executing a block of code the points we looked at everyones code because we were having a hard
171 time with it and we ended up using newmans code forfor is a looping structure for repeatedly executing a block of code the most part with a few
172 variations*/
173 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value pointTracker()
174 {open braces start code blocks and must be matched with a close brace
175
176 points=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("0");
177 points.setSize(0.10);
178 points.setColor(getColor("white"));
179 points.setLocation(0.9, 0.9);
180 addSprite(points);
181 }close braces end code blocks and must match an earlier open brace
182 /**keeps track of when the ball hits the bricks*/
183 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value pointsWithCollision()
184 {open braces start code blocks and must be matched with a close brace
185 forfor is a looping structure for repeatedly executing a block of code(Sprite single: alltargets)
186 {open braces start code blocks and must be matched with a close brace
187 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.isVisible()==this is the comparison operator which evaluates to true if both sides are the sametruetrue is the boolean value that is the opposite of false &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 &&) single.intersects(ball))
188 {open braces start code blocks and must be matched with a close brace
189 ball.bounceOffOf(single);
190
191 single.setVisible(falsefalse is a value for the boolean type and means not true);
192 intint is the type for whole numbers and it is short for integer startscores =this assignment operator makes the left side equal to the right side getScore();
193 setScore(startscores+adds two numbers together or concatenates Strings together1);
194 }close braces end code blocks and must match an earlier open brace
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 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value hit()
198 {open braces start code blocks and must be matched with a close brace
199
200 forfor is a looping structure for repeatedly executing a block of code(Sprite single: alltargets)
201 {open braces start code blocks and must be matched with a close brace
202 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.isVisible() &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 &&) ball.intersects(single))
203 {open braces start code blocks and must be matched with a close brace
204
205
206 ball.bounceOffOf(single);
207 single.setVisible(falsefalse is a value for the boolean type and means not true);
208 }close braces end code blocks and must match an earlier open brace
209 }close braces end code blocks and must match an earlier open brace
210 }close braces end code blocks and must match an earlier open brace
211
212
213
214
215
216
217
218
219 /**handle input and game events*/
220 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
221 {open braces start code blocks and must be matched with a close brace
222 pointsWithCollision();
223 bounceing();
224 paddleMovement();
225 hit();
226
227 /** keeps track of score*/
228 points.setText(""+adds two numbers together or concatenates Strings togethergetScore());
229 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'r')
230 {open braces start code blocks and must be matched with a close brace
231 setLives(setLife-1);
232 lives.setText("Lives:"+adds two numbers together or concatenates Strings togethergetLives());
233 ball.setLocation(.5, .7);
234 }close braces end code blocks and must match an earlier open brace
235 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same't')
236 {open braces start code blocks and must be matched with a close brace
237 setLives(setLife-2);
238 lives.setText("Lives:"+adds two numbers together or concatenates Strings togethergetLives());
239 ball.setLocation(.5, .7);
240 }close braces end code blocks and must match an earlier open brace
241 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'y')
242 {open braces start code blocks and must be matched with a close brace
243 setLives(setLife-3);
244 lives.setText("Lives:"+adds two numbers together or concatenates Strings togethergetLives());
245 ball.setLocation(.5, .7);
246 }close braces end code blocks and must match an earlier open brace
247 }close braces end code blocks and must match an earlier open brace
248 }close braces end code blocks and must match an earlier open brace
|