Jayson/wackadot/Wackadot

From ggc

Jump to: navigation, search

001 //package wackadot;
002 package Jayson.wackadot;
003 
004 import wiki.Wiki;
005 import fang.*;
006 import java.awt.*;
007 import java.awt.geom.*;
008 
009 /**This is a fun, simple game I made using
010  * the FANG Engine.
011  @author Jayson Park
012  */
013 public class Wackadot extends GameLoop
014 {
015   public static void main(String[] args)
016   {
017     Wackadot wack = new Wackadot();
018     wack.runAsApplication();
019   }
020 
021   private Sprite[] dots = new Sprite[7];
022   private Color[] colors = new Color[6];
023   private ImageSprite[] stars = new ImageSprite[10];
024   private StringSprite scoreSprite;
025   private int score;
026   private int timeLeft;
027   private StringSprite timerSprite;
028   Sound plus;
029   Sound minus;
030 
031   //Pregame variable setting.
032   public void startGame()
033   {
034     score = 0;
035     timeLeft = 60;
036     makeSprites();
037     scheduleRelative(new TimeUpdater()1);
038     plus = new Sound(Wiki.getMedia("Arrow.wav"));
039     minus = new Sound(Wiki.getMedia("Boom1.wav"));
040   }
041 
042   //Updates timer every second
043   class TimeUpdater implements Alarm
044   {
045     public void alarm()
046     {
047       timeLeft--;
048       updateTimer();
049       if (timeLeft > 0)
050       {
051         scheduleRelative(this1);
052       }
053     }
054   }
055 
056   //Creation of Sprites, sets the colors, shapes, etc.
057   private void makeSprites()
058   {
059     Ellipse2D.Double circle = new Ellipse2D.Double(0011);
060     makeStars();
061     makeColors();
062     makeMouseDot(circle);
063     double scaleDot = 0;
064     for(int = 1; i < dots.length; i++)
065     {
066       if (% == 0)
067         scaleDot = .15;
068       else
069         scaleDot = .1;
070       otherDots(circle, colors[i - 1], i, scaleDot);
071     }
072     makeScoreTimer();
073   }
074 
075   public void makeStars()
076   {
077     for (int = 0; i < stars.length; i++)
078     {
079       stars[i] = new ImageSprite(Wiki.getMedia("Star1.gif"));
080       stars[i].setLocation(random.nextDouble(), random.nextDouble());
081       stars[i].setScale(.10);
082       canvas.addSprite(stars[i]);
083     }
084   }
085   public void makeScoreTimer()
086   {
087     scoreSprite = new StringSprite("Score: " + score);
088     scoreSprite.setHeight(0.1);
089     scoreSprite.rightJustify();
090     scoreSprite.topJustify();
091     scoreSprite.setLocation(10);
092     canvas.addSprite(scoreSprite);
093     timerSprite = new StringSprite("Timer: " + timeLeft);
094     timerSprite.leftJustify();
095     timerSprite.topJustify();
096     timerSprite.setHeight(0.1);
097     timerSprite.setLocation(00);
098     canvas.addSprite(timerSprite);
099   }
100 
101   public void makeMouseDot(Ellipse2D.Double circle)
102   {
103     dots[0] = new Sprite(circle);
104     dots[0].setScale(0.1);
105     dots[0].setLocation(0.50.5);
106     dots[0].setColor(Color.RED);
107     canvas.addSprite(dots[0]);
108   }
109 
110   public void otherDots(Ellipse2D.Double circle, Color dotColor, int dotNum, double scale)
111   {
112     dots[dotNum] = new OvalSprite(11);
113     dots[dotNum].setScale(scale);
114     dots[dotNum].setLocation(random.nextDouble(), random.nextDouble());
115     dots[dotNum].setColor(dotColor);
116     canvas.addSprite(dots[dotNum]);
117   }
118 
119   public void makeColors()
120   {
121     colors[0] = Color.RED;
122     colors[1] = Color.BLUE;
123     colors[2] = Color.GREEN;
124     colors[3] = Color.PINK;
125     colors[4] = Color.WHITE;
126     colors[5] = Color.YELLOW;
127   }
128 
129   private void updateScore()
130   {
131     scoreSprite.setText("Score: " + score);
132   }
133 
134   private void repositionRandomly(Sprite sprite)
135   {
136     sprite.setLocation(random.nextDouble(), random.nextDouble());
137   }
138 
139   public void advanceFrame(double timePassed)
140   {
141     if (timeLeft > 0)
142     {
143       Point2D.Double mouse = getPlayer().getMouse().getLocation();
144       dots[0].setLocation(mouse);
145       handleCollisions();
146     }
147     if (getPlayer().getKeyboard().getLastKey() == 'r')
148     {
149       score = 0;
150       timeLeft = 60;
151       updateTimer();
152       updateScore();
153     }
154   }
155 
156   //Method to update the timer in the display.
157   private void updateTimer()
158   {
159     timerSprite.setText("Timer: " + timeLeft);
160   }
161 
162   //Method that holds all of the collisions with the mouse and the Sprites on screen.
163   private void handleCollisions()
164   {
165     for (int = 1; i < dots.length; i++)
166     {
167       if (dots[0].intersects(dots[i]))
168       {
169         repositionRandomly(dots[i]);
170         if (dots[0].getColor().equals(dots[i].getColor()))
171         {
172           if (== 6)
173             dots[0].setColor(colors[0]);
174           else
175             dots[0].setColor(colors[i]);
176           score++;
177           plus.play();
178         }
179         else
180         {
181           score--;
182           minus.play();
183         }
184         updateScore();
185       }
186     }
187   }
188 }
189 
190 

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

Download/View Jayson/wackadot/Wackadot.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