matt mitrovich kcie green/Breakout2

From ggc

Jump to: navigation, search

001 package matt_mitrovich_kcie_green;
002 //start auto-imports
003 import java.util.*;
004 //end auto-imports
005 
006 import fang.*;
007 import java.awt.*;
008 import java.awt.geom.*;
009 
010 /**
011  * All about my game.
012  @author My Name Here
013  */
014 public class Breakout2 extends Game
015 {
016   private ArrayList<Sprite> alltargets;
017   private ImageSprite ball;
018   private ProjectileTransformer sonicTransformer;
019   private RectangleSprite paddle, obsticle;
020   private OutlineSprite boundry, boundry2,boundry3;
021   private StringSprite points, lives;
022   private int setLife=3;
023 
024   /**sets up the game*/
025   public void setup()
026   {
027 
028     makeBricks();
029     makeBall();
030     makePaddle();
031     boundry();
032     blinkyThing();
033     pointTracker();
034     lives();
035     helpScreen();
036   }
037   private void helpScreen()
038   {
039 
040     {
041       String helpText=
042           " welcome to the sonic edition of brick breaker<br>"+
043           " move the paddle to destroy the bricks<br>"+
044           " if your ball goes away hit R to respawn the ball<br>"+
045           " if your ball goes away again hit T to respawn the ball<br>"+
046           " if your ball goes away a last time hit Y to respawn the ball<br>";
047       setHelpText(helpText);
048     }
049 
050 
051   }
052   private void makeBricks()
053   {
054     //*had Dr.Jenkins help us with this and referenced space invaders
055     alltargets=new ArrayList<Sprite>();
056     int targetsAcross=10;
057     int targetsDown=4;
058     for(int n=0; n<targetsDown; n++)
059     {
060       for(int m=1; m<=targetsAcross; m++)
061       {
062         //* Referenced Array code from jam/SpaceInvaders*/
063         ImageSprite targets=new ImageSprite("Goal_ring.jpg");
064         targets.setSize(.7/ targetsAcross);
065         double x=0.5/targetsAcross+1.0/targetsAcross*(m-1);
066         double y=0.5/targetsAcross+(n+0.0)/targetsAcross;
067         targets.setLocation(x, y);
068         addSprite(targets);
069 
070         alltargets.add(targets)
071         ;
072       }
073     }
074   }
075   /** adds three boundry lines that are small skinny and black so it appears that they are not there when the game starts*/
076   private void boundry()
077   {
078     boundry=new OutlineSprite(new LineSprite(0002));
079     boundry.setSize(2);
080     boundry.setLocation(0,0);
081     boundry.setColor(Palette.getColor("black"));
082     addSprite(boundry);
083 
084     boundry2=new OutlineSprite(new LineSprite(0002));
085     boundry2.setSize(2);
086     boundry2.setLocation(1,0);
087     boundry2.setColor(Palette.getColor("Black"));
088     addSprite(boundry2);
089 
090     boundry3=new OutlineSprite(new LineSprite(0020));
091     boundry3.setSize(2);
092     boundry3.setLocation(0,0);
093     boundry3.setColor(Palette.getColor("black"));
094     addSprite(boundry3);
095 
096   }
097   /** adds the ball*/
098   private void makeBall()
099   {
100 
101     ball=new ImageSprite("Ssth.png");
102     ball.setSize(0.09);
103     ball.setLocation(0.50.70);
104     ball.setVisible(true);
105     addSprite(ball);
106     sonicTransformer=new ProjectileTransformer(0.30.3);
107     ball.setTracker(sonicTransformer);
108   }
109   /**adds the paddle and makes it spin for an extra challenge*/
110   private void makePaddle()
111   {
112 
113     paddle=new RectangleSprite(0.8,0.3);
114     paddle.setSize(0.15);
115     paddle.setLocation(0.5,0.9);
116     paddle.setColor(getColor("Green"));
117     addSprite(paddle);
118 
119     Spinner spinner;
120     spinner=new Spinner(0);
121     spinner.setRotationDegrees(100);
122     paddle.addTransformer(spinner);
123   }
124 
125   private void paddleMovement()
126   {
127     paddle.setX(getMouseX());
128   }
129   /**handels what the ball bounces off of*/
130   private void bounceing()
131   {
132     ball.bounceOffOf(paddle);
133     ball.bounceOffOf(boundry);
134     ball.bounceOffOf(boundry2);
135     ball.bounceOffOf(boundry3);
136     ball.bounceOffOf(obsticle);
137     pointsWithCollision();
138 
139 
140   }
141   /** this adds a square in the middle of the screen that spins and acts as an obsticle*/
142   private void blinkyThing()
143   {
144 
145     obsticle=new RectangleSprite(1,1);
146     obsticle.setSize(0.07);
147     obsticle.setLocation(0.50.6);
148     addSprite(obsticle);
149 
150 
151     Spinner spinner;
152     spinner=new Spinner(0);
153     spinner.setRotationDegrees(45);
154     obsticle.addTransformer(spinner);
155   }
156 
157   /**looked at space invaders fook this code tried to make it work on own still cant get it but havent copied it to make it work because
158   its not mine but i did use the basic code for the string from space invaders*/
159   private void lives()
160   {
161 
162     setLives(3);
163     lives = new StringSprite("Lives: "+getLives());
164     lives.setSize(0.20);
165     lives.leftJustify();
166     lives.setLocation(.1.9);
167     lives.setColor(getColor("White"));
168     addSprite(lives);
169   }
170   /**for the points we looked at everyones code because we were having a hard
171   time with it and we ended up using newmans code for the most part with a few
172   variations*/
173   private void pointTracker()
174   {
175 
176     points=new StringSprite("0");
177     points.setSize(0.10);
178     points.setColor(getColor("white"));
179     points.setLocation(0.90.9);
180     addSprite(points);
181   }
182   /**keeps track of when the ball hits the bricks*/
183   private void  pointsWithCollision()
184   {
185     for(Sprite single: alltargets)
186     {
187       if(single.isVisible()==true && single.intersects(ball))
188       {
189         ball.bounceOffOf(single);
190 
191         single.setVisible(false);
192         int startscores = getScore();
193         setScore(startscores+1);
194       }
195     }
196   }
197   private void hit()
198   {
199 
200     for(Sprite single: alltargets)
201     {
202       if(single.isVisible() && ball.intersects(single))
203       {
204 
205 
206         ball.bounceOffOf(single);
207         single.setVisible(false);
208       }
209     }
210   }
211 
212 
213 
214 
215 
216 
217 
218 
219   /**handle input and game events*/
220   public void advance()
221   {
222     pointsWithCollision();
223     bounceing();
224     paddleMovement();
225     hit();
226 
227     /** keeps track of score*/
228     points.setText(""+getScore());
229     if(getKeyPressed()=='r')
230     {
231       setLives(setLife-1);
232       lives.setText("Lives:"+getLives());
233       ball.setLocation(.5.7);
234     }
235     if(getKeyPressed()=='t')
236     {
237       setLives(setLife-2);
238       lives.setText("Lives:"+getLives());
239       ball.setLocation(.5.7);
240     }
241     if(getKeyPressed()=='y')
242     {
243       setLives(setLife-3);
244       lives.setText("Lives:"+getLives());
245       ball.setLocation(.5.7);
246     }
247   }
248 }


Download/View matt_mitrovich_kcie_green/Breakout2.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