LuanNguyen/wackadot/Wackadot

From ggc

Jump to: navigation, search

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

Compiler Errors:
----------
1. ERROR in LuanNguyen/wackadot/Wackadot.java (at line 54)
	cat=new ImageSprite(Wiki.getMedia("Picture1.jpg"));
	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in LuanNguyen/wackadot/Wackadot.java (at line 60)
	jerry=new ImageSprite(Wiki.getMedia("Picture2.jpg"));
	      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
3 problems (3 errors)

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