jam/IfInputExamples

From ggc

Jump to: navigation, search

01 package jam;
02 
03 import fang.*;
04 import java.awt.*;
05 import java.awt.geom.*;
06 
07 /**
08  * All about my game.
09  @author My Name Here
10  */
11 public class IfInputExamples extends Game
12 {
13   /**an oval*/
14   private Sprite oval;
15   private Sprite sprite;
16 
17   /**sets up the game*/
18   public void setup()
19   {
20     makeSprites();
21     addSprites();
22   }
23 
24   /**makes the sprites*/
25   private void makeSprites()
26   {
27     oval=new OvalSprite(21);
28     oval.setSize(0.75);
29     oval.setLocation(0.50.5);
30   }
31 
32   /**adds the sprites to the screen*/
33   private void addSprites()
34   {
35     addSprite(oval);
36   }
37 
38   /**handle input and game events*/
39   public void advance()
40   {
41     if(getClick2D()!=null)
42     {
43       oval.setLocation(getMouse2D());
44       oval.setSize(randomDouble());
45 
46       String contents="("+getMouseX()+", "+getMouseY()+")";
47       if(sprite!=null)
48         removeSprite(sprite);
49       sprite=new StringSprite(contents);
50       sprite.setLocation(getMouse2D());
51       sprite.setSize(0.25);
52       sprite.setColor(new Color(255255255128));
53       addSprite(sprite);
54     }
55     if(getKeyPressed()=='r')
56     {
57       oval.setLocation(getMouse2D());
58       oval.setColor(Palette.getColor("red"));
59     }
60     if(getKeyPressed()=='w')
61     {
62       oval.setColor(Palette.getColor("white"));
63     }
64   }
65 }


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