GBell/Dot Removes Shapes

From ggc

Jump to: navigation, search

01 package GBell;
02 import wiki.Wiki;
03 import fang.*;
04 import java.awt.*;
05 import java.awt.geom.*;
06 
07 /**
08  * All about my game here.
09  @author Gbell
10  */
11 public class Dot_Removes_Shapes extends GameLoop
12 {
13   /**an oval*/
14   private Sprite[] oval;
15 
16   /**a dot*/
17   private Sprite dot;
18 
19   /**a tracker*/
20   private ProjectileTracker tracker;
21 
22   /**sets up the game*/
23   public void startGame()
24   {
25     pauseToggle();
26     oval=new Sprite[100];
27     makeSprites();
28     addSprites();
29 
30   }
31 
32   /**makes the sprites*/
33   private void makeSprites()
34   {
35     dot=new OvalSprite(1,1);
36     dot.setScale(.1);
37     dot.setColor(Color.GREEN);
38     canvas.addSprite(dot);
39 
40     for(int i=0; i<oval.length; i++)
41     {
42       oval[i]=new PolygonSprite(random.nextInt(5)+3);
43       oval[i].setScale(random.nextDouble());
44       oval[i].setLocation(random.nextDouble(), random.nextDouble());
45       Color color=new Color(random.nextFloat(), random.nextFloat(), random.nextFloat());
46       oval[i].setColor(color);
47     }
48   }
49 
50   /**adds the sprites to the screen*/
51   private void addSprites()
52   {
53     for(int i=0; i<oval.length; i++)
54     {
55       canvas.addSprite(oval);
56     }
57   }
58 
59   public void advanceFrame(double timePassed)
60   {
61     Point2D.Double click=getPlayer().getMouse().getClickLocation();
62     if(click!=null)
63     {
64       /**ball follows mouse*/
65     }
66     handleCollisions();
67     trackerSetup();
68   }
69   private void handleCollisions()
70   {
71     for (int i=0; i<oval.length; i++)
72     {
73       if(dot.intersects(oval[i]))
74       {
75         canvas.removeSprite(oval[i]);
76       }
77     }
78   }
79 
80   private void trackerSetup()
81   {
82     Point2D.Double direction=getPlayer().getMouse().getLocation();
83     direction.x-=dot.getLocation().x;
84     direction.y-=dot.getLocation().y;
85     tracker=new ProjectileTracker(direction);
86     dot.setTracker(tracker);
87   }
88 }


Download/View GBell/Dot_Removes_Shapes.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