Nick/Wackadot

From ggc

Jump to: navigation, search

001 package Nick;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * A simple, fun game I made using the FANG Engine.
010  @author Nmckee
011  */
012 public class Wackadot extends GameLoop
013 {
014   private Sprite dot;
015   private Sprite redDot;
016   private Sprite blueDot;
017   private Sprite gDot;
018   private Sprite orangeDot;
019   private Sprite whiteDot;
020   private StringSprite scoreSprite;
021   private int score;
022   private int timeLeft;
023   private StringSprite timerSprite;
024 
025 
026   public void startGame()
027   {
028     score=0;
029     timeLeft=20;
030     makeSprites();
031     addSprites();
032     scheduleRelative(new TimeUpdater()1);
033     setHelp("resources/WackadotHelp.html");
034   }
035 
036   class TimeUpdater implements Alarm
037         Sound sound=new Sound("trainwhistle.wav")
038               {
039                 public void alarm()
040                 {
041                   timeLeft--;
042                   updateTimer();
043                   if(timeLeft>0)
044                   {
045                     scheduleRelative(this1);
046                   }
047                 }
048               }
049 
050               private void makeSprites()
051               {
052                 Ellipse2D.Double circle=
053                     new Ellipse2D.Double(0011);
054 
055                 dot=new Sprite(circle);
056                 dot.setScale(0.05);
057                 dot.setLocation(0.50.5);
058                 dot.setColor(Color.RED);
059 
060                 redDot=new OvalSprite(11);
061                 redDot.setScale(0.1);
062                 redDot.setLocation(
063                     random.nextDouble(),
064                     random.nextDouble());
065                 redDot.setColor(Color.RED);
066 
067                 blueDot=new OvalSprite(11);
068                 blueDot.setScale(0.2);
069                 blueDot.setLocation(
070                     random.nextDouble(),
071                     random.nextDouble());
072                 blueDot.setColor(Color.BLUE);
073 
074                 gDot=new OvalSprite(11);
075                 gDot.setScale(0.3);
076                 gDot.setLocation(
077                     random.nextDouble(),
078                     random.nextDouble());
079                 gDot.setColor(Color.GREEN);
080 
081                 orangeDot=new OvalSprite(11);
082                 orangeDot.setScale(0.4);
083                 orangeDot.setLocation(
084                     random.nextDouble(),
085                     random.nextDouble());
086                 orangeDot.setColor(Color.ORANGE);
087 
088                 whiteDot=new OvalSprite(11);
089                 whiteDot.setScale(0.3);
090                 whiteDot.setLocation(
091                     random.nextDouble(),
092                     random.nextDouble());
093                 whiteDot.setColor(Color.WHITE);
094 
095                 scoreSprite=new StringSprite("Score: "+score);
096                 scoreSprite.setHeight(0.1);
097                 scoreSprite.rightJustify();
098                 scoreSprite.topJustify();
099                 scoreSprite.setLocation(10);
100 
101                 timerSprite=new StringSprite("Timer: "+timeLeft);
102                 timerSprite.leftJustify();
103                 timerSprite.topJustify();
104                 timerSprite.setHeight(0.1);
105                 timerSprite.setLocation(00);
106               }
107 
108               private void addSprites()
109               {
110                 canvas.addSprite(dot);
111                 canvas.addSprite(redDot);
112                 canvas.addSprite(blueDot);
113                 canvas.addSprite(gDot);
114                 canvas.addSprite(orangeDot);
115                 canvas.addSprite(whiteDot);
116                 canvas.addSprite(scoreSprite);
117                 canvas.addSprite(timerSprite);
118               }
119 
120               private void updateTimer()
121               {
122                 timerSprite.setText("Timer: "+timeLeft);
123               }
124 
125               private void repositionRandomly(Sprite sprite)
126               {
127                 sprite.setLocation(
128                     random.nextDouble(),
129                     random.nextDouble());
130               }
131 
132               private void updateScore()
133               {
134                 scoreSprite.setText("Score: "+score);
135               }
136 
137               private void handleCollisions()
138               {
139                 if(dot.intersects(blueDot))
140                 {
141                   repositionRandomly(blueDot);
142                   if(dot.getColor().equals(Color.BLUE))
143                   {
144                     dot.setColor(Color.ORANGE);
145                     score++;
146                   }
147                   else
148                   {
149                     score--;
150                   }
151                   updateScore();
152                 }
153                 if(dot.intersects(redDot))
154                 {
155                   repositionRandomly(redDot);
156                   if(dot.getColor().equals(Color.RED))
157                   {
158                     dot.setColor(Color.GREEN);
159                     score++;
160                   }
161                   else
162                   {
163                     score--;
164                   }
165                   updateScore();
166                 }
167 
168                 if(dot.intersects(gDot))
169                 {
170                   repositionRandomly(gDot);
171                   if(dot.getColor().equals(Color.GREEN))
172                   {
173                     dot.setColor(Color.BLUE);
174                     score++;
175                   }
176                   else
177                   {
178                     score--;
179                   }
180                   updateScore();
181                 }
182 
183                 if(dot.intersects(orangeDot))
184                 {
185                   repositionRandomly(orangeDot);
186                   if(dot.getColor().equals(Color.ORANGE))
187                   {
188                     dot.setColor(Color.WHITE);
189                     score++;
190                   }
191                   else
192                   {
193                     score--;
194                   }
195                   updateScore();
196                 }
197 
198                 if(dot.intersects(whiteDot))
199                 {
200                   repositionRandomly(whiteDot);
201                   if(dot.getColor().equals(Color.WHITE))
202                   {
203                     dot.setColor(Color.RED);
204                     score++;
205                   }
206                   else
207                   {
208                     score--;
209                   }
210                   updateScore();
211                 }
212               }
213 
214               public void advanceFrame(double timePassed)
215               {
216                 if(timeLeft>0)
217                 {
218                   Point2D.Double mouse=
219                       getPlayer().getMouse().getLocation();
220                   dot.setLocation(mouse);
221                   handleCollisions();
222                 }
223 
224               }
225 
226             }

Compiler Errors:
----------
1. ERROR in Nick/Wackadot.java (at line 30)
	makeSprites();
	^^^^^^^^^^^
The method makeSprites() is undefined for the type Wackadot
----------
2. ERROR in Nick/Wackadot.java (at line 31)
	addSprites();
	^^^^^^^^^^
Syntax error, insert ";" to complete FieldDeclaration
----------
5 problems (5 errors)

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