Jayson/finalassign/WackadotEnhance

From ggc

Jump to: navigation, search

Modifications

001 //package wackadot;
002 package Jayson.finalassign;
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 /**
008  * Wackadot Enhancements Final Assignment
009  @author Jayson Park
010  */
011 public class WackadotEnhance extends GameLoop
012 {
013   /**Sides for the sprites to bounce off of*/
014   private Sprite[] bound = new Sprite[4];
015   /**Array for the dots*/
016   private PolygonSides[] dots = new PolygonSides[7];
017   /**Array for the colors*/
018   private Color[] colors = new Color[6];
019   /**Array for the star gifs in the background*/
020   private ImageSprite[] stars = new ImageSprite[10];
021   /**Array for the trackers for the dots*/
022   private ProjectileTracker[] dotTracker = new ProjectileTracker[6];
023   /**String for the score and timer*/
024   private StringSprite scoreSprite, timerSprite;
025   /**Integers for the actual score and time that is left.*/
026   private int score, timeLeft;
027   /**Double value for the normal value to bounce.*/
028   private double normal;
029   /**Initializations for the sounds*/
030   Sound plus, minus;
031   /**Main method*/
032   public static void main(String[] args)
033   {
034     WackadotEnhance wack = new WackadotEnhance();
035     wack.runAsApplication();
036   }
037   /**Pregame variable setting.*/
038   public void startGame()
039   {
040     score = 0;
041     timeLeft = 60;
042     makeSprites();
043     scheduleRelative(new TimeUpdater()1);
044     plus = new Sound(Wiki.getMedia("Arrow.wav"));
045     minus = new Sound(Wiki.getMedia("Boom1.wav"));
046   }
047   /**Sets it so the ball bounces when it hits the paddle or boundary*/
048   public void dotBounce(Sprite surface, int dotInt)
049   {
050     normal = Sprite.getNormalVector(surface.getShape(), dots[dotInt].getShape());
051     dotTracker[dotInt].bounce(normal);
052   }
053   /**Make the trackers and sets to the dots.*/
054   public void makeTracks()
055   {
056     dotTracker[0] = new ProjectileTracker(.25.25);
057     dotTracker[1] = new ProjectileTracker(-.25.25);
058     dotTracker[2] = new ProjectileTracker(0, -.25);
059     dotTracker[3] = new ProjectileTracker(-.25, -.25);
060     dotTracker[4] = new ProjectileTracker(.250);
061     dotTracker[5] = new ProjectileTracker(0.25);
062     for(int = 0; i < dotTracker.length; i++)
063     {
064       dots[i+1].setTracker(dotTracker[i]);
065     }
066   }
067   /**Updates timer every second*/
068   class TimeUpdater implements Alarm
069   {
070     public void alarm()
071     {
072       timeLeft--;
073       updateTimer();
074       if (timeLeft > 0)
075       {
076         scheduleRelative(this1);
077       }
078     }
079   }
080   /**Creation of Sprites, sets the colors, shapes, etc.*/
081   private void makeSprites()
082   {
083     makeStars();
084     makeBound();
085     makeColors();
086     makeMouseDot();
087     double scaleDot = 0;
088     for (int = 1; i < dots.length; i++)
089     {
090       scaleDot = scaleNormalDot(i);
091       otherDots(colors[i - 1], i, scaleDot);
092     }
093     makeTracks();
094     makeScoreTimer();
095   }
096   /**Creates the boundaries around the level.*/
097   public void makeBound()
098   {
099     bound[0] = new RectangleSprite(.1,2);
100     bound[1] = new RectangleSprite(.1,2);
101     bound[2] = new RectangleSprite(2,.1);
102     bound[3] = new RectangleSprite(2,.1);
103     bound[0].setLocation(1.1,.5);
104     bound[1].setLocation(-.1,.5);
105     bound[2].setLocation(.5,-.1);
106     bound[3].setLocation(.5,1.1);
107     for(int = 0; i < bound.length; i++)
108     {
109       bound[i].setScale(.5);
110       canvas.addSprite(bound[i]);
111     }
112   }
113   /**Returns value for scale depending on array element sent in.*/
114   private double scaleNormalDot(int i)
115   {
116     if (% == 0)
117       return (.15);
118     else
119       return (.1);
120   }
121   /**Makes the stars in the background.*/
122   public void makeStars()
123   {
124     for (int = 0; i < stars.length; i++)
125     {
126       stars[i] = new ImageSprite(Wiki.getMedia("Star1.gif"));
127       stars[i].setLocation(random.nextDouble(), random.nextDouble());
128       stars[i].setScale(.10);
129       canvas.addSprite(stars[i]);
130     }
131   }
132   /**Creates the score and the timer text.*/
133   public void makeScoreTimer()
134   {
135     scoreSprite = new StringSprite("Score: " + score);
136     scoreSprite.setHeight(0.1);
137     scoreSprite.rightJustify();
138     scoreSprite.topJustify();
139     scoreSprite.setLocation(10);
140     canvas.addSprite(scoreSprite);
141     timerSprite = new StringSprite("Timer: " + timeLeft);
142     timerSprite.leftJustify();
143     timerSprite.topJustify();
144     timerSprite.setHeight(0.1);
145     timerSprite.setLocation(00);
146     canvas.addSprite(timerSprite);
147   }
148   /**Creates the dot that the mouse controls.*/
149   public void makeMouseDot()
150   {
151     dots[0] = new PolygonSides(random.nextInt(7)+3);
152     dots[0].setScale(0.1);
153     dots[0].setLocation(0.50.5);
154     dots[0].setColor(colors[random.nextInt(5)]);
155     canvas.addSprite(dots[0]);
156   }
157   /**Creates the other dots that is not the one controlled by the player.*/
158   public void otherDots(Color dotColor, int dotNum,
159                         double scale)
160   {
161     dots[dotNum] = new PolygonSides(random.nextInt(7)+3);
162     dots[dotNum].setScale(scale);
163     dots[dotNum].setLocation(random.nextDouble(), random.nextDouble());
164     dots[dotNum].setColor(dotColor);
165     canvas.addSprite(dots[dotNum]);
166   }
167   /**Sets colors to the color array.*/
168   public void makeColors()
169   {
170     colors[0] = Color.RED;
171     colors[1] = Color.BLUE;
172     colors[2] = Color.GREEN;
173     colors[3] = Color.PINK;
174     colors[4] = Color.WHITE;
175     colors[5] = Color.YELLOW;
176   }
177   /**Updates the score*/
178   private void updateScore()
179   {
180     scoreSprite.setText("Score: " + score);
181   }
182   /**Changes the location of the sprite to a random one.*/
183   private void repositionRandomly(Sprite sprite)
184   {
185     sprite.setLocation(random.nextDouble(), random.nextDouble());
186   }
187   /**Changes the scale of the dots, if goes to 0, repositions, then reverts scale size.*/
188   private void changeScaleDots()
189   {
190     for (int = 1; i < dots.length; i++)
191     {
192       dots[i].setScale(dots[i].getScale() .0025);
193       if (dots[i].getScale() <= 0.005)
194       {
195         repositionRandomly(dots[i]);
196         dots[i].setScale(scaleNormalDot(i));
197       }
198     }
199   }
200   /**Check for a Reset*/
201   public void checkReset()
202   {
203     if (getPlayer().getKeyboard().getLastKey() == 'r')
204     {
205       score = 0;
206       timeLeft = 60;
207       updateTimer();
208       updateScore();
209     }
210   }
211   /**Frame advances 30 FPS*/
212   public void advanceFrame(double timePassed)
213   {
214     if (timeLeft > 0)
215     {
216       Point2D.Double mouse = getPlayer().getMouse().getLocation();
217       dots[0].setLocation(mouse);
218       handleCollisions();
219     }
220     checkReset();
221     changeScaleDots();
222     rotateDots();
223   }
224   /**Rotates the dots every frame.*/
225   public void rotateDots()
226   {
227     for(int = 0; i < dots.length; i++)
228     {
229       dots[i].rotate(.01);
230     }
231   }
232   /**Method to update the timer in the display.*/
233   private void updateTimer()
234   {
235     timerSprite.setText("Timer: " + timeLeft);
236   }
237   /**Method to check if the dot correctly intersected the right shape/color*/
238   private void checkIntersect(int i)
239   {
240     if (dots[0].getColor().equals(dots[i].getColor()) && dots[0].getSides()!=dots[i].getSides())
241     {
242       dots[0].setColor(colors[random.nextInt(6)]);
243       score++;
244       plus.play();
245     }
246     else
247       if (!dots[0].getColor().equals(dots[i].getColor()) && dots[0].getSides()==dots[i].getSides())
248       {
249         dots[0].setColor(colors[random.nextInt(6)]);
250         score++;
251         plus.play();
252       }
253       else
254       {
255         score--;
256         minus.play();
257       }
258   }
259   /**Method that holds all of the collisions with the mouse and the Sprites on screen.*/
260   private void handleCollisions()
261   {
262     for (int = 2; i < dots.length; i++)
263     {
264       if(dots[i-1].intersects(dots[i]))
265       {
266         dotBounce(dots[i], i-1);
267       }
268     }
269     for (int = 1; i < dots.length; i++)
270     {
271       for(int = 0; j < bound.length; j++)
272       {
273         if (dots[i].intersects(bound[j]))
274         {
275           dotBounce(bound[j], i-1);
276         }
277       }
278     }
279     for (int = 1; i < dots.length; i++)
280     {
281       if (dots[0].intersects(dots[i]))
282       {
283         repositionRandomly(dots[i]);
284         canvas.removeSprite(dots[0]);
285         makeMouseDot();
286         checkIntersect(i);
287         updateScore();
288       }
289     }
290   }
291 }
292 /**Class that adds the method getSides for the PolygonSprite*/
293 class PolygonSides extends PolygonSprite
294 {
295   int sides = 0;
296   PolygonSides(int sidesGiven)
297   {
298     super(sidesGiven);
299     sides = sidesGiven;
300   }
301   public int getSides()
302   {
303     return(sides);
304   }
305 }

Compiler Errors:
----------
1. ERROR in Jayson/finalassign/WackadotEnhance.java (at line 126)
	stars[i] = new ImageSprite(Wiki.getMedia("Star1.gif"));
	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
1 problem (1 error)

Download/View Jayson/finalassign/WackadotEnhance.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