TravVal/Breakout

From ggc

Jump to: navigation, search

We made changes to our Breakout project so it would follow a theme. Our theme is UGA football because we are both fans. Our 5 changes: -

  1. We changed our paddle to a dog to represent the mascot.
  2. We changed our ball to a football.
  3. We put a help text feature to help players play the game.
  4. We made the football quack every time the all intersects the wall and/or brick.
  5. We added a title to our game.
  6. We changed the colors of the bricks, walls and text to follow the red and white UGA theme.
  7. We added an explosion in when the ball intersects with a brick.
  8. We changed the win text to Touchdown! and lose text to Fumble!

001 package TravVal;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * All about my game here.
010  @author Valerie Hagen and Travis Kirby
011  */
012 public class Breakout extends GameLoop
013 {
014   private Sprite[] bricks;
015   private Color[] brickColor;
016   private int numBricksX, numBricksY;
017   private double startYCoord, startXCoord;
018   private double brickWidth, brickHeight;
019   private double yCoord, xCoord;
020   private Sprite leftWall, rightWall, Floor, Ceiling;
021   private Sprite paddle, ball;
022   private Sprite scoreText, livesText, win, lose;
023   private int score, lives;
024   private boolean gameOver = false;
025   private ProjectileTracker ballTracker;
026   private double normal;
027   private int brickAmount;
028   private SpriteFrame frame = new SpriteFrame();
029   private Sound bounce;
030   private ImageSprite explosion;
031   private Sprite title;
032   private Color color=new Color (1396919);
033 
034 
035 
036   public void startGame()
037   {
038     toggleAudible();
039     makeSprites();
040     makeSounds();
041     makeExplosion();
042     makeOutcome();
043 
044     setHelpText("Use the dog to get a score of 50 and recieve a touchdown! If you run out of lives, you fumble! Have fun!!");
045 
046     title=new StringSprite("UGA Breakout");
047     title.setLocation(0.50.9);
048     title.setColor(Color.red);
049     title.setScale(.5);
050     canvas.addSprite(title);
051 
052   }
053   public static void main(String[] args)
054   {
055 
056     Breakout breakout = new Breakout();
057 
058     breakout.runAsApplication();
059   }
060 
061   private void makeSprites()
062   {
063     lives = 3;
064     score = 0;
065     makeScoreLives();
066     levelAssign();
067     makeBrickColors();
068     makeBricks();
069     makeLevelBoundaries();
070     makePadBall();
071     makeBallTracker();
072   }
073 
074   private void makeExplosion()
075   {
076     explosion = new ImageSprite(Wiki.getMedia("explosion.gif"));
077     explosion.setScale(.5);
078   }
079 
080   private void makeSounds()
081   {
082     bounce=new Sound(Wiki.getMedia("Quack.wav"));
083 
084   }
085 
086   public void makeScoreLives()
087   {
088     makescoreText();
089     makelivesText();
090   }
091 
092   public void makescoreText()
093   {
094     canvas.removeSprite(scoreText);
095     scoreText = new StringSprite("Score: " + score);
096     scoreText.setLocation(0.3.1);
097     scoreText.setColor(Color.WHITE);
098     scoreText.setScale(0.2);
099     canvas.addSprite(scoreText);
100     frame.addSprite(scoreText);
101   }
102 
103   public void makelivesText()
104   {
105     canvas.removeSprite(livesText);
106     livesText = new StringSprite("Lives: " + lives);
107     livesText.setLocation(0.6.1);
108     livesText.setColor(Color.WHITE);
109     livesText.setScale(0.2);
110     canvas.addSprite(livesText);
111     frame.addSprite(livesText);
112   }
113 
114 
115   public void makeBrickColors()
116   {
117     brickColor = new Color[numBricksY];
118     for(int colorInt = 0; colorInt < numBricksY; colorInt++)
119     {
120       brickColor[colorInt] = colorOrder(colorInt);
121     }
122   }
123 
124   public Color colorOrder(int colorNum)
125   {
126     Color colorReturn;
127     switch (colorNum)
128     {
129     case 0: colorReturn = Color.red;
130       break;
131     case 1: colorReturn = Color.red;
132       break;
133     case 2: colorReturn=Color.red;
134 
135     default: colorReturn = Color.white;
136     }
137     return(colorReturn);
138   }
139 
140   public void makeBricks()
141   {
142     bricks = new Sprite[numBricksX * numBricksY];
143     for (int = 0; i < numBricksY; i++)
144     {
145       yCoord = startYCoord - (i * brickHeight);
146       for (int = 0; a < numBricksX; a++)
147       {
148         xCoord = startXCoord + a * brickWidth;
149         bricks[(i * numBricksX+ a] = new RectangleSprite(brickWidth, brickHeight);
150         bricks[(i * numBricksX+ a].setColor(brickColor[i]);
151         bricks[(i * numBricksX+ a].setLocation(xCoord, yCoord);
152         bricks[(i * numBricksX+ a].setScale(0.05);
153         canvas.addSprite(bricks[(i * numBricksX+ a]);
154         frame.addSprite(bricks[(i * numBricksX+ a]);
155       }
156     }
157     brickAmount = bricks.length;
158   }
159 
160 
161   public void levelAssign()
162   {
163 
164     numBricksX=8;
165     numBricksY = 4;
166     startYCoord = .4;
167     startXCoord = .1;
168     brickWidth = (* startXCoord(numBricksX - 1);
169     brickHeight = brickWidth / 2.5;
170   }
171 
172   public void makeLevelBoundaries()
173   {
174     makeFloor();
175     makeCeiling();
176     makeLeftWall();
177     makeRightWall();
178   }
179 
180 
181   public void makeCeiling()
182   {
183     Ceiling= new RectangleSprite(10.5);
184     Ceiling.setLocation(.5.17);
185     Ceiling.setColor(Color.red);
186     canvas.addSprite(Ceiling);
187     frame.addSprite(Ceiling);
188   }
189 
190   public void makeLeftWall()
191   {
192     leftWall = new RectangleSprite(110);
193     leftWall.setLocation(startXCoord / 4.5);
194     leftWall.setColor(Color.red);
195     canvas.addSprite(leftWall);
196     frame.addSprite(leftWall);
197   }
198 
199   public void makeRightWall()
200   {
201     rightWall= new RectangleSprite(110);
202     rightWall.setLocation(- startXCoord / 4.5.5);
203     rightWall.setColor(Color.red);
204     canvas.addSprite(rightWall);
205     frame.addSprite(rightWall);
206   }
207 
208   public void makeFloor()
209   {
210     Floor=new RectangleSprite(501);
211     Floor.setLocation(0.50.99);
212     Floor.setScale(1);
213     Floor.setColor(Color.BLACK);
214     canvas.addSprite(Floor);
215   }
216 
217   public void makePadBall()
218   {
219     makePaddle();
220     makeBall();
221   }
222 
223   public void makePaddle()
224   {
225     paddle = new ImageSprite(Wiki.getMedia("Dog.gif"));
226     paddle.setLocation(.5.8);
227     paddle.setScale(.15);
228     canvas.addSprite(paddle);
229     frame.addSprite(paddle);
230   }
231 
232   public void makeBall()
233 
234   {
235     ball = new OvalSprite(42);
236     ball.setLocation(.5.7);
237     ball.setColor(color);
238     ball.setScale(.03);
239     canvas.addSprite(ball);
240     frame.addSprite(ball);
241 
242   }
243   public void randomColorBound()
244   {
245     ball.setColor(new Color(random.nextInt()));
246   }
247 
248   public void makeBallTracker()
249   {
250     ballTracker = new ProjectileTracker(0.1, -.25);
251     ball.setTracker(ballTracker);
252   }
253 
254   public void boundaryBounce()
255   {
256     if (ball.intersects(paddle))
257     {
258       if (ball.getLocation().y < paddle.getLocation().y)
259       {
260         ballBounce(paddle, ball);
261         bounce.play();
262       }
263     }
264     if (ball.intersects(Ceiling))
265     {
266       ballBounce(Ceiling, ball);
267       bounce.play();
268     }
269     if (ball.intersects(leftWall))
270     {
271       ballBounce(leftWall, ball);
272       bounce.play();
273     }
274     if (ball.intersects(rightWall))
275     {
276       ballBounce(rightWall, ball);
277       bounce.play();
278     }
279     if (ball.intersects(explosion))
280     {
281       canvas.removeSprite(explosion);
282     }
283   }
284 
285 
286   public void brickBounce()
287   {
288     for (int brickInt = 0; brickInt < bricks.length; brickInt++)
289     {
290       if (canvas.containsSprite(bricks[brickInt]&& ball.intersects(bricks[brickInt]&& bricks[brickInt] != null)
291       {
292         score++;
293         makeScoreLives();
294         ballBounce(bricks[brickInt], ball);
295         canvas.removeSprite(bricks[brickInt]);
296         brickAmount--;
297         explosion.setLocation(bricks[brickInt].getLocation());
298         explosion.setLooping(false);
299         explosion.startAnimationNow();
300         canvas.addSprite(explosion);
301       }
302 
303       if(Floor.intersects(ball))
304       {
305         lives--;
306 
307         ball.setLocation(.5,.5);
308         makeOutcome();
309       }
310     }
311   }
312 
313   private void makeOutcome()
314   {
315     if(lives==0)
316     {
317       lose=new StringSprite("Fumble!");
318       lose.setLocation(0.50.5);
319       lose.setScale(.4);
320       lose.setColor(Color.WHITE);
321       canvas.addSprite(lose);
322       canvas.removeSprite(ball, paddle);
323     }
324 
325     if(score==32)
326     {
327       win=new StringSprite("Touchdown!");
328       win.setLocation(0.50.5);
329       win.setScale(.4);
330       win.setColor(Color.WHITE);
331       canvas.addSprite(win);
332       canvas.removeSprite(ball, paddle);
333     }
334 
335   }
336 
337 
338   public void ballBounce(Sprite surface, Sprite ball)
339   {
340     normal = Sprite.getNormalVector(surface.getShape(), ball.getShape());
341     ballTracker.bounce(normal);
342   }
343 
344 
345   public void win()
346   {
347     if(brickAmount == 0)
348     {
349       gameOver = true;
350       ball.setVisible(false);
351     }
352   }
353 
354 
355   public void advanceFrame(double timePassed)
356   {
357 
358 
359     frame.setCenter(.5.5);
360     frame.rotate(0.00);
361     if(gameOver == false)
362     {
363       paddle.setLocation(getPlayer().getMouse().getLocation().x, paddle.getLocation().y);
364       boundaryBounce();
365       brickBounce();
366       win();
367     }
368   }
369 }
370 

Compiler Errors:
----------
1. ERROR in TravVal/Breakout.java (at line 76)
	explosion = new ImageSprite(Wiki.getMedia("explosion.gif"));
	            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in TravVal/Breakout.java (at line 225)
	paddle = new ImageSprite(Wiki.getMedia("Dog.gif"));
	         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2 problems (2 errors)

Download/View TravVal/Breakout.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter