Curtis/InteractiveArt

From ggc

Jump to: navigation, search

001 package Curtis;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * Interactive PacMan.
009  @author Curtis
010  */
011 public class InteractiveArt extends Game
012 {
013   private PieSprite pac1;
014   private OvalSprite circ1;
015   private StringSprite name, title;
016   private ImageSprite cherry, cherry2;
017   private ProjectileTransformer projectile;
018   private OutlineSprite boundary;
019   private int numClicks;
020 
021   /**sets up the game*/
022   public void setup()
023   {
024     name();
025     cherry();
026     makePacman();
027     moveUp();
028     moveRight();
029     moveDown();
030     moveLeft();
031     helpScreen();
032     boundary();
033     numClicks=0;
034 
035     Sound theme=new Sound("Pac-man.mp3");
036     theme.play(.9);
037     theme.setVolume(.8);
038     theme.loop();
039 
040     projectile=new ProjectileTransformer(.1.25);
041     cherry.setTracker(projectile);
042 
043   }
044 
045   /**Makes the cherries*/
046   private void cherry()
047   {
048     cherry=new ImageSprite("CherryCS.jpg");
049     cherry.setSize(.1);
050     cherry.setLocation(.65.5);
051     addSprite(cherry);
052 
053 
054     cherry2=new ImageSprite("CherryCS.jpg");
055     cherry2.setSize(.1);
056     cherry2.setLocation(.2.5);
057     cherry2.setVisible(false);
058 
059   }
060 
061   /**Makes the PacMan image*/
062   private void makePacman()
063   {
064     pac1= new PieSprite(1130315);
065     pac1.setSize(.3);
066     pac1.setLocation(.5.5);
067     pac1.setColor(getColor("yellow"));
068     addSprite(pac1);
069 
070     circ1=new OvalSprite(11);
071     circ1.setSize(.295);
072     circ1.setLocation(.5.5);
073     circ1.setColor(getColor("yellow"));
074     addSprite(circ1);
075 
076     schedule(new Blinker().25);
077   }
078 
079   /**Makes the circle blink to simulate mouth movement*/
080   class Blinker extends TimedAction
081   {
082     public void act()
083     {
084       boolean vis=circ1.isVisible();
085       circ1.setVisible(!vis);
086       schedule(this.3);
087     }
088   }
089   /**Name And Title*/
090   private void name()
091   {
092     name=new StringSprite("Curtis St. John");
093     name.setSize(.25);
094     name.setLocation(.85.9);
095     name.setColor(getColor("red"));
096     addSprite(name);
097 
098     title=new StringSprite("Interactive PacMan");
099     title.setSize(.5);
100     title.setLocation(.5.3);
101     title.setColor(getColor("red"));
102     addSprite(title);
103   }
104   /**The Help Screen*/
105   private void helpScreen()
106   {
107     String helpText=
108         "Press a, s, w, d,<br>"+
109         "To Move<br>"+
110         "PacMan.<br>"+
111         "Click on PacMan when his<br>"+
112         "mouth is open for a cherry<br>"+
113         "Click when closed and<br>"+
114         "PacMan DIES!.";
115     setHelpText(helpText);
116   }
117 
118   /**Makes the boundary*/
119   private void boundary()
120   {
121     boundary=new OutlineSprite(new PolygonSprite(4));
122     boundary.setSize(1.2);
123     boundary.setLineThickness(.05);
124     boundary.setLocation(.5.5);
125     addSprite(boundary);
126 
127     Spinner spin;
128     spin=new Spinner(0);
129     spin.setRotationDegrees(25);
130     boundary.addTransformer(spin);
131   }
132 
133   private void collisions()
134   {
135     cherry.bounceOffOf(boundary);
136     cherry.bounceOffOf(circ1);
137   }
138 
139   /**Moves PacMan right*/
140   private void moveRight()
141   {
142     OutlineTransformer right;
143     right=new OutlineTransformer(0.25,
144                                  0.50.5,
145                                  0.80.5,
146                                  0.50.5);
147     right.setLooping(false);
148 
149     circ1.addTransformer(right);
150     circ1.setLocation(right.getCurrentPoint());
151     pac1.addTransformer(right);
152     pac1.setLocation(right.getCurrentPoint());
153     addSprite(circ1);
154     addSprite(pac1);
155   }
156   /**Moves PacMan left*/
157   private void moveLeft()
158   {
159     OutlineTransformer left;
160     left=new OutlineTransformer(0.25,
161                                 0.50.5,
162                                 0.20.5,
163                                 0.50.5);
164     left.setLooping(false);
165 
166     circ1.addTransformer(left);
167     circ1.setLocation(left.getCurrentPoint());
168     pac1.addTransformer(left);
169     pac1.setLocation(left.getCurrentPoint());
170     addSprite(circ1);
171     addSprite(pac1);
172   }
173   /**Moves PacMan up*/
174   private void moveUp()
175   {
176     OutlineTransformer up;
177     up=new OutlineTransformer(0.25,
178                               0.50.5,
179                               0.50.2,
180                               0.50.5);
181     up.setLooping(false);
182 
183     circ1.addTransformer(up);
184     circ1.setLocation(up.getCurrentPoint());
185     pac1.addTransformer(up);
186     pac1.setLocation(up.getCurrentPoint());
187     addSprite(circ1);
188     addSprite(pac1);
189   }
190   /**Moves PacMan down*/
191   private void moveDown()
192   {
193     OutlineTransformer down;
194     down=new OutlineTransformer(0.25,
195                                 0.50.5,
196                                 0.50.8,
197                                 0.50.5);
198     down.setLooping(false);
199 
200     circ1.addTransformer(down);
201     circ1.setLocation(down.getCurrentPoint());
202     pac1.addTransformer(down);
203     pac1.setLocation(down.getCurrentPoint());
204     addSprite(circ1);
205     addSprite(pac1);
206   }
207   /**Makes the title go away*/
208   class TitleLag extends TimedAction
209   {
210     public void act()
211     {
212       title.setVisible(false);
213     }
214   }
215   /**Makes Cherry appear*/
216 
217   private void surprise()
218   {
219     cherry2.setVisible(true);
220     addSprite(cherry2);
221   }
222 
223   private void death()
224   {
225     Spinner die;
226     die=new Spinner(0);
227     die.setRotationDegrees(25);
228     pac1.addTransformer(die);
229 
230     Sound death=new Sound("PacManDies.wav");
231     death.setVolume(.8);
232     death.play(.2);
233   }
234 
235   /**handle input and game events*/
236   public void advance()
237   {
238     collisions();
239 
240     /**Click for cherry or death*/
241 
242     if(getClick2D()!=null);
243     {
244       numClicks++;
245     }
246     if(numClicks==0)
247     {
248       cherry.setVisible(false);
249     }
250 
251     else if(numClicks==1)
252     {
253       if(getClick2D()!=null && circ1.intersects(getClick2D()))
254       {
255         death();
256       }
257 
258       else if(getClick2D()!=null && pac1.intersects(getClick2D()))
259       {
260         surprise();
261       }
262     }
263 
264     /**press a,s,d,w to move*/
265     if(getKeyPressed()=='d')
266     {
267       moveRight();
268     }
269 
270     if(getKeyPressed()=='a')
271     {
272       moveLeft();
273     }
274 
275     if(getKeyPressed()=='w')
276     {
277       moveUp();
278     }
279 
280     if(getKeyPressed()=='s')
281     {
282       moveDown();
283     }
284     /**press aswd to of making the title go away*/
285     if(getKeyPressed()=='a' || getKeyPressed()=='d' || getKeyPressed()=='s' || getKeyPressed()=='w')
286     {
287       schedule(new TitleLag().5);
288     }
289   }
290 }


Download/View Curtis/InteractiveArt.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