Wilson/InteractiveArt

From ggc

Jump to: navigation, search

001 package Wilson;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * All about my game.
009  @author Wilson Green
010  * Used some of your example code as, well examples.
011  */
012 public class InteractiveArt extends Game
013 {
014   OutlineSprite boundary;
015   OvalSprite ballSprite;
016   ProjectileTransformer projectile;
017   double i=0.01;
018   /**
019   *This class sets up everything
020   *Implements all of the different methods in this program
021   */
022   public void setup()
023   {
024     helpSetup();
025     titleSetup();
026     spiningSun();
027     boundary();
028     ballSprite();
029   }
030   /**
031   * This class makes the help file
032   *
033   */
034   private void helpSetup()
035   {
036     String helpText=
037         "Click on the ball to change it to white after 2.5 seconds"+
038         "or press the y key, for yellow";
039     setHelpText(helpText);
040   }
041   /**
042   *Creates a string for the title and justifys it to the top and left.
043   *
044   */
045   private void titleSetup()
046   {
047     StringSprite title=new StringSprite("Interactive Art! (Wilson Green)");
048     title.leftJustify();
049     title.topJustify();
050     title.setWidth(1);
051     addSprite(title);
052   }
053   /**
054   *Creates an image with "sun.gif" and sets its location, also makes it spin with a transformer
055   *
056   */
057   private void spiningSun()
058   {
059     ImageSprite sun=new ImageSprite("Sun.gif");
060     Spinner spinner=new Spinner(0);
061     sun.setLocation(.5,.2);
062     sun.setSize(.2);
063     addSprite(sun);
064     spinner.setRotationDegrees(45);
065     sun.addTransformer(spinner);
066   }
067   /**
068   *This method creates the boundry for which the ballSprite bounces around in
069   *
070   */
071   public void boundary()
072   {
073     boundary=new OutlineSprite(new PolygonSprite(6));
074     boundary.setSize(0.9);
075     boundary.setLineThickness(i);
076     boundary.setLocation(0.50.5);
077     addSprite(boundary);
078   }
079   /**
080   *Creates the ballSprite that bounces around in the center, uses a transformer to bounce back an forth.
081   *
082   */
083   public void ballSprite()
084   {
085     ballSprite=new OvalSprite(0.10.1);
086     ballSprite.setLocation(0.50.5);
087     addSprite(ballSprite);
088     projectile=new ProjectileTransformer(0.10.25);
089     ballSprite.setTracker(projectile);
090   }
091   /**
092   *Handles the collisions (hence the name) between the bondary and the ballSprite, and makes it veer to a 145 degree angle when hitting a boundary
093   *
094   */
095   private void handleCollisions()
096   {
097     if(ballSprite.intersects(boundary))
098     {
099       Vector2D vector=projectile.getVector2D();
100       vector.turnDegrees(145);
101       projectile.setVector2D(vector);
102     }
103   }
104   /**
105   *When clicking on the screen this delays the response to turn the ball white
106   *
107   */
108   class DelayedResponse extends TimedAction
109   {
110     public void act()
111     {
112       ballSprite.setColor(getColor("white"));
113     }
114   }
115 
116   /**
117   *Handles game inputs, such as clicking anywhere to turn the ball white after 2.5 seconds,
118   *or clicking y to turn the ball yellow.
119   */
120   public void advance()
121   {
122     handleCollisions();
123     if(getClick2D()!=null)
124     {
125       schedule(new DelayedResponse()2.5);
126     }
127     if(getKeyPressed()=='y')
128     {
129       ballSprite.setColor(getColor("YELLOW"));
130     }
131     if(i<.05)
132     {
133       i=i+.01;
134       boundary.setLineThickness(i);
135     }
136     else if(i>=.05)
137     {
138       i=.01;
139       boundary.setLineThickness(i);
140     }
141   }
142 }


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