|
001 packagepackage is used to name the directory or folder a class is in Merima;
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 * @authornull Merima Omanovic
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, left, right, top, bottom;
016 intint is the type for whole numbers and it is short for integer score, lives;
017 privateprivate is used to restrict access to the current class only StringSprite scorelives;
018 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
019
020
021 /**sets up the game*/
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
023 {open braces start code blocks and must be matched with a close brace
024 score=this assignment operator makes the left side equal to the right side0;
025 lives=this assignment operator makes the left side equal to the right side3;
026 makePaddle();
027 makeBall();
028 makeWalls();
029 makescorelives();
030 makeTracker();
031 makeBricks();
032 setHelpText("1. Move the paddle with the mouse. 2. Try hitting the ball to make it bounce off and hit the bricks. 3. You have 3 lives. GOODLUCK");
033
034 }close braces end code blocks and must match an earlier open brace
035 /**makes the Paddle*/
036 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makePaddle()
037 {open braces start code blocks and must be matched with a close brace
038 paddle =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(19, 1);
039 paddle.setLocation(.5, .9);
040 paddle.setScale(.23);
041 paddle.setColor(Color.WHITE);
042 canvas.addSprite(paddle);
043 }close braces end code blocks and must match an earlier open brace
044 /**score and lives*/
045 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makescorelives()
046 {open braces start code blocks and must be matched with a close brace
047 scorelives=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 together score+adds two numbers together or concatenates Strings together " Lives: "+adds two numbers together or concatenates Strings togetherlives);
048 scorelives.setLocation(.5,.027);
049 scorelives.setColor(Color.WHITE);
050 scorelives.setScale(.39);
051 canvas.addSprite(scorelives);
052 }close braces end code blocks and must match an earlier open brace
053
054 /**makes walls*/
055 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeWalls()
056 {open braces start code blocks and must be matched with a close brace
057 left=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(3, 100);
058 left.setLocation(0.015, 0.5);
059 left.setScale(1);
060 left.setColor(Color.RED);
061 canvas.addSprite(left);
062
063 right=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(3, 100);
064 right.setLocation(.985, 0.5);
065 right.setScale(1);
066 right.setColor(Color.RED);
067 canvas.addSprite(right);
068
069 top=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(100, 3);
070 top.setLocation(0.5, 0);
071 top.setScale(1);
072 top.setColor(Color.RED);
073 canvas.addSprite(top);
074
075 bottom=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(11,1);
076 bottom.setLocation(.5,1);
077 bottom.setColor(Color.BLACK);
078 bottom.setScale(1);
079 canvas.addSprite(bottom);
080
081 }close braces end code blocks and must match an earlier open brace
082 /**makes ball*/
083 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBall()
084 {open braces start code blocks and must be matched with a close brace
085 ball =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(2, 2);
086 ball.setLocation(.5, .9);
087 ball.setScale(.018);
088 ball.setColor(Color.WHITE);
089 canvas.addSprite(ball);
090 }close braces end code blocks and must match an earlier open brace
091 /**make tracker*/
092 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeTracker()
093 {open braces start code blocks and must be matched with a close brace
094 tracker=this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ProjectileTracker(.1,-.5);
095 ball.setTracker(tracker);
096 }close braces end code blocks and must match an earlier open brace
097 /**makes bricks*/
098 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeBricks()
099 {open braces start code blocks and must be matched with a close brace
100 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;
101 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) arrays70]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
102 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;
103 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side.25;
104 doubledouble is the type for numbers that can contain decimal fractions endLocationY=this assignment operator makes the left side equal to the right side1-startLocationY;
105 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;
106 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)
107 {open braces start code blocks and must be matched with a close brace
108 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;
109 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 side14;
110 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;
111 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;
112 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;
113 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)
114 {open braces start code blocks and must be matched with a close brace
115 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;
116 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);
117 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(0.06);
118 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/4);
119 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.PINK);
120 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);
121 index++this is the increment operator, which increases the variable by 1;
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 /** make doubledouble is the type for numbers that can contain decimal fractions timepass*/
127 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)
128 {open braces start code blocks and must be matched with a close brace
129 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;
130 paddle.setLocation(x,paddle.getLocation().y);
131 bounceOffObjects();
132 hitsBricks();
133 }close braces end code blocks and must match an earlier open brace
134 /**make bounce*/
135 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value bounceOffObjects()
136 {open braces start code blocks and must be matched with a close brace
137 bounceOffPaddle();
138 bounceOffLeft();
139 bounceOffRight();
140 bounceOffTop();
141 }close braces end code blocks and must match an earlier open brace
142 /**make the ball bounce off the paddle*/
143 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffPaddle()
144 {open braces start code blocks and must be matched with a close brace
145 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
146 {open braces start code blocks and must be matched with a close brace
147 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());
148 tracker.bounce(normal);
149 }close braces end code blocks and must match an earlier open brace
150 }close braces end code blocks and must match an earlier open brace
151 /**makes the ball bounce off left*/
152 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffLeft()
153 {open braces start code blocks and must be matched with a close brace
154 ifif executes the next statement only if the condition in parenthesis evaluates to true(left.intersects(ball))
155 {open braces start code blocks and must be matched with a close brace
156 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(left.getShape(), ball.getShape());
157 tracker.bounce(normal);
158 }close braces end code blocks and must match an earlier open brace
159 }close braces end code blocks and must match an earlier open brace
160 /**make the ball bounce off right*/
161 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffRight()
162 {open braces start code blocks and must be matched with a close brace
163 ifif executes the next statement only if the condition in parenthesis evaluates to true(right.intersects(ball))
164 {open braces start code blocks and must be matched with a close brace
165 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(right.getShape(), ball.getShape());
166 tracker.bounce(normal);
167 }close braces end code blocks and must match an earlier open brace
168 }close braces end code blocks and must match an earlier open brace
169
170 /**makes the ball bounce off top*/
171 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffTop()
172 {open braces start code blocks and must be matched with a close brace
173 ifif executes the next statement only if the condition in parenthesis evaluates to true(top.intersects(ball))
174 {open braces start code blocks and must be matched with a close brace
175 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(top.getShape(), ball.getShape());
176 tracker.bounce(normal);
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 /**breaks the bricks*/
180 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value hitsBricks()
181 {open braces start code blocks and must be matched with a close brace
182 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 side0; m<bricks.length; m++this is the increment operator, which increases the variable by 1)
183 {open braces start code blocks and must be matched with a close brace
184 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) arraysm]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 &&) bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysm]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(ball))
185 {open braces start code blocks and must be matched with a close brace
186 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) arraysm]brackets are typically used to declare, initialize and index (indicate which element of) arrays.getShape(), ball.getShape());
187 score++this is the increment operator, which increases the variable by 1;
188 scorelives.setText("Score: "+adds two numbers together or concatenates Strings togetherscore+adds two numbers together or concatenates Strings together" Lives: "+adds two numbers together or concatenates Strings togetherlives);
189 tracker.bounce(normal);
190 bricks[brackets are typically used to declare, initialize and index (indicate which element of) arraysm]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);
191 }close braces end code blocks and must match an earlier open brace
192 }close braces end code blocks and must match an earlier open brace
193 }close braces end code blocks and must match an earlier open brace
194 }close braces end code blocks and must match an earlier open brace
195
196
197
|