|
001 packagepackage is used to name the directory or folder a class is in NickandChris;
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 Nmckee
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 blocks[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;
015 privateprivate is used to restrict access to the current class only StringSprite displayScore, displayLives, win, lose;
016 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, score;
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 Sprite paddle;
022 privateprivate is used to restrict access to the current class only Sprite ball;
023 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
024
025 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
026 {open braces start code blocks and must be matched with a close brace
027 lives=this assignment operator makes the left side equal to the right side4;
028 score=this assignment operator makes the left side equal to the right side0;
029 blocks=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) arrays50]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
030 makeBlocks();
031 makeSprites();
032 makeTracker();
033 makeBounces();
034 }close braces end code blocks and must match an earlier open brace
035
036 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
037 {open braces start code blocks and must be matched with a close brace
038 makeScore();
039 makeLives();
040 makePaddleandBall();
041 makeWalls();
042 makeOutcome();
043 }close braces end code blocks and must match an earlier open brace
044
045 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBlocks()
046 {open braces start code blocks and must be matched with a close brace
047 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;
048 intint is the type for whole numbers and it is short for integer numBlocksHigh=this assignment operator makes the left side equal to the right side5;
049 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side0.1;
050 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side0.3;
051 doubledouble is the type for numbers that can contain decimal fractions distanceHigh=this assignment operator makes the left side equal to the right sideendLocationY-startLocationY;
052 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<numBlocksHigh; j++this is the increment operator, which increases the variable by 1)
053 {open braces start code blocks and must be matched with a close brace
054 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sidej*distanceHigh/(numBlocksHigh-1)+adds two numbers together or concatenates Strings togetherstartLocationY;
055
056 intint is the type for whole numbers and it is short for integer numBlocksAcross=this assignment operator makes the left side equal to the right side10;
057 doubledouble is the type for numbers that can contain decimal fractions startLocationX=this assignment operator makes the left side equal to the right side0.1;
058 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;
059 doubledouble is the type for numbers that can contain decimal fractions distanceAcross=this assignment operator makes the left side equal to the right sideendLocationX-startLocationX;
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 i=this assignment operator makes the left side equal to the right side0; i<numBlocksAcross; i++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 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidei*distanceAcross/(numBlocksAcross-1)+adds two numbers together or concatenates Strings togetherstartLocationX;
063 blocks[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.4, 1.25);
064 blocks[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(.075);
065 blocks[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);
066 blocks[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.BLUE);
067 canvas.addSprite(blocks[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);
068 index++this is the increment operator, which increases the variable by 1;
069 }close braces end code blocks and must match an earlier open brace
070 }close braces end code blocks and must match an earlier open brace
071 }close braces end code blocks and must match an earlier open brace
072
073 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeScore()
074 {open braces start code blocks and must be matched with a close brace
075 displayScore =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 togetherscore);
076 displayScore.setLocation(0.3, .95);
077 displayScore.setColor(Color.WHITE);
078 displayScore.setScale(0.175);
079 canvas.addSprite(displayScore);
080 }close braces end code blocks and must match an earlier open brace
081
082 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeLives()
083 {open braces start code blocks and must be matched with a close brace
084 displayLives =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 togetherlives);
085 displayLives.setLocation(0.7, .95);
086 displayLives.setColor(Color.WHITE);
087 displayLives.setScale(0.175);
088 canvas.addSprite(displayLives);
089 }close braces end code blocks and must match an earlier open brace
090
091 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePaddleandBall()
092 {open braces start code blocks and must be matched with a close brace
093 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(25, 1);
094 paddle.setColor(Color.YELLOW);
095 paddle.setScale(.15);
096 paddle.setLocation(.5, .8);
097 canvas.addSprite(paddle);
098
099 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);
100 ball.setColor(Color.RED);
101 ball.setScale(0.03);
102 ball.setLocation(.5, .7);
103 canvas.addSprite(ball);
104 }close braces end code blocks and must match an earlier open brace
105
106 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeWalls()
107 {open braces start code blocks and must be matched with a close brace
108 leftWall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(3, 50);
109 leftWall.setLocation(0.015, 0.5);
110 leftWall.setScale(1);
111 leftWall.setColor(Color.YELLOW);
112 canvas.addSprite(leftWall);
113
114 rightWall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(3, 50);
115 rightWall.setLocation(.985, 0.5);
116 rightWall.setScale(1);
117 rightWall.setColor(Color.YELLOW);
118 canvas.addSprite(rightWall);
119
120 topWall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(50, 3);
121 topWall.setLocation(0.5, 0);
122 topWall.setScale(1);
123 topWall.setColor(Color.YELLOW);
124 canvas.addSprite(topWall);
125
126 bottomWall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(50, 1);
127 bottomWall.setLocation(0.5, 0.99);
128 bottomWall.setScale(1);
129 bottomWall.setColor(Color.BLACK);
130 canvas.addSprite(bottomWall);
131 }close braces end code blocks and must match an earlier open brace
132
133 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
134 {open braces start code blocks and must be matched with a close brace
135 tracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(.1,-0.5);
136 ball.setTracker(tracker);
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 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 makeBounces();
144 hitsBlocks();
145 }close braces end code blocks and must match an earlier open brace
146
147
148 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeOutcome()
149 {open braces start code blocks and must be matched with a close brace
150 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)
151 {open braces start code blocks and must be matched with a close brace
152 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!");
153 lose.setLocation(0.5, 0.5);
154 lose.setScale(.4);
155 lose.setColor(Color.WHITE);
156 canvas.addSprite(lose);
157 canvas.removeSprite(ball, paddle);
158 }close braces end code blocks and must match an earlier open brace
159
160 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 same50)
161 {open braces start code blocks and must be matched with a close brace
162 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("You Win!");
163 win.setLocation(0.5, 0.5);
164 win.setScale(.4);
165 win.setColor(Color.WHITE);
166 canvas.addSprite(win);
167 canvas.removeSprite(ball, paddle);
168 }close braces end code blocks and must match an earlier open brace
169
170 }close braces end code blocks and must match an earlier open brace
171
172
173 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBounces()
174 {open braces start code blocks and must be matched with a close brace
175 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
176 {open braces start code blocks and must be matched with a close brace
177 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());
178 tracker.bounce(normal);
179 }close braces end code blocks and must match an earlier open brace
180
181 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightWall.intersects(ball))
182 {open braces start code blocks and must be matched with a close brace
183 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());
184 tracker.bounce(normal);
185 }close braces end code blocks and must match an earlier open brace
186
187 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftWall.intersects(ball))
188 {open braces start code blocks and must be matched with a close brace
189 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());
190 tracker.bounce(normal);
191 }close braces end code blocks and must match an earlier open brace
192
193 ifif executes the next statement only if the condition in parenthesis evaluates to true(topWall.intersects(ball))
194 {open braces start code blocks and must be matched with a close brace
195 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());
196 tracker.bounce(normal);
197 }close braces end code blocks and must match an earlier open brace
198
199
200
201 }close braces end code blocks and must match an earlier open brace
202
203 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value hitsBlocks()
204 {open braces start code blocks and must be matched with a close brace
205 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<blocks.length; i++this is the increment operator, which increases the variable by 1)
206 {open braces start code blocks and must be matched with a close brace
207 ifif executes the next statement only if the condition in parenthesis evaluates to true(blocks[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() &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 &&) blocks[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))
208 {open braces start code blocks and must be matched with a close brace
209 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(blocks[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());
210 score++this is the increment operator, which increases the variable by 1;
211 displayScore.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
212 tracker.bounce(normal);
213 blocks[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);
214
215 }close braces end code blocks and must match an earlier open brace
216 }close braces end code blocks and must match an earlier open brace
217
218 ifif executes the next statement only if the condition in parenthesis evaluates to true(bottomWall.intersects(ball))
219 {open braces start code blocks and must be matched with a close brace
220 lives--this is the decrement operator, which decreases the variable by 1;
221 displayLives.setText("Lives: "+adds two numbers together or concatenates Strings togetherlives);
222 ball.setLocation(.5,.5);
223 makeOutcome();
224 }close braces end code blocks and must match an earlier open brace
225 }close braces end code blocks and must match an earlier open brace
226
227 }close braces end code blocks and must match an earlier open brace
|