JacobOlson/wackadot/Wackadot

From ggc

Jump to: navigation, search

001 package JacobOlson.wackadot;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  this game is very basic but yet it is a great time spender
010  this is a duplication of an original
011  * I used the Fang Engine
012  @author Jacob Olson
013  */
014 public class Wackadot extends GameLoop
015 {
016   private Sprite dot;
017   private Sprite redDot;
018   private Sprite blueDot;
019   private StringSprite scoreSprite;
020   private int score;
021   private int timeLeft;
022   private StringSprite timerSprite;
023   private Sound sound=new Sound(Wiki.getMedia("Boom1.wav"));
024   private Sound sound1=new Sound(Wiki.getMedia("Ding.wav"));
025   private ImageSprite sprite;
026   /**
027    this is what appears at the beginning of the game before you start
028    */
029   public void startGame()
030   {
031     score=0;
032     timeLeft=30;
033     makeSprites();
034     addSprites();
035     scheduleRelative(new TimeUpdater()1);
036     setHelp("resources/WackadotHelp.html");
037     toggleAudible();
038 
039   }
040   /**
041    this is wear i set up the count down for the timer during the game
042    */
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   private void makeSprites()
057   {
058     Ellipse2D.Double circle=new Ellipse2D.Double(0,0,1,1);
059     dot=new Sprite(circle);
060     dot.setScale(0.1);
061     dot.setLocation(0.5,0.5);
062     dot.setColor(Color.RED);
063 
064     redDot=new OvalSprite(1,1);
065     redDot.setScale(0.1)
066     ;
067     redDot.setLocation(
068         random.nextDouble(),
069         random.nextDouble());
070     redDot.setColor(Color.RED);
071 
072     blueDot=new OvalSprite(1,1);
073     blueDot.setScale(0.1);
074     blueDot.setLocation(
075         random.nextDouble(),
076         random.nextDouble());
077     blueDot.setColor(Color.BLUE);
078 
079     scoreSprite=new StringSprite("Score: "+score);
080     scoreSprite=new StringSprite("Score: 0");
081     scoreSprite.setHeight(0.1);
082     scoreSprite.rightJustify();
083     scoreSprite.topJustify();
084     scoreSprite.setLocation(10);
085     timerSprite=new StringSprite("Timer: "+timeLeft);
086     timerSprite.leftJustify();
087     timerSprite.topJustify();
088     timerSprite.setHeight(0.1);
089     timerSprite.setLocation(00);
090 
091     /**
092      *I got this picture from "http://www.flickr.com/photos/8003170@N06/481435956/"
093      */
094     sprite=new ImageSprite(Wiki.getMedia("Mountains.jpg"));
095     sprite.setScale(.8);
096     sprite.setLocation(.5,.5);
097 
098   }
099 
100   private void updateTimer()
101   {
102     timerSprite.setText("Timer: "+timeLeft);
103   }
104 
105   private void addSprites()
106   {
107     canvas.addSprite(sprite);
108     canvas.addSprite(dot);
109     canvas.addSprite(redDot);
110     canvas.addSprite(blueDot);
111     canvas.addSprite(scoreSprite);
112     canvas.addSprite(timerSprite);
113 
114   }
115 
116   private void repositionRandomly(Sprite sprite)
117   {
118     sprite.setLocation(
119         random.nextDouble(),
120         random.nextDouble());
121   }
122 
123   private void updateScore()
124   {
125     scoreSprite.setText("Score: "+score);
126   }
127 
128   private void handleCollisions()
129   {
130     if(dot.intersects(redDot))
131     {
132       repositionRandomly(redDot);
133       if(dot.getColor().equals(Color.RED))
134       {
135         dot.setColor(Color.BLUE);
136         score++;
137         sound1.play();
138       }
139 
140       else
141       {
142         score--;
143         sound.play();
144       }
145       updateScore();
146 
147     }
148 
149     if(dot.intersects(blueDot))
150     {
151       repositionRandomly(blueDot);
152       if(dot.getColor().equals(Color.BLUE))
153       {
154         dot.setColor(Color.RED);
155         score++;
156         sound1.play();
157       }
158 
159       else
160       {
161         score--;
162         sound.play();
163       }
164       updateScore();
165     }
166   }
167 
168   public void advanceFrame(double timePassed)
169   {
170     if(timeLeft>0)
171     {
172       Point2D.Double mouse=
173           getPlayer(0).getMouse().getLocation();
174       dot.setLocation(mouse);
175       handleCollisions();
176     }
177   }
178 }

Compiler Errors:
----------
1. ERROR in JacobOlson/wackadot/Wackadot.java (at line 94)
	sprite=new ImageSprite(Wiki.getMedia("Mountains.jpg"));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
1 problem (1 error)

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