|
001 packagepackage is used to name the directory or folder a class is in cray;
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 * All about my game here.
010 * @authorthis is the Javadoc tag for documenting who created the source code Cray
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 BreakOut extendsextends means to customize or extend the functionality of a class GameLoop
013 {open braces start code blocks and must be matched with a close brace
014 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 bricks;
015 privateprivate is used to restrict access to the current class only Sprite paddle,ball;
016 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
017 privateprivate is used to restrict access to the current class only Sprite leftWall;
018 privateprivate is used to restrict access to the current class only Sprite rightWall;
019 privateprivate is used to restrict access to the current class only Sprite topWall;
020 privateprivate is used to restrict access to the current class only Sprite bottomWall;
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=this assignment operator makes the left side equal to the right side0;
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 lives=this assignment operator makes the left side equal to the right side3;
023 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
024 privateprivate is used to restrict access to the current class only StringSprite lifeSprite;
025 privateprivate is used to restrict access to the current class only StringSprite lose;
026 privateprivate is used to restrict access to the current class only StringSprite win;
027 privateprivate is used to restrict access to the current class only Sound clip=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Pong.wav");
028 privateprivate is used to restrict access to the current class only Sound clip2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Doh.wav");
029 privateprivate is used to restrict access to the current class only Sound clip3=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Coin.wav");
030 privateprivate is used to restrict access to the current class only Sound clip4=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Kidscheer.wav");
031
032
033
034 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
035 {open braces start code blocks and must be matched with a close brace
036 makeSprites();
037 makeBricks();
038 makeWalls();
039 }close braces end code blocks and must match an earlier open brace
040
041 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks()
042 {open braces start code blocks and must be matched with a close brace
043 intint is the type for whole numbers and it is short for integer index=this assignment operator makes the left side equal to the right side0;
044 bricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays60]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
045 intint is the type for whole numbers and it is short for integer bricksHigh=this assignment operator makes the left side equal to the right side6;
046 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side.1;
047 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side.4;
048 doubledouble is the type for numbers that can contain decimal fractions brickDistanceHigh=this assignment operator makes the left side equal to the right sideendLocationY-startLocationY;
049 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 side0; i<bricksHigh; i++this is the increment operator, which increases the variable by 1)
050 {open braces start code blocks and must be matched with a close brace
051
052 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sidei*brickDistanceHigh/(bricksHigh-1)+adds two numbers together or concatenates Strings togetherstartLocationY;
053 intint is the type for whole numbers and it is short for integer bricksAcross=this assignment operator makes the left side equal to the right side10;
054 doubledouble is the type for numbers that can contain decimal fractions startLocationX=this assignment operator makes the left side equal to the right side.1;
055 doubledouble is the type for numbers that can contain decimal fractions endLocationX=this assignment operator makes the left side equal to the right side1-startLocationX;
056 doubledouble is the type for numbers that can contain decimal fractions brickDistanceAcross=this assignment operator makes the left side equal to the right sideendLocationX-startLocationX;
057 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 j=this assignment operator makes the left side equal to the right side0; j<bricksAcross; j++this is the increment operator, which increases the variable by 1)
058 {open braces start code blocks and must be matched with a close brace
059 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidej*brickDistanceAcross/(bricksAcross-1)+adds two numbers together or concatenates Strings togetherstartLocationX;
060 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]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 sidenewnew is used to create objects by calling the constructor RectangleSprite(2,1);
061 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setScale(.08);
062 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setLocation(x,y);
063 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.setColor(Color.GREEN);
064 canvas.addSprite(bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysindex]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
065 index++this is the increment operator, which increases the variable by 1;
066 }close braces end code blocks and must match an earlier open brace
067 }close braces end code blocks and must match an earlier open brace
068 }close braces end code blocks and must match an earlier open brace
069
070 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeWalls()
071 {open braces start code blocks and must be matched with a close brace
072 leftWall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,20);
073 leftWall.setScale(1);
074 leftWall.setLocation(0,.5);
075 leftWall.setColor(Color.YELLOW);
076 canvas.addSprite(leftWall);
077
078 rightWall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,20);
079 rightWall.setScale(1);
080 rightWall.setLocation(1,.5);
081 rightWall.setColor(Color.YELLOW);
082 canvas.addSprite(rightWall);
083
084 topWall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(20,1);
085 topWall.setScale(1);
086 topWall.setLocation(.5,0);
087 topWall.setColor(Color.YELLOW);
088 canvas.addSprite(topWall);
089
090 }close braces end code blocks and must match an earlier open brace
091
092 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
093 {open braces start code blocks and must be matched with a close brace
094 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(8,1);
095 paddle.setScale(.25);
096 paddle.setLocation(.5,.9);
097 paddle.setColor(Color.BLUE);
098 canvas.addSprite(paddle);
099
100 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,1);
101 ball.setScale(.05);
102 ball.setLocation(.5,.7);
103 ball.setColor(Color.RED);
104 canvas.addSprite(ball);
105
106 doubledouble is the type for numbers that can contain decimal fractions angle=this assignment operator makes the left side equal to the right siderandom.nextDouble()*Math.PI;
107
108 tracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(Math.cos(angle),
109 .5);
110
111 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);
112 scoreSprite.setHeight(.05);
113 scoreSprite.setColor(Color.ORANGE);
114 scoreSprite.setLocation(.15, .95);
115 canvas.addSprite(scoreSprite);
116
117 lifeSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Lives: "+adds two numbers together or concatenates Strings togetherlives);
118 lifeSprite.setHeight(.05);
119 lifeSprite.setColor(Color.WHITE);
120 lifeSprite.setLocation(.15, .87);
121 canvas.addSprite(lifeSprite);
122
123 lose=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("YOU LOSE");
124 lose.setHeight(.15);
125 lose.setColor(Color.RED);
126 lose.setLocation(.5, .5);
127
128
129 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("WINNER!!!");
130 win.setHeight(.15);
131 win.setColor(Color.GREEN);
132 win.setLocation(.5, .5);
133
134
135 }close braces end code blocks and must match an earlier open brace
136
137 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)
138 {open braces start code blocks and must be matched with a close brace
139 ifif executes the next statement only if the condition in parenthesis evaluates to true(lives>0 &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 &&) score<60)
140 {open braces start code blocks and must be matched with a close brace
141 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getLocation().x;
142 paddle.setLocation(x,paddle.getLocation().y);
143
144 Point2D.Double lClick=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getLeftClickLocation();
145 Point2D.Double rClick=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getRightClickLocation();
146
147 ifif executes the next statement only if the condition in parenthesis evaluates to true(lClick!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object)
148 {open braces start code blocks and must be matched with a close brace
149 ball.setTracker(tracker);
150 }close braces end code blocks and must match an earlier open brace
151
152
153 ifif executes the next statement only if the condition in parenthesis evaluates to true(rClick!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object)
154 {open braces start code blocks and must be matched with a close brace
155 score=this assignment operator makes the left side equal to the right side60;
156 updateScore();
157 }close braces end code blocks and must match an earlier open brace
158
159
160
161 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
162 {open braces start code blocks and must be matched with a close brace
163 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(paddle.getShape(), ball.getShape());
164 tracker.bounce(normal);
165 }close braces end code blocks and must match an earlier open brace
166
167 wallBounce();
168 hitBricks();
169 }close braces end code blocks and must match an earlier open brace
170 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(lives==this is the comparison operator which evaluates to true if both sides are the same0)
171 {open braces start code blocks and must be matched with a close brace
172 canvas.addSprite(lose);
173 }close braces end code blocks and must match an earlier open brace
174 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(score==this is the comparison operator which evaluates to true if both sides are the same60)
175 {open braces start code blocks and must be matched with a close brace
176 canvas.addSprite(win);
177 ball.setTracker(nullnull is the value used to refer to a non-existant object);
178
179 }close braces end code blocks and must match an earlier open brace
180
181
182
183
184
185 }close braces end code blocks and must match an earlier open brace
186
187
188 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value hitBricks()
189 {open braces start code blocks and must be matched with a close brace
190 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 side0; i<bricks.length; i++this is the increment operator, which increases the variable by 1)
191 {open braces start code blocks and must be matched with a close brace
192 ifif executes the next statement only if the condition in parenthesis evaluates to true(bricks[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.intersects(ball) &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 &&) bricks[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.isVisible())
193 {open braces start code blocks and must be matched with a close brace
194 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(bricks[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.getShape(), ball.getShape());
195 tracker.bounce(normal);
196 bricks[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.setVisible(falsefalse is a value for the boolean type and means not true);
197 score++this is the increment operator, which increases the variable by 1;
198 updateScore();
199 clip3.play();
200
201 }close braces end code blocks and must match an earlier open brace
202 }close braces end code blocks and must match an earlier open brace
203 }close braces end code blocks and must match an earlier open brace
204
205
206 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value wallBounce()
207 {open braces start code blocks and must be matched with a close brace
208 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftWall.intersects(ball))
209 {open braces start code blocks and must be matched with a close brace
210 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(leftWall.getShape(), ball.getShape());
211 tracker.bounce(normal);
212 clip.play();
213 }close braces end code blocks and must match an earlier open brace
214 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightWall.intersects(ball))
215 {open braces start code blocks and must be matched with a close brace
216 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(rightWall.getShape(), ball.getShape());
217 tracker.bounce(normal);
218 clip.play();
219 }close braces end code blocks and must match an earlier open brace
220 ifif executes the next statement only if the condition in parenthesis evaluates to true(topWall.intersects(ball))
221 {open braces start code blocks and must be matched with a close brace
222 doubledouble is the type for numbers that can contain decimal fractions normal=this assignment operator makes the left side equal to the right sideSprite.getNormalVector(topWall.getShape(), ball.getShape());
223 tracker.bounce(normal);
224 clip.play();
225 }close braces end code blocks and must match an earlier open brace
226 ifif executes the next statement only if the condition in parenthesis evaluates to true(ball.getLocation().y>1)
227 {open braces start code blocks and must be matched with a close brace
228 ball.setLocation(.5,.7);
229 lives--this is the decrement operator, which decreases the variable by 1;
230 updateScore();
231 ball.setTracker(nullnull is the value used to refer to a non-existant object);
232 clip2.play();
233 }close braces end code blocks and must match an earlier open brace
234 }close braces end code blocks and must match an earlier open brace
235 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
236 {open braces start code blocks and must be matched with a close brace
237 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
238 lifeSprite.setText("Lives: "+adds two numbers together or concatenates Strings togetherlives);
239 }close braces end code blocks and must match an earlier open brace
240 }close braces end code blocks and must match an earlier open brace
|