GBell/wackadot/Wackadot

From ggc

Jump to: navigation, search

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

Compiler Errors:
----------
1. ERROR in GBell/wackadot/Wackadot.java (at line 56)
	redsmile=new ImageSprite(Wiki.getMedia("Gbellredsmile.gif"));
	         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in GBell/wackadot/Wackadot.java (at line 62)
	bluesmile=new ImageSprite(Wiki.getMedia("Gbellbluesmile.gif"));
	          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2 problems (2 errors)

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