TwoDArray

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 TwoDArray 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][2];
26     for(int i=0; i<oval.length; i++)
27     {
28       for(int j=0; j<oval[i].length; j++)
29       {
30         oval[i][j]=new OvalSprite(21);
31         oval[i][j].setScale(0.25);
32         oval[i][j].setLocation(random.nextDouble(), random.nextDouble());
33       }
34     }
35   }
36 
37   /**adds the sprites to the screen*/
38   private void addSprites()
39   {
40     for(int i=0; i<oval.length; i++)
41     {
42       for(int j=0; j<oval[i].length; j++)
43       {
44         canvas.addSprite(oval[i][j]);
45       }
46     }
47   }
48 
49   private void handleCollisions()
50   {
51     Point2D.Double click=getPlayer().getMouse().getClickLocation();
52     if(click!=null)
53     {
54       for(int i=0; i<oval.length; i++)
55       {
56         for(int j=0; j<oval[i].length; j++)
57         {
58           if(canvas.containsSprite(oval[i][j]))
59           {
60             if(oval[i][j].intersects(click))
61             {
62               canvas.removeSprite(oval[i][j]);
63             }
64           }
65         }
66       }
67     }
68   }
69 
70   /**handle input and game events*/
71   public void advanceFrame(double timePassed)
72   {
73     handleCollisions();
74   }
75 }


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