Drew Schwarz/Assignment6

From ggc

Jump to: navigation, search

001 package Drew_Schwarz;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * Creates a game that uses interactive art.
009  @author Drew Schwarz
010  */
011 public class Assignment6 extends Game
012 {
013   private Sound sound= new Sound("DingLower.wav");
014   private Sound dohs= new Sound("32dohs.wav");
015   private ImageSprite nose;
016   private ImageSprite eyeone;
017   private ImageSprite eyetwo;
018   private ImageSprite mouth;
019   private OvalSprite spin;
020   private OvalSprite bounce;
021   private OutlineSprite boundarytwo;
022   private ProjectileTransformer projectile;
023   private int circles = 15, i=2;
024   private double area = 360.0/circles;
025   StringSprite titalspin = new StringSprite("Spining Room by Drew Schwarz");
026   StringSprite titalcrazy = new StringSprite("Crazy Face by Drew Schwarz");
027   StringSprite title = new StringSprite("Assignment 6 The art program.To get more info use the help button.");
028 
029 
030   /**sets up the help screen of the game as well as the best part of the game*/
031   public void setup()
032   {
033     removeAllSprites();
034     String helpText=
035         "Hello this page helps you to learn<br>"+
036         "how to run this application<br>"+
037         "First you can press R, C, or O to swich between the Spining Room (R) the Craze Face(C) or the title page(O).<br>"+
038         "While in the Spining Room hold down the M key and click in the game area to set the spining shape.<br>"+
039         "While on the Craze Face click the eyeballs or nose to change thier collor.";
040     setHelpText(helpText);
041     title.setLocation(.5,.3);
042     title.setSize(.9);
043     addSprite(title);
044     bounce();
045 
046   }
047 
048   /**Adds the ding soud to the program*/
049   public void sound()
050   {
051     sound.play(0.1);
052   }
053 
054   /**Adds the Dohs sound to the program*/
055   public void dohs()
056   {
057     dohs.play (0.9);
058   }
059 
060   /** Creates a spining room application where the User determans the placment of further sprites */
061   public void spiningroom()
062   {
063     for (int i=2; i <= circles; i++)
064     {
065       spin= new OvalSprite(.5,1);
066       spin.setLocation(.5,.5);
067       spin.setSize(1.0-(1.0*(i-1)/circles));
068       spin.rotateDegrees(circles + (i-1)*area);
069       if (i%2==0)
070         spin.setColor(Palette.getColor("Yellow"));
071       else
072         spin.setColor(Palette.getColor("Red"));
073       addSprite(spin);
074 
075       Spinner spinner;
076       spinner=new Spinner(0);
077       spinner.setRotationDegrees(45);
078 
079       spin.addTransformer(spinner);
080     }
081   }
082 
083   class DelayedResponse extends TimedAction
084   {
085     public void act()
086     {
087       for (int i=2; i <= circles; i++)
088       {
089         spin.setSize(1.0-(1.0*(i-1)/circles));
090         spin.rotateDegrees(circles + (i-1)*area);
091         if (i%2==0)
092           spin.setColor(Palette.getColor("White"));
093         else
094           spin.setColor(Palette.getColor("Black"));
095         addSprite(spin);
096 
097         Spinner spinner;
098         spinner=new Spinner(0);
099         spinner.setRotationDegrees(45);
100 
101         spin.addTransformer(spinner);
102       }
103     }
104   }
105 
106 
107   /** Makes more sprites in the game when you click the mouse*/
108   public void makeMore()
109   {
110     for (int i=2; i <= circles; i++)
111     {
112       spin= new OvalSprite(.5,1);
113       spin.setLocation(getMouse2D());
114       spin.setSize(1.0-(1.0*(i-1)/circles));
115       spin.rotateDegrees(circles + (i-1)*area);
116       if (i%2==0)
117         spin.setColor(Palette.getColor("Yellow"));
118       else
119         spin.setColor(Palette.getColor("Red"));
120       addSprite(spin);
121 
122       Spinner spinner;
123       spinner=new Spinner(0);
124       spinner.setRotationDegrees(45);
125 
126       spin.addTransformer(spinner);
127 
128       schedule(new DelayedResponse(),.5);
129     }
130   }
131 
132   /**adds the crazyface application to the game*/
133   public void crazyface()
134   {
135     mouth();
136     eyes();
137     nose();
138   }
139 
140   /**creates a mouth image under the nose*/
141   public void mouth()
142   {
143     mouth= new ImageSprite("Mouth.gif");
144     mouth.setLocation(.5.9);
145     mouth.setSize(.4);
146     addSprite(mouth);
147   }
148 
149   /** creates a set of eye immages under in the craze face application*/
150   public void eyes()
151   {
152     eyeone=new ImageSprite("Eyeone.gif");
153     eyeone.setLocation(.2.3);
154     eyeone.setSize(.4);
155     addSprite(eyeone);
156 
157     eyetwo= new ImageSprite("Eyetwo.jpg");
158     eyetwo.setLocation(.8.3);
159     eyetwo.setSize(.5);
160     addSprite(eyetwo);
161 
162     schedule(new Blinker()1);
163   }
164 
165   public void nose()
166   {
167     nose= new ImageSprite("nose.gif");
168     nose.setLocation(.5,.6);
169     nose.setSize(.3);
170     addSprite(nose);
171   }
172 
173   /** creates a bounsing ball in the opening application*/
174   private void bounce()
175   {
176     boundarytwo=new OutlineSprite(new PolygonSprite(5));
177     boundarytwo.setSize(0.5);
178     boundarytwo.setLineThickness(0.2);
179     boundarytwo.setLocation(0.50.8);
180     addSprite(boundarytwo);
181 
182     bounce=new OvalSprite(0.10.1);
183     bounce.setLocation(0.50.8);
184     addSprite(bounce);
185 
186     projectile=new ProjectileTransformer(0.10.25);
187     bounce.setTracker(projectile);
188   }
189 
190   /** can handale the collisions of the eyetwo sprite
191   *when placed alown in the advaced method
192   */
193   private void handleCollisions()
194   {
195     if(bounce.intersects(boundarytwo))
196     {
197       Vector2D vector=projectile.getVector2D();
198       vector.turnDegrees(90);
199       projectile.setVector2D(vector);
200     }
201   }
202 
203   class Blinker extends TimedAction
204   {
205     public void act()
206     {
207       boolean vis=eyeone.isVisible();
208       eyeone.setVisible(!vis);
209       schedule(this1);
210     }
211   }
212 
213 
214   /**handle input and game events*/
215   public void advance()
216   {
217     handleCollisions();
218 
219     if(getKeyPressed()=='r')
220     {
221       removeAllSprites();
222       spiningroom();
223       sound();
224       titalspin.setLocation(.5.9);
225       titalspin.setSize(.5);
226       addSprite(titalspin);
227     }
228     if (getKeyPressed()=='c')
229     {
230       removeAllSprites();
231       crazyface();
232       titalcrazy.setLocation(.5.1);
233       titalcrazy.setSize(.5);
234       addSprite(titalcrazy);
235       dohs();
236     }
237 
238     if (getKeyPressed()=='o')
239     {
240       setup();
241     }
242 
243     if (getKeyPressed()=='m')
244     {
245       if (getClick2D()!=null)
246         makeMore();
247     }
248   }
249 }


Download/View Drew_Schwarz/Assignment6.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