William Anderson/bo

From ggc

Jump to: navigation, search

001 package William_Anderson;
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  
011  */
012 public class bo extends GameLoop
013 {
014   private Sprite[] bricks;
015   private Sprite lwall, rwall, floor, twall, paddle, ball;
016   private StringSprite scoreSprite, livesS, over, win;
017   private int score, level, lives;
018   private ProjectileTracker tracker;
019   private Sound blip;
020 
021   public void startGame()
022   {
023     bricks=new Sprite[40];
024     makeSprites();
025     addSprites();
026     makeBricks();
027     makeWalls();
028     makeSounds();
029     level=0;
030     lives=3;
031     score=0;
032     setHelpText("Breakout Clone #88994887439874" +
033                 "                                        Move the paddle left and right with your mouse to hit the ball up to hit the bircks." + "Missing the ball loses a life. When you have zero lives its game over");
034   }
035   private void makeBricks()
036   {
037     int index=0;
038     int numBricksHigh=4;
039     double startLocationY=0.4;
040     double endLocationY=1-startLocationY;
041     double distanceHigh=endLocationY-startLocationY;
042     for(int i=0; i<numBricksHigh; i++)
043     {
044       double y=i*distanceHigh/(numBricksHigh-1)+startLocationY;
045       int numBricksAcross=10;
046       double startLocationX=0.1;
047       double endLocationX=1-startLocationX;
048       double distanceAcross=endLocationX-startLocationX;
049       for(int o=0; o<numBricksAcross; o++)
050       {
051         double x=o*distanceAcross/(numBricksAcross-1)+startLocationX;
052         bricks[index]=new RectangleSprite(21);
053         bricks[index].setScale(.08);
054         bricks[index].setLocation(x, y-.3);
055         bricks[index].setColor(Color.GREEN);
056         canvas.addSprite(bricks[index]);
057         index++;
058       }
059     }
060   }
061   private void makeSprites()
062   {
063     paddle=new OvalSprite(1,.5);
064     paddle.setScale(.2);
065     paddle.setLocation(.1,1);
066     ball=new ImageSprite(Wiki.getMedia("WillBall.gif"));
067     ball.setScale(.05);
068     ball.setLocation(.5,.5);
069     scoreSprite=new StringSprite("Score: "+score);
070     scoreSprite.setScale(.2);
071     scoreSprite.setLocation(.8,.9);
072     livesS=new StringSprite("Lives: 3");
073     livesS.setScale(.2);
074     livesS.setLocation(.2,.9);
075     over=new StringSprite("Game Over :( " );
076     over.setScale(.5);
077     over.setColor(Color.RED);
078     over.setLocation(.5,.5);
079     win=new StringSprite("Congratz! A winnar is you. =)");
080     win.setScale(.8);
081     win.setColor(Color.RED);
082     win.setLocation(.5,.5);
083     tracker=new ProjectileTracker(.25,-.5);
084     ball.setTracker(tracker);
085   }
086   public void addSprites()
087   {
088     canvas.addSprite(paddle, ball, scoreSprite, livesS);
089   }
090   public void makeWalls()
091   {
092     lwall=new RectangleSprite(140);
093     lwall.setLocation(00.5);
094     lwall.setScale(1);
095     lwall.setColor(Color.BLUE);
096     canvas.addSprite(lwall);
097     rwall=new RectangleSprite(140);
098     rwall.setLocation(10.5);
099     rwall.setScale(1);
100     rwall.setColor(Color.BLUE);
101     canvas.addSprite(rwall);
102     twall=new RectangleSprite(401);
103     twall.setLocation(0.50);
104     twall.setScale(1);
105     twall.setColor(Color.BLUE);
106     canvas.addSprite(twall);
107     floor=new RectangleSprite(401);
108     floor.setLocation(0.51);
109     floor.setScale(1);
110     floor.setColor(Color.BLACK);
111     canvas.addSprite(floor);
112   }
113   private void makeSounds()
114   {
115     blip=new Sound(Wiki.getMedia("WAblip.wav"));
116   }
117   private void brickIntersects()
118   {
119     for(int i=0; i<bricks.length; i++)
120     {
121       if(bricks[i].isVisible() && bricks[i].intersects(ball))
122       {
123         score++;
124         if(level==0)
125         {
126           double normal=Sprite.getNormalVector(bricks[i].getShape(), ball.getShape());
127           tracker.bounce(normal);
128           bricks[i].setVisible(false);
129           blip.play();
130         }
131 
132       }
133       updateScore();
134       winorlose();
135     }
136     if(rwall.intersects(ball))
137     {
138       double normal=Sprite.getNormalVector(rwall.getShape(), ball.getShape());
139       tracker.bounce(normal);
140       blip.play();
141     }
142     if(lwall.intersects(ball))
143     {
144       double normal=Sprite.getNormalVector(lwall.getShape(), ball.getShape());
145       tracker.bounce(normal);
146       blip.play();
147     }
148     if(paddle.intersects(ball))
149     {
150       double normal=Sprite.getNormalVector(paddle.getShape(), ball.getShape());
151       tracker.bounce(normal);
152       blip.play();
153     }
154     if(twall.intersects(ball))
155     {
156       double normal=Sprite.getNormalVector(twall.getShape(), ball.getShape());
157       tracker.bounce(normal);
158       blip.play();
159     }
160 
161     if(floor.intersects(ball))
162     {
163       ball.setLocation(
164           random.nextDouble(),
165           random.nextDouble());
166       lives--;
167       livesS.setText("Lives: "+lives);
168       winorlose();
169     }
170 
171   }
172   private void updateScore()
173   {
174     scoreSprite.setText("Score: "+score);
175   }
176   public void winorlose()
177   {
178     if (lives==0)
179     {
180       canvas.removeSprite(paddle, ball, livesS, scoreSprite);
181       canvas.addSprite(over);
182     }
183 
184     if (score==40)
185     {
186       canvas.removeSprite(paddle, ball, livesS, scoreSprite);
187       canvas.addSprite(win);
188     }
189   }
190   public void advanceFrame(double timePassed)
191   {
192     double x=getPlayer().getMouse().getLocation().x;
193     paddle.setLocation(x,paddle.getLocation().y);
194     brickIntersects();
195     updateScore();
196     winorlose();
197   }
198 
199 }

Compiler Errors:
----------
1. ERROR in William_Anderson/bo.java (at line 66)
	ball=new ImageSprite(Wiki.getMedia("WillBall.gif"));
	     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
1 problem (1 error)

Download/View William_Anderson/bo.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