Charles/InteractiveArt

From ggc

Jump to: navigation, search

001 package Charles;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * All about my game.
009  @author Charles
010  */
011 public class InteractiveArt extends Game
012 {
013   private StringSprite title;
014   private String helptxt;
015   private PolygonSprite poly;
016   private OutlineSprite border;
017   private OvalSprite ball;
018   private ImageSprite pump1, witch, explode;
019   private LineSprite lbar, rbar;
020   private Sound door=new Sound("Door_cre.wav");;
021 
022   /**sets up the game*/
023   public void setup()
024   {
025     makeHelp();
026     makeAndAddBorder();
027     makeBall();
028     makeAndAddLeftBar();
029     makeAndAddRightBar();
030     makeAndAddPumpkins();
031     makeAndAddWitch();
032     makeAndAddExplosion();
033     makeAndAddTitle();
034     blowUpWitch();
035 
036     playSoundImmediately();
037     door.setVolume(0.2);
038 
039   }
040   /**Creates the title of the program and the authers*/
041   private void makeAndAddTitle()
042   {
043     title=new StringSprite("Interactive Art  By: Charles and Chanelle");
044     title.setLocation(0.50.1);
045     title.setSize(0.9);
046     title.setColor(Palette.getColor("Purple"));
047     addSprite(title);
048   }
049   /**Creates the text displayed in the help menu*/
050   private void makeHelp()
051   {
052     helptxt=
053         "*To begin click the Start button.<br>"+
054         "*Click anywhere in the green box to release your ball.<br>"+
055         "*Press the B key on your keyboard to get a suprise!!";
056     setHelpText(helptxt);
057   }
058   /**Creates the border for the game area where the ball will bounce in*/
059   private void makeAndAddBorder()
060   {
061     poly=new PolygonSprite(0.010.150.990.150.990.990.010.99);
062     border=new OutlineSprite(poly);
063     border.setSize(0.99);
064     border.setLineThickness(0.05);
065     border.setLocation(0.50.55);
066     border.setColor(Palette.getColor("Green"));
067     addSprite(border);
068   }
069   /** creates the ball and projectile transformer that bounces within the game area*/
070   private void makeBall()
071   {
072     ball=new OvalSprite(1,1);
073     ball.setSize(.05);
074     ball.setColor(Palette.getColor("Purple"));
075     double x=random.nextInt(2);
076     if(x==0)
077     {
078       x=-0.1;
079     }
080     else
081     {
082       x=0.1;
083     }
084     ProjectileTransformer bounce=new ProjectileTransformer(x, -0.35);
085     ball.setTracker(bounce);
086   }
087 
088   /**creates the bar that occupies the left side of the game area*/
089   private void makeAndAddLeftBar()
090   {
091     lbar=new LineSprite(1111.5);
092     lbar.setSize(0.1);
093     lbar.setLineThickness(0.1);
094     lbar.setColor(Palette.getColor("Fire Brick"));
095     lbar.setLocation(0.15,0.7);
096     OutlineTransformer track1;
097     track1=new OutlineTransformer(0.120.150.70.20.50.30.70.150.7);
098     track1.setLooping(true);
099     lbar.addTransformer(track1);
100     addSprite(lbar);
101   }
102 
103   /**creates the bar that occupies the right side of the game area*/
104   private void makeAndAddRightBar()
105   {
106     rbar=new LineSprite(1111.5);
107     rbar.setSize(0.1);
108     rbar.setLineThickness(0.1);
109     rbar.setColor(Palette.getColor("Fire Brick"));
110     rbar.setLocation(0.85,0.65);
111     OutlineTransformer track2;
112     track2=new OutlineTransformer(0.130.20.50.130.70.20.5);
113     track2.setLooping(true);
114     rbar.addTransformer(track2);
115     addSprite(rbar);
116   }
117 
118   /**creates the pumkin image that spins in the center of the game area*/
119   private void makeAndAddPumpkins()
120   {
121     pump1=new ImageSprite("Pumpkin.JPG");
122     pump1.setLocation(.50.5);
123     pump1.setSize(0.1);
124     addSprite(pump1);
125 
126     Spinner spinRight;
127     spinRight=new Spinner(0);
128     spinRight.setRotationDegrees(45);
129 
130     pump1.addTransformer(spinRight);
131   }
132 
133   /**creates the witch image that moves across the top of the game area*/
134   private void makeAndAddWitch()
135   {
136     witch=new ImageSprite("Witch.jpg");
137     OutlineTransformer flight;
138     flight=new OutlineTransformer(0.2,0.10.1,0.80.10.10.1);
139     flight.setLooping(true);
140     witch.addTransformer(flight);
141     witch.setLocation(0.150.24);
142     witch.setSize(.15);
143     addSprite(witch);
144   }
145 
146   /**creates the explosion image that appears when the "b" key is pressed*/
147   private void makeAndAddExplosion()
148   {
149     explode=new ImageSprite("Explode.png");
150     explode.setLocation(.50.5);
151     explode.setSize(0.3);
152     addSprite(explode);
153     explode.setVisible(false);
154   }
155   /**makes the ball bounce off of the selected objects*/
156   private void handleBounce()
157   {
158     ball.bounceOffOf(border);
159     ball.bounceOffOf(lbar);
160     ball.bounceOffOf(rbar);
161     ball.bounceOffOf(witch);
162     ball.bounceOffOf(pump1);
163 
164   }
165   /** makes the delayed release of the ball*/
166   class DelayedResponse extends TimedAction
167   {
168     public void act()
169     {
170       addSprite(ball);
171     }
172   }
173 
174   /** replaces the pumpkin image with the explosion image*/
175   private void blowUpWitch()
176   {
177     if(getKeyPressed()=='b')
178     {
179       pump1.setVisible(false);
180       explode.setVisible(true);
181     }
182   }
183 
184   /**creates the door creaking sound when game starts*/
185   private void makeDoorCreek()
186   {
187 
188     playSoundImmediately();
189     door.setVolume(0.2);
190   }
191   /**handle input and game events*/
192   public void advance()
193   {
194     handleBounce();
195     blowUpWitch();
196     /** sets up the delay for the ball release*/
197     if(getClick2D()!=null)
198     {
199       ball.setLocation(getClick2D());
200       schedule(new DelayedResponse()1.5);
201     }
202   }
203 }


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