|
001 packagepackage is used to name the directory or folder a class is in William_Anderson;
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 *
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 bo 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 lwall, rwall, floor, twall, paddle, ball;
016 privateprivate is used to restrict access to the current class only StringSprite scoreSprite, livesS, over, win;
017 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, level, lives;
018 privateprivate is used to restrict access to the current class only ProjectileTracker tracker;
019 privateprivate is used to restrict access to the current class only Sound blip;
020
021 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
022 {open braces start code blocks and must be matched with a close brace
023 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) arrays40]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
024 makeSprites();
025 addSprites();
026 makeBricks();
027 makeWalls();
028 makeSounds();
029 level=this assignment operator makes the left side equal to the right side0;
030 lives=this assignment operator makes the left side equal to the right side3;
031 score=this assignment operator makes the left side equal to the right side0;
032 setHelpText("Breakout Clone #88994887439874" +adds two numbers together or concatenates Strings together
033 " Move the paddle left and right with your mouse to hit the ball up to hit the bircks." +adds two numbers together or concatenates Strings together "Missing the ball loses a life. When you have zero lives its game over");
034 }close braces end code blocks and must match an earlier open brace
035 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBricks()
036 {open braces start code blocks and must be matched with a close brace
037 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;
038 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 side4;
039 doubledouble is the type for numbers that can contain decimal fractions startLocationY=this assignment operator makes the left side equal to the right side0.4;
040 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;
041 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;
042 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<numBricksHigh; i++this is the increment operator, which increases the variable by 1)
043 {open braces start code blocks and must be matched with a close brace
044 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right sidei*distanceHigh/(numBricksHigh-1)+adds two numbers together or concatenates Strings togetherstartLocationY;
045 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;
046 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;
047 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;
048 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;
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 o=this assignment operator makes the left side equal to the right side0; o<numBricksAcross; o++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 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sideo*distanceAcross/(numBricksAcross-1)+adds two numbers together or concatenates Strings togetherstartLocationX;
052 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);
053 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);
054 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-.3);
055 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);
056 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);
057 index++this is the increment operator, which increases the variable by 1;
058 }close braces end code blocks and must match an earlier open brace
059 }close braces end code blocks and must match an earlier open brace
060 }close braces end code blocks and must match an earlier open brace
061 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
062 {open braces start code blocks and must be matched with a close brace
063 paddle=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,.5);
064 paddle.setScale(.2);
065 paddle.setLocation(.1,1);
066 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("WillBall.gif"));
067 ball.setScale(.05);
068 ball.setLocation(.5,.5);
069 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);
070 scoreSprite.setScale(.2);
071 scoreSprite.setLocation(.8,.9);
072 livesS=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Lives: 3");
073 livesS.setScale(.2);
074 livesS.setLocation(.2,.9);
075 over=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Game Over :( " );
076 over.setScale(.5);
077 over.setColor(Color.RED);
078 over.setLocation(.5,.5);
079 win=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Congratz! A winnar is you. =)");
080 win.setScale(.8);
081 win.setColor(Color.RED);
082 win.setLocation(.5,.5);
083 tracker=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(.25,-.5);
084 ball.setTracker(tracker);
085 }close braces end code blocks and must match an earlier open brace
086 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addSprites()
087 {open braces start code blocks and must be matched with a close brace
088 canvas.addSprite(paddle, ball, scoreSprite, livesS);
089 }close braces end code blocks and must match an earlier open brace
090 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value makeWalls()
091 {open braces start code blocks and must be matched with a close brace
092 lwall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 40);
093 lwall.setLocation(0, 0.5);
094 lwall.setScale(1);
095 lwall.setColor(Color.BLUE);
096 canvas.addSprite(lwall);
097 rwall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(1, 40);
098 rwall.setLocation(1, 0.5);
099 rwall.setScale(1);
100 rwall.setColor(Color.BLUE);
101 canvas.addSprite(rwall);
102 twall=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
103 twall.setLocation(0.5, 0);
104 twall.setScale(1);
105 twall.setColor(Color.BLUE);
106 canvas.addSprite(twall);
107 floor=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RectangleSprite(40, 1);
108 floor.setLocation(0.5, 1);
109 floor.setScale(1);
110 floor.setColor(Color.BLACK);
111 canvas.addSprite(floor);
112 }close braces end code blocks and must match an earlier open brace
113 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSounds()
114 {open braces start code blocks and must be matched with a close brace
115 blip=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound(Wiki.getMedia("WAblip.wav"));
116 }close braces end code blocks and must match an earlier open brace
117 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value brickIntersects()
118 {open braces start code blocks and must be matched with a close brace
119 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)
120 {open braces start code blocks and must be matched with a close brace
121 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.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) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays.intersects(ball))
122 {open braces start code blocks and must be matched with a close brace
123 score++this is the increment operator, which increases the variable by 1;
124 ifif executes the next statement only if the condition in parenthesis evaluates to true(level==this is the comparison operator which evaluates to true if both sides are the same0)
125 {open braces start code blocks and must be matched with a close brace
126 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());
127 tracker.bounce(normal);
128 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);
129 blip.play();
130 }close braces end code blocks and must match an earlier open brace
131
132 }close braces end code blocks and must match an earlier open brace
133 updateScore();
134 winorlose();
135 }close braces end code blocks and must match an earlier open brace
136 ifif executes the next statement only if the condition in parenthesis evaluates to true(rwall.intersects(ball))
137 {open braces start code blocks and must be matched with a close brace
138 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(rwall.getShape(), ball.getShape());
139 tracker.bounce(normal);
140 blip.play();
141 }close braces end code blocks and must match an earlier open brace
142 ifif executes the next statement only if the condition in parenthesis evaluates to true(lwall.intersects(ball))
143 {open braces start code blocks and must be matched with a close brace
144 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(lwall.getShape(), ball.getShape());
145 tracker.bounce(normal);
146 blip.play();
147 }close braces end code blocks and must match an earlier open brace
148 ifif executes the next statement only if the condition in parenthesis evaluates to true(paddle.intersects(ball))
149 {open braces start code blocks and must be matched with a close brace
150 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());
151 tracker.bounce(normal);
152 blip.play();
153 }close braces end code blocks and must match an earlier open brace
154 ifif executes the next statement only if the condition in parenthesis evaluates to true(twall.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(twall.getShape(), ball.getShape());
157 tracker.bounce(normal);
158 blip.play();
159 }close braces end code blocks and must match an earlier open brace
160
161 ifif executes the next statement only if the condition in parenthesis evaluates to true(floor.intersects(ball))
162 {open braces start code blocks and must be matched with a close brace
163 ball.setLocation(
164 random.nextDouble(),
165 random.nextDouble());
166 lives--this is the decrement operator, which decreases the variable by 1;
167 livesS.setText("Lives: "+adds two numbers together or concatenates Strings togetherlives);
168 winorlose();
169 }close braces end code blocks and must match an earlier open brace
170
171 }close braces end code blocks and must match an earlier open brace
172 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value updateScore()
173 {open braces start code blocks and must be matched with a close brace
174 scoreSprite.setText("Score: "+adds two numbers together or concatenates Strings togetherscore);
175 }close braces end code blocks and must match an earlier open brace
176 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value winorlose()
177 {open braces start code blocks and must be matched with a close brace
178 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)
179 {open braces start code blocks and must be matched with a close brace
180 canvas.removeSprite(paddle, ball, livesS, scoreSprite);
181 canvas.addSprite(over);
182 }close braces end code blocks and must match an earlier open brace
183
184 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 same40)
185 {open braces start code blocks and must be matched with a close brace
186 canvas.removeSprite(paddle, ball, livesS, scoreSprite);
187 canvas.addSprite(win);
188 }close braces end code blocks and must match an earlier open brace
189 }close braces end code blocks and must match an earlier open brace
190 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)
191 {open braces start code blocks and must be matched with a close brace
192 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;
193 paddle.setLocation(x,paddle.getLocation().y);
194 brickIntersects();
195 updateScore();
196 winorlose();
197 }close braces end code blocks and must match an earlier open brace
198
199 }close braces end code blocks and must match an earlier open brace
|