Abbie/wackadot/Wackadot

From ggc

Jump to: navigation, search

001 package Abbie.wackadot;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**This is a fun simple game I made using
009  * the FANG Engine. 
010  @author Abbie Lyday 
011  */
012 public class Wackadot extends GameLoop
013 {
014   private ImageSprite dot;
015   private ImageSprite redDot;
016   private ImageSprite blueDot;
017   private StringSprite scoreSprite;
018   private int score;
019   private int timeLeft;
020   private StringSprite timerSprite;
021   private Sound sound=new Sound("Grizzlybear.wav");
022   private Sound sound2=new Sound("DingLower.wav");
023 
024   public void startGame()
025   {
026 
027     score=0;
028     timeLeft=10;
029     makeSprites();
030 
031     addSprites();
032     scheduleRelative(new TimeUpdater(),1);
033     setHelpText("Use the pawprint that follows your mouse to knock into the other pictures.  Match the pointer picture to another picture, and bump the match.  Your pointer picture will then change, and you have to find another match to your pointer picture.  Matched bumps will earn you points, while unmatched bumps will subtract points.  Get as much points as possible in 10 seconds.");
034   }
035 
036   class TimeUpdater implements Alarm
037   {
038     public void alarm()
039     {
040       timeLeft--;
041       updateTimer();
042       if(timeLeft>0)
043       {
044         scheduleRelative(this,1);
045       }
046     }
047   }
048   private void makeSprites()
049   {
050     dot=new ImageSprite("GGC.gif");
051     dot.setImage("Bearpaw.png");
052     dot.setScale(0.1);
053     dot.setLocation(0.50.5);
054     dot.setColor(Color.RED);
055 
056     redDot=new ImageSprite("GGC.gif");
057     redDot.setImage("Bearpaw.png");
058     redDot.setScale(0.1);
059     redDot.setLocation(
060         random.nextDouble(),
061         random.nextDouble());
062     redDot.setColor(Color.RED);
063 
064     blueDot=new ImageSprite("Bearpaw.png");
065     blueDot.setImage("GGC.gif");
066     blueDot.setScale(0.2);
067     blueDot.setLocation(
068         random.nextDouble(),
069         random.nextDouble());
070     blueDot.setColor(Color.BLUE);
071 
072     scoreSprite=new StringSprite("Score: "+score);
073     scoreSprite.setHeight(0.1);
074     scoreSprite.rightJustify();
075     scoreSprite.topJustify();
076     scoreSprite.setLocation(10);
077 
078 
079     timerSprite=new StringSprite ("Timer: "+timeLeft);
080     timerSprite.leftJustify();
081     timerSprite.topJustify();
082     timerSprite.setHeight(0.1);
083     timerSprite.setLocation(0,0);
084   }
085 
086   private void addSprites()
087   {
088     canvas.addSprite(dot);
089     canvas.addSprite(redDot);
090     canvas.addSprite(blueDot);
091     canvas.addSprite(scoreSprite);
092     canvas.addSprite(timerSprite);
093   }
094 
095   private void updateTimer()
096   {
097     timerSprite.setText("Timer: "+timeLeft);
098     if(timeLeft<1)
099       sound.play();
100   }
101   private void repositionRandomly(Sprite sprite)
102   {
103     sprite.setLocation(
104         random.nextDouble(),
105         random.nextDouble());
106   }
107   private void updateScore()
108   {
109     scoreSprite.setText("Score: "+score);
110   }
111 
112   private void handleCollisions()
113   {
114     if(dot.intersects(blueDot))
115     {
116       repositionRandomly(blueDot);
117       if(dot.getColor().equals(Color.BLUE))
118       {
119 
120         dot.setColor(Color.RED);
121         dot.setScale(0.1);
122         dot.setImage("Bearpaw.png");
123         score++;
124         sound2.play();
125 
126       }
127       else
128       {
129         score--;
130       }
131       updateScore();
132     }
133     if(dot.intersects(redDot))
134     {
135       repositionRandomly(redDot);
136       if(dot.getColor().equals(Color.RED))
137       {
138 
139         dot.setColor(Color.BLUE);
140         dot.setScale(0.2);
141         dot.setImage("GGC.gif");
142         score++;
143         sound2.play();
144 
145       }
146       else
147       {
148         score--;
149       }
150       updateScore();
151     }
152   }
153   public void advanceFrame(double timePassed)
154   {
155 
156     if(timeLeft>0)
157     {
158       Point2D.Double mouse=
159           getPlayer().getMouse().getLocation();
160       dot.setLocation(mouse);
161       handleCollisions();
162     }
163   }
164 }
165 
166 


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