|
001 importimport means to make the classes and/or packages available in this program fang.*;
002 importimport means to make the classes and/or packages available in this program java.awt.*;
003 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
004
005 /**
006 * All about my game here.
007 * @authorthis is the Javadoc tag for documenting who created the source code Kmooney
008 */
009 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 KimBreakOut extendsextends means to customize or extend the functionality of a class GameLoop
010 {open braces start code blocks and must be matched with a close brace
011
012 privateprivate is used to restrict access to the current class only Sprite ball;
013 privateprivate is used to restrict access to the current class only Sprite paddle;
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 square;
015 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
016 privateprivate is used to restrict access to the current class only Sprite leftwall;
017 privateprivate is used to restrict access to the current class only Sprite topwall;
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 bottomwall;
020 privateprivate is used to restrict access to the current class only StringSprite wordscore;
021 privateprivate is used to restrict access to the current class only StringSprite wordlives;
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 score;
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 livesLeft;
024 privateprivate is used to restrict access to the current class only StringSprite livesSprite;
025 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
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 makeSprites();
031 addSprites();
032 makeTracker();
033 score=this assignment operator makes the left side equal to the right side0;
034 livesLeft=this assignment operator makes the left side equal to the right side3;
035 scheduleRelative(newnew is used to create objects by calling the constructor TimeUpdater(), 1);
036 toggleAudible();
037 setHelpText("Hit the bricks by bouncing the ball off the paddle. You have three chances!");
038 }close braces end code blocks and must match an earlier open brace
039 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
040 {open braces start code blocks and must be matched with a close brace
041 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
042 {open braces start code blocks and must be matched with a close brace
043 livesLeft--this is the decrement operator, which decreases the variable by 1;
044 updateTimer();
045 ifif executes the next statement only if the condition in parenthesis evaluates to true(livesLeft>0)
046 {open braces start code blocks and must be matched with a close brace
047 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
048 }close braces end code blocks and must match an earlier open brace
049 }close braces end code blocks and must match an earlier open brace
050 }close braces end code blocks and must match an earlier open brace
051
052 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
053 {open braces start code blocks and must be matched with a close brace
054 leftwall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 40);
055 leftwall.setLocation(0.015, 0.5);
056 leftwall.setScale(1);
057 leftwall.setColor(Color.GREEN);
058
059 topwall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
060 topwall.setLocation(0.5, 0);
061 topwall.setScale(1);
062 topwall.setColor(Color.GREEN);
063
064 rightwall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 40);
065 rightwall.setLocation(.985, 0.5);
066 rightwall.setScale(1);
067 rightwall.setColor(Color.GREEN);
068
069 bottomwall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
070 bottomwall.setLocation(0.5, 1);
071 bottomwall.setScale(1);
072 bottomwall.setColor(Color.GREEN);
073
074 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);
075 ball.setScale(0.05);
076 ball.setLocation(0.5, 0.9);
077 ball.setColor(Color.RED);
078
079 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(4, 1);
080 paddle.setScale(.25);
081 paddle.setLocation(.5, 1);
082 paddle.setColor(Color.BLUE);
083
084
085 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;
086 square=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;
087 intint is the type for whole numbers and it is short for integer numBricksHigh=this assignment operator makes the left side equal to the right side5;
088 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;
089 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side.3;
090 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;
091 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<numBricksHigh; j++this is the increment operator, which increases the variable by 1)
092 {open braces start code blocks and must be matched with a close brace
093 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/(numBricksHigh-1)+adds two numbers together or concatenates Strings togetherstartLocationY;
094
095 intint is the type for whole numbers and it is short for integer numBricksAcross=this assignment operator makes the left side equal to the right side10;
096 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;
097 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;
098 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;
099
100 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<numBricksAcross; i++this is the increment operator, which increases the variable by 1)
101 {open braces start code blocks and must be matched with a close brace
102 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/(numBricksAcross-1)+adds two numbers together or concatenates Strings togetherstartLocationX;
103 square[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=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 1);
104 square[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.setScale(.025);
105 square[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.setLocation(x,y);
106 square[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.setColor(Color.YELLOW);
107
108 canvas.addSprite(square[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);
109
110
111 wordscore=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 wordscore=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Score: 0");
113 wordscore.setLocation(0.90, .05);
114 wordscore.setScale(0.10);
115 wordscore.setColor(Color.WHITE);
116
117 wordlives=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 togetherlivesLeft);
118 wordlives.setLocation(.15, .05);
119 wordlives.setScale(0.10);
120 wordlives.setColor(Color.WHITE);
121
122 }close braces end code blocks and must match an earlier open brace
123 }close braces end code blocks and must match an earlier open brace
124 }close braces end code blocks and must match an earlier open brace
125
126 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateTimer()
127 {open braces start code blocks and must be matched with a close brace
128 livesSprite.setText("Lives: "+adds two numbers together or concatenates Strings togetherlivesLeft);
129 }close braces end code blocks and must match an earlier open brace
130
131 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
132 {open braces start code blocks and must be matched with a close brace
133 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
134 }close braces end code blocks and must match an earlier open brace
135
136
137 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
138 {open braces start code blocks and must be matched with a close brace
139 canvas.addSprite(ball);
140 canvas.addSprite(paddle);
141 canvas.addSprite(leftwall);
142 canvas.addSprite(topwall);
143 canvas.addSprite(rightwall);
144 canvas.addSprite(bottomwall);
145 canvas.addSprite(wordscore);
146 canvas.addSprite(wordlives);
147
148 }close braces end code blocks and must match an earlier open brace
149
150 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
151 {open braces start code blocks and must be matched with a close brace
152 tracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(.75, -.95);
153 ball.setTracker(tracker);
154 }close braces end code blocks and must match an earlier open brace
155
156
157 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
158 {open braces start code blocks and must be matched with a close brace
159 Point2D.Double click=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getClickLocation();
160 ifif executes the next statement only if the condition in parenthesis evaluates to true(click!=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)
161 {open braces start code blocks and must be matched with a close brace
162 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<square.length; i++this is the increment operator, which increases the variable by 1)
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(canvas.containsSprite(square[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))
165 {open braces start code blocks and must be matched with a close brace
166 ifif executes the next statement only if the condition in parenthesis evaluates to true(square[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(click))
167 {open braces start code blocks and must be matched with a close brace
168 canvas.removeSprite(square[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);
169 score++this is the increment operator, which increases the variable by 1;
170 }close braces end code blocks and must match an earlier open brace
171 elseelse is what happens when the if condition is false
172 {open braces start code blocks and must be matched with a close brace
173 score--this is the decrement operator, which decreases the variable by 1;
174 }close braces end code blocks and must match an earlier open brace
175 updateScore();
176 }close braces end code blocks and must match an earlier open brace
177 }close braces end code blocks and must match an earlier open brace
178 }close braces end code blocks and must match an earlier open brace
179 }close braces end code blocks and must match an earlier open brace
180
181 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)
182 {open braces start code blocks and must be matched with a close brace
183 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
184 {open braces start code blocks and must be matched with a close brace
185 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());
186 tracker.bounce(normal);
187 }close braces end code blocks and must match an earlier open brace
188
189 ifif executes the next statement only if the condition in parenthesis evaluates to true(leftwall.intersects(ball))
190 {open braces start code blocks and must be matched with a close brace
191 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());
192 tracker.bounce(normal);
193 }close braces end code blocks and must match an earlier open brace
194 ifif executes the next statement only if the condition in parenthesis evaluates to true(topwall.intersects(ball))
195 {open braces start code blocks and must be matched with a close brace
196 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());
197 tracker.bounce(normal);
198 }close braces end code blocks and must match an earlier open brace
199 ifif executes the next statement only if the condition in parenthesis evaluates to true(rightwall.intersects(ball))
200 {open braces start code blocks and must be matched with a close brace
201 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());
202 tracker.bounce(normal);
203 }close braces end code blocks and must match an earlier open brace
204
205 ifif executes the next statement only if the condition in parenthesis evaluates to true(bottomwall.intersects(ball))
206 {open braces start code blocks and must be matched with a close brace
207 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(bottomwall.getShape(), ball.getShape());
208 tracker.bounce(normal);
209 }close braces end code blocks and must match an earlier open brace
210 ifif executes the next statement only if the condition in parenthesis evaluates to true(livesLeft>0)
211 {open braces start code blocks and must be matched with a close brace
212 handleCollisions();
213 toggleAudible();
214 }close braces end code blocks and must match an earlier open brace
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
|