Rohrer/Interactive Art Assignment 6

From ggc

Jump to: navigation, search

001 package Rohrer;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * A random stupid Game that I created.
009  @author Kevin Rohrer
010  */
011 public class Interactive_Art_Assignment_6 extends Game
012 {
013   ImageSprite nuke = new ImageSprite("Rohrer-Nuke.jpg");
014   ImageSprite fire = new ImageSprite("Rohrer-Fire.jpg");
015   public Sound bang = new Sound("Rohrer-Missile.wav");
016   public Sound burn = new Sound("Rohrer-Fireball.wav");
017   public ProjectileTransformer bouncer;
018   public OutlineSprite screenOutline;
019   public Sprite bouncingBall;
020   public Sprite spin1, spin2;
021   public Sprite artist, title;
022 
023 
024   /**adds primary objects to the game*/
025   public void setup()
026   {
027     addScreenOutline();
028     titleAndArtist();
029     addFireNukeIcon();
030     bounceBall();
031     spiningBricks();
032     helpScreen();
033   }
034   /**handle input and game events*/
035   public void advance()
036   {
037     bounce();
038     soundWhenClick();
039     colorChange();
040   }
041 
042 
043   /** creates and adds the Fire and Nuke icon to screen */
044   public void addFireNukeIcon()
045   {
046     fire.setSize(.2);
047     fire.setLocation(.9,.1);
048     addSprite(fire);
049 
050     nuke.setSize(.2);
051     nuke.setLocation(.1,.1);
052     addSprite(nuke);
053   }
054   /** plays a sound when user clicks on ether the Nuke or the Fire icon */
055   public void soundWhenClick()
056   {
057     if (getClick2D()!=null  && nuke.intersects(getClick2D()))
058     {
059       bang.setVolume(.5);
060       bang.play(.25);
061     }
062     if (getClick2D()!=null  && fire.intersects(getClick2D()))
063     {
064       burn.setVolume(.5);
065       burn.play(.75);
066     }
067   }
068 
069   /** makes, adds, and sets spin velocity to the two spinning objects*/
070   public void spiningBricks()
071   {
072     spin1 = new PolygonSprite(3);
073     spin1.setLocation(.3,.7);
074     spin1.setSize(.2);
075     spin1.setColor(getColor("Lawn Green"));
076     addSprite(spin1);
077 
078     spin2 = new PolygonSprite(3);
079     spin2.setLocation(.7,.7);
080     spin2.setSize(.2);
081     spin2.setColor(getColor("Lawn Green"));
082     addSprite(spin2);
083 
084     Spinner spinner;
085     spinner=new Spinner(0);
086     spinner.setRotationDegrees(180);
087 
088     spin1.addTransformer(spinner);
089     spin2.addTransformer(spinner);
090   }
091   /** exicutes the proper delayed color change of the spinning objects apon keypress*/
092   public void colorChange()
093   {
094     if(getKeyPressed()=='c')
095     {
096       schedule(new DelayedResponse1()2.5);
097     }
098     if(getKeyPressed()=='r')
099     {
100       schedule(new DelayedResponse2()2.5);
101     }
102   }
103   /** changes color of spinning objects after a preset time*/
104   class DelayedResponse1 extends TimedAction
105   {
106     public void act()
107     {
108       spin1.setColor(getColor("red"));
109       spin2.setColor(getColor("red"));
110     }
111   }
112   /**changes color of spinning objects after a preset time*/
113   class DelayedResponse2 extends TimedAction
114   {
115     public void act()
116     {
117       spin1.setColor(getColor("Lawn Green"));
118       spin2.setColor(getColor("Lawn Green"));
119     }
120   }
121 
122 
123   /** creates and sets direction and speed of the bouncing ball */
124   public void bounceBall()
125   {
126     bouncingBall = new OvalSprite(1,1);
127     bouncingBall.setSize(.1);
128     bouncingBall.setLocation(.5,.3);
129     bouncingBall.setColor(getColor("orange"));
130     addSprite(bouncingBall);
131 
132     bouncer=new ProjectileTransformer(0.10.5);
133     bouncingBall.addTransformer(bouncer);
134 
135     schedule(new Blinker().5);
136   }
137   /** makes the ball blink every 1/2 second*/
138   class Blinker extends TimedAction
139   {
140     public void act()
141     {
142       boolean vis=bouncingBall.isVisible();
143       bouncingBall.setVisible(!vis);
144       schedule(this,.5);
145     }
146   }
147   /** sets bounce boundaries for bouncingBall */
148   public void bounce()
149   {
150     bouncingBall.bounceOffOf(screenOutline);
151     bouncingBall.bounceOffOf(fire);
152     bouncingBall.bounceOffOf(nuke);
153     bouncingBall.bounceOffOf(spin1);
154     bouncingBall.bounceOffOf(spin2);
155   }
156   /** creates the screen outline sprite to keep moving object on the screen */
157   public void addScreenOutline()
158   {
159     PolygonSprite screen = new PolygonSprite(.0,.0,1,.0,1,1,.0,1);
160     screenOutline = new OutlineSprite(screen);
161     screenOutline.setSize(1.1);
162     screenOutline.setLineThickness(0.05);
163     screenOutline.setLocation(0.50.5);
164     screenOutline.setColor(getColor("black"));
165     addSprite(screenOutline);
166   }
167 
168 
169   /**makes and displays the artist and title of the game */
170   public void titleAndArtist()
171   {
172     artist = new StringSprite("BY: Kevin Rohrer");
173     artist.setSize(.4);
174     artist.setLocation(.5.95);
175     addSprite(artist);
176 
177     title = new StringSprite("Headache Maker");
178     title.setSize(.55);
179     title.setLocation(.5.1);
180     addSprite(title);
181   }
182 
183 
184   /** creates the text to go into the help screen*/
185   public void helpScreen()
186   {
187     String helpText=
188         "click on an image to play its sound<br>"+
189         "or press the (C) or (R) key to change the color of the spining objects<br>"+
190         "Enjoy.";
191     setHelpText(helpText);
192   }
193 }


Download/View Rohrer/Interactive_Art_Assignment_6.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