Blake/wackadot/WackADot

From ggc

Jump to: navigation, search

001 package Blake.wackadot;
002 
003 import wiki.Wiki;
004 import fang.*;
005 
006 /**This is a fun, simple game I made using
007  * the FANG Engine.
008  @author Your Name Here
009  */
010 import java.awt.*;
011 import java.awt.geom.*;
012 
013 /**
014  * All about my game here.
015  @author Blake Erskine
016  */
017 public class WackADot extends GameLoop
018 {
019   private Sprite dot;
020   private Sprite redDot;
021   private Sprite blueDot;
022   private StringSprite scoreSprite;
023   private int score;
024   private int timeLeft;
025   private StringSprite timerSprite;
026   Sound sound=new Sound(Wiki.getMedia("Boo.wav"));
027   Sound sound2=new Sound(Wiki.getMedia("Quack.wav"));
028 
029 
030 
031 
032   public void startGame()
033   {
034     score=0;
035     timeLeft=60;
036     makeSprites();
037     addSprites();
038     scheduleRelative(new TimeUpdater()1);
039     setHelp("resources/WackadotHelp.html");
040     toggleAudible();
041   }
042   class TimeUpdater implements Alarm
043   {
044     public void alarm()
045     {
046       timeLeft--;
047       updateTimer();
048       if(timeLeft>0)
049       {
050         scheduleRelative(this1);
051       }
052     }
053   }
054 
055   private void makeSprites()
056   {
057     Ellipse2D.Double circle=
058         new Ellipse2D.Double(0011);
059 
060     dot=new Sprite(circle);
061     dot.setScale(0.1);
062     dot.setLocation(0.50.5);
063     dot.setColor(Color.RED);
064 
065 
066 
067     redDot=new OvalSprite(11);
068     redDot.setScale(0.1);
069     redDot.setLocation(
070         random.nextDouble(),
071         random.nextDouble());
072     redDot.setColor(Color.RED);
073 
074 
075     blueDot=new OvalSprite(11);
076     blueDot.setScale(0.1);
077     blueDot.setLocation(
078         random.nextDouble(),
079         random.nextDouble());
080 
081     scoreSprite=new StringSprite("Score: "+score);
082     scoreSprite=new StringSprite("Score: 0");
083     scoreSprite.setHeight(0.1);
084     scoreSprite.rightJustify();
085     scoreSprite.topJustify();
086     scoreSprite.setLocation(10);
087 
088     timerSprite=new StringSprite("Timer: "+timeLeft);
089     timerSprite.leftJustify();
090     timerSprite.topJustify();
091     timerSprite.setHeight(0.1);
092     timerSprite.setLocation(00);
093   }
094 
095 
096   private void updateScore()
097   {
098     scoreSprite.setText("Score: "+score);
099   }
100 
101   private void addSprites()
102   {
103 
104     canvas.addSprite(dot);
105     canvas.addSprite(redDot);
106     canvas.addSprite(blueDot);
107     canvas.addSprite(scoreSprite);
108     canvas.addSprite(timerSprite);
109   }
110 
111   private void updateTimer()
112   {
113     timerSprite.setText("Timer: "+timeLeft);
114   }
115 
116   private void repositionRandomly(Sprite sprite)
117   {
118     sprite.setLocation(
119         random.nextDouble(),
120         random.nextDouble());
121   }
122 
123   private void handleCollisions()
124   {
125     if(dot.intersects(blueDot))
126     {
127       sound2.play();
128       repositionRandomly(blueDot);
129       if(dot.getColor().equals(Color.BLUE))
130       {
131 
132         dot.setColor(Color.RED);
133         score++;
134       }
135       else
136       {
137         sound.play();
138         score--;
139       }
140       updateScore();
141     }
142     if(dot.intersects(redDot))
143     {
144       sound2.play();
145       repositionRandomly(redDot);
146       if(dot.getColor().equals(Color.RED))
147       {
148         dot.setColor(Color.BLUE);
149         score++;
150       }
151       else
152       {
153         sound.play();
154         score--;
155       }
156       updateScore();
157     }
158 
159 
160   }
161 
162   public void advanceFrame(double timePassed)
163   {
164     if(timeLeft>0)
165     {
166       Point2D.Double mouse=
167           getPlayer().getMouse().getLocation();
168       dot.setLocation(mouse);
169       handleCollisions();
170     }
171 
172   }
173 
174 }
175 


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