ChrisHull/FinalProject

From ggc

Jump to: navigation, search

Here are my Approved Modifications: http://ggc.javawide.org/index.php/ChrisHull/Mod


001 
002 
003 package ChrisHull;
004 
005 import wiki.Wiki;
006 import fang.*;
007 /**This is my final Project a modification of Wackadot
008  @author Chris Hull
009 *  The sounds are from Metal Gear Solid 2 , and Super Mario Brothers, I didn't make them.
010  */
011 import java.awt.*;
012 import java.awt.geom.*;
013 import Beta.*;
014 
015 
016 
017 
018 
019 
020 public class FinalProject extends GameLoop
021 {
022 
023   /** Moves the monsters face for translation*/
024   private Sprite moving;
025   /** determines type of tracker*/
026   private ProjectileTracker tracker;
027   /** Declares Track Statement*/
028   private Beta.OutlineTracker track;
029   /** Makes image move*/
030   private Sprite move;
031   /** Displays Distraction*/
032   private Sprite distraction;
033   /** Plays good sound*/
034   private Sound sound;
035   /** Plays bad sound*/
036   private Sound soundSecond;
037   /** Displays timer*/
038   private Sprite timerSprites;
039   /** Displays score*/
040   private Sprite scoreSprites;
041 
042 
043 
044   private void repositionRandomly(Sprite sprite)
045   {
046     sprite.setLocation(
047         random.nextDouble(),
048         random.nextDouble());
049   }
050 
051   /**modifys Distraction with a Periodic event*/
052   private void PeriodicEvent()
053   {
054     distraction=new ImageSprite("Distraction.JPG");
055     distraction.setScale(0.1);
056     distraction.setLocation(0.50.4);
057     canvas.addSprite(distraction);
058 
059   }
060 
061 
062 
063   /**calls PeriodicEvent when the alarm goes off*/
064   class PeriodicEvent implements Alarm
065   {
066     /**simply calls PerodicEvent*/
067     public void alarm()
068     {
069       distraction.setVisible(!distraction.isVisible());
070 
071       scheduleRelative(this,.1);
072       repositionRandomly(distraction);
073 
074     }
075   }
076   public void startGame()
077 
078   {
079     makeSounds();
080     toggleAudible();
081     score=0;
082     timeLeft=30;
083     makeSprites();
084     addSprites();
085     scheduleRelative(new TimeUpdater()1);
086     scheduleRelative(new PeriodicEvent()1);
087     /** Changes the text in help file*/
088     setHelpText(
089         "Touch the blue wackadot to gain points and the red to lose points<br><br>"+
090         "press 1 and 2 to hear  different sounds<br><br>"+
091         "Click Start to begin");
092     moveSprite();
093     movingSprite();
094     PeriodicEvent();
095   }
096 
097   /**tells what sound will play*/
098   private void makeSounds()
099   {
100     sound=new Sound(Wiki.getMedia("Codec.wav"));
101     soundSecond=new Sound(Wiki.getMedia("Mario2.wav"));
102   }
103 
104   /** determines how sprite will rotate*/
105   private void moveSprite()
106   {
107     move=new ImageSprite(Wiki.getMedia("Blue.JPG"));
108     move.setScale(0.2);
109     move.setLocation(0.50.4);
110     Point2D.Double direction=new Point2D.Double(00);
111     ProjectileTracker pTracker=new ProjectileTracker(direction);
112     pTracker.setAngularVelocity(1);
113     move.setTracker(pTracker);
114     canvas.addSprite(move);
115 
116   }
117 
118   /** determines how the sprite will move*/
119   private void movingSprite()
120   {
121     moving=new ImageSprite(Wiki.getMedia("Red.JPG"));
122     moving.setScale(0.2);
123     moving.setLocation(0.51);
124     track=new Beta.OutlineTracker (.2.5,.6 ,.5,.7);
125     track.setLooping(true);
126     moving.setTracker(track);
127     moving.setLocation(track.getCurrentPoint());
128     canvas.addSprite(moving);
129 
130   }
131 
132 
133 
134   private void handleCollisions()
135   {
136     if(dot.intersects(move))
137     {
138       repositionRandomly(move);
139       if(dot.getColor().equals(Color.BLUE))
140       {
141         dot.setColor(Color.RED);
142         score++;
143         goodsound.play();
144       }
145       else
146       {
147         score--;
148         badsound.play();
149       }
150       updateScore();
151     }
152     if(dot.intersects(moving))
153     {
154       repositionRandomly(moving);
155       if(dot.getColor().equals(Color.RED))
156       {
157         dot.setColor(Color.BLUE);
158         score++;
159         goodsound.play();
160       }
161       else
162       {
163         score--;
164         badsound.play();
165       }
166       updateScore();
167 
168     }
169   }
170 
171 
172   public void advanceFrame(double timePassed)
173   {
174     if(timeLeft>0)
175     {
176       Point2D.Double mouse=
177           getPlayer().getMouse().getLocation();
178       dot.setLocation(mouse);
179       handleCollisions();
180       if(getPlayer().getKeyboard().getLastKey()=='1')
181       {
182         sound.play(0);
183       }
184       if(getPlayer().getKeyboard().getLastKey()=='2')
185       {
186         soundSecond.play(1);
187       }
188     }
189   }
190   private Sprite dot;
191   private Sound goodsound;
192   private Sound badsound;
193   private StringSprite scoreSprite;
194   private int score;
195   private int timeLeft;
196   private StringSprite timerSprite;
197 
198 
199 
200   class TimeUpdater implements Alarm
201   {
202     public void alarm()
203     {
204       timeLeft--;
205       updateTimer();
206       if(timeLeft>0)
207       {
208         scheduleRelative(this1);
209       }
210     }
211   }
212   private void makeSprites()
213   {
214     goodsound = new Sound(Wiki.getMedia("Clap.wav"));
215     badsound = new Sound(Wiki.getMedia("Boom.wav"));
216 
217     dot=new OvalSprite(11);
218     dot.setScale(0.1);
219     dot.setLocation(0.50.5);
220     dot.setColor(Color.RED);
221 
222     timerSprites=new ImageSprite(Wiki.getMedia("Timer.JPG"));
223     timerSprites.setScale(0.3);
224     timerSprites.setLocation(.150.1);
225 
226     scoreSprites=new ImageSprite(Wiki.getMedia("Score.JPG"));
227     scoreSprites.setScale(0.25);
228     scoreSprites.setLocation(0.650.1);
229 
230     {
231       scoreSprite=new StringSprite(" 0");
232       scoreSprite=new StringSprite(" "+score);
233       scoreSprite.setHeight(0.1);
234       scoreSprite.rightJustify();
235       scoreSprite.topJustify();
236       scoreSprite.setLocation(.9.07);
237       timerSprite=new StringSprite(" "+timeLeft);
238       timerSprite.leftJustify();
239       timerSprite.topJustify();
240       timerSprite.setHeight(0.1);
241       timerSprite.setLocation(.35.07);
242     }
243   }
244   private void updateScore()
245   {
246     scoreSprite.setText(" "+score);
247   }
248 
249   private void addSprites()
250   {
251     canvas.addSprite(dot);
252     canvas.addSprite(scoreSprite);
253     canvas.addSprite(timerSprite);
254     canvas.addSprite(scoreSprites);
255     canvas.addSprite(timerSprites);
256   }
257   private void updateTimer()
258   {
259     timerSprite.setText(""+timeLeft);
260   }
261   ;
262 
263 }

Compiler Errors:
----------
1. ERROR in ChrisHull/FinalProject.java (at line 107)
	move=new ImageSprite(Wiki.getMedia("Blue.JPG"));
	     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in ChrisHull/FinalProject.java (at line 121)
	moving=new ImageSprite(Wiki.getMedia("Red.JPG"));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
4 problems (4 errors)

Download/View ChrisHull/FinalProject.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