cray/wackadot/Wackadot

From ggc

Jump to: navigation, search

001 package cray.wackadot;
002 
003 import wiki.Wiki;
004 import fang2.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * All about my game here.
010  @author Cray
011  */
012 
013 
014 public class Wackadot extends GameLoop
015 
016 
017 
018 {
019   //private Sprite dot;
020   private ImageSprite dot;
021   private ImageSprite redDot;
022   private ImageSprite blueDot;
023   private StringSprite scoreSprite;
024   private int score;
025   private int timeLeft;
026   private StringSprite timerSprite;
027   private Sound clip=new Sound("resoures/R2.mp3");
028   private Sound clip2=new Sound("Doh.wav");
029   private Sound clip3=new Sound("Coin.wav");
030   private Sound clip4=new Sound("Airhorn.wav");
031 
032 
033 
034 
035 
036 
037 
038   public void startGame()
039   {
040     score=0;
041     timeLeft=30;
042     makeSprites();
043     addSprites();
044     scheduleRelative(new TimeUpdater()1);
045     setHelpText("The monkey wants to eat the banana, and the banana wants to be eaten by the monkey! When you are the monkey, you must touch the banana, when you are the banana, you must touch the monkey! If the monkey gets the banana or visa versa, then you get a point! However, if You touch the banana with the banana or the monkey with the monkey, you lose a point! You have 30 seconds. ENJOY! Click 'Start' to begin. Click 'Sounds' to toggle sounds on/off.");
046     //clip=new Sound("resources/DingLower.wav");
047 
048 
049   }
050 
051   class TimeUpdater implements Alarm
052 
053   {
054     public void alarm()
055     {
056       timeLeft--;
057       updateTimer();
058       if(timeLeft>0)
059       {
060         scheduleRelative(this1);
061 
062       }
063       else if (timeLeft<1)
064       {
065         clip4.play();
066       }
067     }
068   }
069 
070 
071   private void makeSprites()
072   {
073     //dot=new OvalSprite(1, 1);
074     dot=new ImageSprite("resources/Banana.gif");
075     dot.setScale(0.17);
076     dot.setLocation(0.50.5);
077     dot.setColor(Color.RED);
078 
079     //redDot=new OvalSprite(1, 1);
080     redDot=new ImageSprite("Monkey.gif");
081     redDot.setScale(0.15);
082     redDot.setLocation(
083         random.nextDouble(),
084         random.nextDouble());
085     redDot.setColor(Color.RED);
086 
087     //blueDot=new OvalSprite(1, 1);
088     blueDot=new ImageSprite("Banana.gif");
089     blueDot.setScale(0.15);
090     blueDot.setLocation(
091         random.nextDouble(),
092         random.nextDouble());
093     blueDot.setColor(Color.BLUE);
094 
095     scoreSprite=new StringSprite("Score: "+score);
096     scoreSprite.setHeight(0.1);
097     scoreSprite.rightJustify();
098     scoreSprite.topJustify();
099     scoreSprite.setLocation(10);
100     scoreSprite.setColor(Color.YELLOW);
101 
102     timerSprite=new StringSprite("Timer: "+timeLeft);
103     timerSprite.leftJustify();
104     timerSprite.topJustify();
105     timerSprite.setHeight(0.1);
106     timerSprite.setLocation(00);
107     timerSprite.setColor(Color.YELLOW);
108   }
109 
110   private void addSprites()
111   {
112     canvas.addSprite(dot);
113     canvas.addSprite(redDot);
114     canvas.addSprite(blueDot);
115     canvas.addSprite(scoreSprite);
116     canvas.addSprite(timerSprite);
117 
118 
119   }
120   private void updateTimer()
121   {
122     timerSprite.setText("Timer: "+timeLeft);
123 
124   }
125 
126 
127   private void repositionRandomly(Sprite sprite)
128   {
129     sprite.setLocation(
130         random.nextDouble(),
131         random.nextDouble());
132   }
133 
134   private void updateScore()
135   {
136     scoreSprite.setText("Score: "+score);
137   }
138 
139   private void handleCollisions()
140   {
141     if(dot.intersects(blueDot))
142     {
143       repositionRandomly(blueDot);
144 
145       if(dot.getColor().equals(Color.BLUE))
146       {
147         dot.setColor(Color.RED);
148         dot.setImage("Banana.gif");
149         clip3.play();
150         score++;
151 
152 
153 
154       }
155       else
156       {
157         clip2.play();
158         score--;
159 
160       }
161       updateScore();
162     }
163 
164     if(dot.intersects(redDot))
165     {
166       repositionRandomly(redDot);
167       if(dot.getColor().equals(Color.RED))
168       {
169         dot.setColor(Color.BLUE);
170         dot.setImage("Monkey.gif");
171         clip3.play();
172         score++;
173       }
174       else
175       {
176         clip2.play();
177         score--;
178       }
179       updateScore();
180     }
181 
182   }
183 
184 
185 
186   public void advanceFrame(double timePassed)
187   {
188     if(timeLeft>0)
189     {
190 
191       Point2D.Double mouse=
192           getPlayer().getMouse().getLocation();
193       dot.setLocation(mouse);
194       handleCollisions();
195       //clip.setSoundPosition(getPlayer().getMouse().getLocation().x);
196       clip.setPan(getPlayer().getMouse().getLocation().x);
197     }
198 
199   }
200 
201   public void main(String[] args)
202   {
203     new Wackadot().runAsApplication();
204   }
205 
206 }
207 

Compiler Errors:
----------
1. ERROR in cray/wackadot/Wackadot.java (at line 201)
	public void main(String[] args)
	            ^^^^^^^^^^^^^^^^^^^
This instance method cannot override the static method from GameLoop
----------
1 problem (1 error)

Download/View cray/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