|
001 packagepackage is used to name the directory or folder a class is in Rohrer;
002 //start auto-imports
003 //end auto-imports
004
005 importimport means to make the classes and/or packages available in this program java.util.*;
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 * My Brick Breaker Game.
012 * @authorthis is the Javadoc tag for documenting who created the source code Kevin Rohrer
013 *
014 * I planned to impliment gravity but I could not find it in the API
015 */
016 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 Brick_Breaker_Assignment_7 extendsextends means to customize or extend the functionality of a class Game
017 {open braces start code blocks and must be matched with a close brace
018 /** bricks*/
019 privateprivate is used to restrict access to the current class only ArrayList<Sprite> bricks;
020 /** walls*/
021 privateprivate is used to restrict access to the current class only Sprite w_Wall, n_Wall, e_Wall;
022 /** ball and paddle*/
023 privateprivate is used to restrict access to the current class only Sprite ball, paddle;
024 /** lives and score display*/
025 privateprivate is used to restrict access to the current class only StringSprite livesDisplay, scoreDisplay;
026 /** actual score lives and click values*/
027 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, lives, clicks;
028 /** ball transformer*/
029 privateprivate is used to restrict access to the current class only ProjectileTransformer ballTransformer;
030 /** special bounce objects*/
031 privateprivate is used to restrict access to the current class only Sprite sBounce1, sBounce2;
032
033 /**sets up the game*/
034 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
035 {open braces start code blocks and must be matched with a close brace
036 boundarys();
037 addBricks();
038 paddleBallSettup();
039 addScoreAndLives();
040 specialBounce();
041 }close braces end code blocks and must match an earlier open brace
042 /**handle input and game events*/
043 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
044 {open braces start code blocks and must be matched with a close brace
045 movePaddleBall();
046 bounceBall();
047 ballBrickCollision();
048 end();
049
050 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=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)
051 clicks++this is the increment operator, which increases the variable by 1;
052 }close braces end code blocks and must match an earlier open brace
053
054 /** adds items at bottom od screen to allow more interesting bounces*/
055 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value specialBounce()
056 {open braces start code blocks and must be matched with a close brace
057 sBounce1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor PolygonSprite(0,0,1,1,0,1);
058 sBounce1.setLocation(.1,.8);
059 sBounce1.setSize(.2);
060 sBounce1.setColor(getColor("Orange Red"));
061 addSprite(sBounce1);
062
063 sBounce2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor PolygonSprite(1,0,1,1,0,1);
064 sBounce2.setLocation(.9,.8);
065 sBounce2.setSize(.2);
066 sBounce2.setColor(getColor("Orange Red"));
067 addSprite(sBounce2);
068 }close braces end code blocks and must match an earlier open brace
069
070
071
072 /** removes ball and paddle then displays game over message*/
073 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value end()
074 {open braces start code blocks and must be matched with a close brace
075 ifif executes the next statement only if the condition in parenthesis evaluates to true(getLives() <=this evaluates to true if the left side is not more than the right side 0)
076 {open braces start code blocks and must be matched with a close brace
077 ball.removeTransformer(ballTransformer);
078 ball.setVisible(falsefalse is a value for the boolean type and means not true);
079 paddle.setVisible(falsefalse is a value for the boolean type and means not true);
080
081 StringSprite end =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Game Over");
082 end.setWidth(.8);
083 end.setLocation(.5,.65);
084 addSprite(end);
085 }close braces end code blocks and must match an earlier open brace
086 }close braces end code blocks and must match an earlier open brace
087 /** allows you to move the paddle along the bottom of the screen
088 and sets the ball in motion when user clicks*/
089 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value movePaddleBall()
090 {open braces start code blocks and must be matched with a close brace
091 paddle.setX(getMouseX());
092
093 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=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 &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 &&) clicks==this is the comparison operator which evaluates to true if both sides are the same0)
094 {open braces start code blocks and must be matched with a close brace
095 ballTransformer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.25, -0.5);
096 ball.addTransformer(ballTransformer);
097 }close braces end code blocks and must match an earlier open brace
098 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=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 &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 &&) clicks>0)
099 {open braces start code blocks and must be matched with a close brace}close braces end code blocks and must match an earlier open brace
100 ifif executes the next statement only if the condition in parenthesis evaluates to true(ball.getLocation().y>1)
101 {open braces start code blocks and must be matched with a close brace
102 clicks =this assignment operator makes the left side equal to the right side 0;
103 ball.removeTransformer(ballTransformer);
104 ball.setLocation(.5,.85);
105 setLives(getLives()-1);
106 livesDisplay.setText("Lives: "+adds two numbers together or concatenates Strings togethergetLives());
107 }close braces end code blocks and must match an earlier open brace
108 }close braces end code blocks and must match an earlier open brace
109 /** adds the score and lives display at top of screen*/
110 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addScoreAndLives()
111 {open braces start code blocks and must be matched with a close brace
112 setLives(3);
113 livesDisplay =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());
114 livesDisplay.setHeight(.08);
115 livesDisplay.leftJustify();
116 livesDisplay.setLocation(.02, .05);
117 livesDisplay.setColor(getColor("White"));
118 addSprite(livesDisplay);
119
120 scoreDisplay =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 togethergetScore());
121 scoreDisplay.setHeight(.08);
122 scoreDisplay.leftJustify();
123 scoreDisplay.setLocation(.5,.05);
124 scoreDisplay.setColor(getColor("White"));
125 addSprite(scoreDisplay);
126 }close braces end code blocks and must match an earlier open brace
127 /** checks forfor is a looping structure for repeatedly executing a block of code collisions between the ball and any of the bricks and changes state acordingly*/
128 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value ballBrickCollision()
129 {open braces start code blocks and must be matched with a close brace
130 forfor is a looping structure for repeatedly executing a block of code(Sprite brick: bricks)
131 {open braces start code blocks and must be matched with a close brace
132 ifif executes the next statement only if the condition in parenthesis evaluates to true(brick.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 &&) brick.intersects(ball))
133 {open braces start code blocks and must be matched with a close brace
134 ball.bounceOffOf(brick);
135 ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(brick.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Green")
136 {open braces start code blocks and must be matched with a close brace
137 brick.setColor(getColor("Yellow"));
138 setScore(getScore()+adds two numbers together or concatenates Strings together1);
139 scoreDisplay.setText("Score: "+adds two numbers together or concatenates Strings togethergetScore());
140 }close braces end code blocks and must match an earlier open brace
141 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(brick.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Yellow")
142 {open braces start code blocks and must be matched with a close brace
143 brick.setColor(getColor("Red"));
144 setScore(getScore()+adds two numbers together or concatenates Strings together2);
145 scoreDisplay.setText("Score: "+adds two numbers together or concatenates Strings togethergetScore());
146 }close braces end code blocks and must match an earlier open brace
147 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(getColorName(brick.getColor())==this is the comparison operator which evaluates to true if both sides are the same"Red")
148 {open braces start code blocks and must be matched with a close brace
149 brick.setVisible(falsefalse is a value for the boolean type and means not true);
150 setScore(getScore()+adds two numbers together or concatenates Strings together3);
151 scoreDisplay.setText("Score: "+adds two numbers together or concatenates Strings togethergetScore());
152 }close braces end code blocks and must match an earlier open brace
153 }close braces end code blocks and must match an earlier open brace
154 }close braces end code blocks and must match an earlier open brace
155 }close braces end code blocks and must match an earlier open brace
156 /** adds the breakable bricks to the screen */
157 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addBricks()
158 {open braces start code blocks and must be matched with a close brace
159 bricks=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Sprite>();
160 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 side15;
161 intint is the type for whole numbers and it is short for integer bricksDown=this assignment operator makes the left side equal to the right side10;
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 j=this assignment operator makes the left side equal to the right side0; j<bricksDown; j++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 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 side1; i<=this evaluates to true if the left side is not more than the right sidebricksAcross; i++this is the increment operator, which increases the variable by 1)
165 {open braces start code blocks and must be matched with a close brace
166 RectangleSprite brick=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(2, 1);
167 brick.setSize(0.9/bricksAcross);
168 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/bricksAcross+adds two numbers together or concatenates Strings together1.0/bricksAcross*(i-1);
169 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side((0.5/bricksAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.0)/bricksAcross)/2)+adds two numbers together or concatenates Strings together.1;
170 brick.setLocation(x, y);
171 brick.setColor(getColor("Green"));
172 addSprite(brick);
173 bricks.add(brick);
174 }close braces end code blocks and must match an earlier open brace
175 }close braces end code blocks and must match an earlier open brace
176 }close braces end code blocks and must match an earlier open brace
177 /** sets the items that the ball will bounce off of */
178 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceBall()
179 {open braces start code blocks and must be matched with a close brace
180 ball.bounceOffOf(w_Wall);
181 ball.bounceOffOf(n_Wall);
182 ball.bounceOffOf(e_Wall);
183 ball.bounceOffOf(paddle);
184 ball.bounceOffOf(sBounce1);
185 ball.bounceOffOf(sBounce2);
186 }close braces end code blocks and must match an earlier open brace
187 /** creates and adds paddle and ball*/
188 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value paddleBallSettup()
189 {open braces start code blocks and must be matched with a close brace
190 paddle =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(6,1);
191 paddle.setSize(.15);
192 paddle.setLocation(.5,.9);
193 paddle.setColor(getColor("Lawn Green"));
194 addSprite(paddle);
195
196 ball =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
197 ball.setSize(.05);
198 ball.setLocation(.5,.85);
199 ball.setColor(getColor("Orange Red"));
200 addSprite(ball);
201 }close braces end code blocks and must match an earlier open brace
202 /** creates and adds the screen boundarys*/
203 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value boundarys()
204 {open braces start code blocks and must be matched with a close brace
205 w_Wall =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LineSprite(0,1,0,0);
206 w_Wall.setSize(1);
207 w_Wall.setLocation(0,.5);
208 w_Wall.setColor(getColor("black"));
209 addSprite(w_Wall);
210
211 n_Wall =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LineSprite(0,.1,1,.1);
212 n_Wall.setSize(1);
213 n_Wall.setLocation(.5,0);
214 n_Wall.setColor(getColor("black"));
215 addSprite(n_Wall);
216
217 e_Wall =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LineSprite(1,0,1,1);
218 e_Wall.setSize(1);
219 e_Wall.setLocation(1,.5);
220 e_Wall.setColor(getColor("black"));
221 addSprite(e_Wall);
222
223 }close braces end code blocks and must match an earlier open brace
224 }close braces end code blocks and must match an earlier open brace
|