ThreeDots

From ggc

Jump to: navigation, search

01 import fang.*;
02 import java.awt.*;
03 import java.awt.geom.*;
04 
05 /**
06  * All about my game here.
07  @author Jam Jenkins
08  */
09 public class ThreeDots extends GameLoop
10 {
11   /**an oval*/
12   private Sprite[] oval;
13 
14   /**sets up the game*/
15   public void startGame()
16   {
17     makeSprites();
18     addSprites();
19     setHelpText("Click on the ovals to make them go away");
20   }
21 
22   /**makes the sprites*/
23   private void makeSprites()
24   {
25     oval=new Sprite[3];
26     for(int i=0; i<oval.length; i++)
27     {
28       oval[i]=new OvalSprite(21);
29       oval[i].setScale(0.25);
30       oval[i].setLocation(random.nextDouble(), random.nextDouble());
31     }
32   }
33 
34   /**adds the sprites to the screen*/
35   private void addSprites()
36   {
37     canvas.addSprite(oval);
38   }
39 
40   private void handleCollisions()
41   {
42     Point2D.Double click=getPlayer().getMouse().getClickLocation();
43     if(click!=null)
44     {
45       for(int i=0; i<oval.length; i++)
46       {
47         if(canvas.containsSprite(oval[i]))
48         {
49           if(oval[i].intersects(click))
50           {
51             canvas.removeSprite(oval[i]);
52           }
53         }
54       }
55     }
56   }
57 
58   /**handle input and game events*/
59   public void advanceFrame(double timePassed)
60   {
61     handleCollisions();
62   }
63 }


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