scg/ch05/ColoredRectangles

From FANG

Jump to: navigation, search

01 package scg.ch05;
02 
03 import fang2.attributes.Location2D;
04 import fang2.core.Game;
05 import fang2.sprites.RectangleSprite;
06 
07 /**
08  * ColoredRectangles demonstrates how to use local variables. The class
09  * has no fields and no setup method. In advance, it checks for a mouse
10  * click and if there is one, it creates a new, randomly sized and
11  * randomly colored rectangle centered where the mouse was clicked.
12  */
13 public class ColoredRectangles
14   extends Game {
15   /**
16    * Check for a mouse click; if one is clicked, make a random
17    * rectangle.
18    */
19   @Override
20   public void advance(double secondsSinceLastCall{
21     Location2D mouseClick;
22     mouseClick = getClick2D();
23 
24     if (mouseClick != null{// any click at all?
25       RectangleSprite rectangle;
26       rectangle = new RectangleSprite(randomDouble(), randomDouble());
27       rectangle.setColor(randomColor());
28       rectangle.setLocation(mouseClick);
29       addSprite(rectangle);
30     }
31     // Is rectangle in scope?
32   }
33 }
34 
35 //Uploaded on Mon Mar 29 21:39:05 EDT 2010


Download/View scg/ch05/ColoredRectangles.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

Games
Games