Derrick/AssignmentSixIneractiveArt

From ggc

Jump to: navigation, search

001 package Derrick;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * All about my game.
009  @author Derrick Dixon
010  */
011 public class AssignmentSixIneractiveArt extends Game
012 {
013 
014   private Sound ding, shipsound;
015   private OutlineSprite boundary, forcefield;
016   private ProjectileTransformer projectile;
017   private OvalSprite shot;
018   private String helpbox;
019   private ImageSprite car, spaceship, sun;
020   private RectangleSprite background;
021   private StringSprite title, artistname;
022 
023   //**Makes forcefield for spaceship blink*/
024   class ForcefieldBlinker extends TimedAction
025   {
026     public void act()
027     {
028       boolean vis=forcefield.isVisible();
029       forcefield.setVisible(!vis);
030       schedule(this0.5);
031     }
032   }
033   /**Makes and adds boundary for shot and forcefield spaceship*/
034   private  void makeAndAddBoundary()
035   {
036     boundary=new OutlineSprite(new RectangleSprite(2,2));
037     boundary.setSize(1.0);
038 
039     boundary.setColor(Palette.getColor("WHITE"));
040     boundary.setLineThickness(0.0001);
041     boundary.setLocation(0.50.5);
042     addSprite(boundary);
043 
044     forcefield=new OutlineSprite(new RectangleSprite(2,1));
045     forcefield.setSize(0.45);
046     forcefield.setColor(Palette.getColor("Blue"));
047     forcefield.setLineThickness(0.15);
048     forcefield.setLocation(0.50.2);
049     addSprite(forcefield);
050 
051 
052     Spinner spinshield;
053     spinshield=new Spinner(0);
054     spinshield.setRotationDegrees(45);
055 
056     forcefield.addTransformer(spinshield);
057 
058   }
059   /**Makes Sounds I used ding twice Because I could not find another sound to use*/
060   private void makeAndAddSound()
061   {
062     ding=new Sound("DingLower.wav");
063 
064     shipsound=new Sound("DingLower.wav");
065     shipsound.setVolume(0.05);
066 shipsound.loop();
067 
068 
069 
070   }
071   /**Makes shot fired, color and size*/
072   private void makeAndAddShot()
073 
074   {
075     shot=new OvalSprite(11);
076     shot.setSize(0.025);
077     shot.setColor(Palette.getColor("BLACK"));
078     shot.setLocation(0.50.305);
079     addSprite(shot);
080 
081 
082   }
083   /** The in java the game background is black so in order for me to
084   make the background and the images in my art not clash I changed the background
085   this method also makes and creates the car image*/
086   private void makeAndAddCarBackground()
087   {
088     background=new RectangleSprite(22);
089     background.setColor(Palette.getColor("WHITE"));
090     background.setSize(1.0);
091     background.setLocation(0.50.5);
092     addSprite(background);
093 
094     car=new ImageSprite("Car123.jpg");
095     car.setSize(0.10);
096     car.setLocation(0.50.80);
097     addSprite(car);
098 
099   }
100   /**Here I add a spinner and an image of a spinner.
101   the image is spun by the spinner*/
102   private void makeAndAddSpaceship()
103   {
104     spaceship=new ImageSprite("Spaceship.jpg");
105     spaceship.setSize(0.4);
106     spaceship.setLocation(0.50.2);
107     addSprite(spaceship);
108 
109     Spinner spinship;
110     spinship=new Spinner(0);
111     spinship.setRotationDegrees(45);
112 
113     spaceship.addTransformer(spinship);
114   }
115   /**Creates caption in help box*/
116   private void makeAndAddGetHelp()
117   {
118     String helpbox=
119         "Press start to begin.<br>"+
120         "Click on a location to move the car.<br>"+
121         "Press r to change the color of shot fired";
122 
123     setHelpText(helpbox);
124   }
125   /**Creates String sprite with artist name and title*/
126   private void makeAndAddStrings()
127   {
128     artistname=new StringSprite("Derrick");
129     artistname.setColor(Palette.getColor("Yellow Green"));
130     artistname.setSize(0.50);
131     artistname.setLocation(0.50.25);
132     addSprite(artistname);
133 
134     title=new StringSprite("U.F.O.");
135     title.setColor(Palette.getColor("Black"));
136     title.setSize(0.50);
137     title.setLocation(0.500.75);
138     addSprite(title);
139   }
140 
141   /**makes and creates sun as well as its movement */
142   private void makeAndAddSun()
143   {
144     sun=new ImageSprite("sun.gif");
145     sun.setSize(0.10);
146 
147     addSprite(sun);
148 
149     OutlineTransformer transformer;
150     transformer=new OutlineTransformer(0.25,
151                                        0.10.1,
152                                        0.5, -0.25,
153                                        1.00.25,
154                                        0.990.25,
155                                        0.5, -0.25,
156                                        0.10.1);
157     transformer.setLooping(true);
158 
159     sun.addTransformer(transformer);
160     sun.setLocation(transformer.getCurrentPoint());
161     addSprite(sun);
162   }
163   /**sets up the game*/
164   public void setup()
165   {
166     makeAndAddSound();
167     makeAndAddGetHelp();
168     makeAndAddCarBackground();
169     makeAndAddSun();
170     makeAndAddSpaceship();
171     makeAndAddShot();
172     makeAndAddBoundary();
173     makeAndAddStrings();
174     schedule(new ForcefieldBlinker()1);
175     playSoundImmediately();
176 
177 
178     projectile=new ProjectileTransformer(0.10.25);
179     shot.setTracker(projectile);
180   }
181   /**Here we tell the shot what to bounce off of*/
182   private void handleCollisions()
183   {
184     shot.bounceOffOf(boundary);
185     shot.bounceOffOf(forcefield);
186   }
187   /**Causes a delay in the color change of the shot fired*/
188   class DelayedResponse extends TimedAction
189   {
190     public void act()
191 
192     {
193       shot.setColor(Palette.getColor("Red"));
194 
195     }
196   }
197   /**handle input and game events*/
198   public void advance()
199   {
200 
201     handleCollisions();
202     if(getClick2D()!=null)
203     {
204 
205       
206       title.setVisible(false);
207       artistname.setVisible(false);
208       car.setLocation(getClick2D());
209       ding.play();
210 
211     }
212     if(getKeyPressed()=='r')
213     {
214       schedule(new DelayedResponse()2.5);
215     }
216 
217   }
218 }


Download/View Derrick/AssignmentSixIneractiveArt.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