scg/ch01/CommentedMeteors

From FANG

Jump to: navigation, search

01 package scg.ch01;
02 
03 import scg.ch01.spacesprites.Meteor;
04 import scg.ch01.spacesprites.Ship;
05 import fang2.core.Game;
06 
07 
08 /**
09  * A simple Asteroids-clone game. Construct one ship, set it up so it
10  * can shoot rocks. Set up one rock, moving randomly on the screen. Let
11  * the games begin.
12  */
13 public class CommentedMeteors
14   extends Game {
15   /**
16    * the name of the ship; commands are given to the ship as messages of
17    * the form ship.<command>(<stuff>). Different command names appear in
18    * place of <command> and the <stuff> can be nothing, one item, or a
19    * comma-separated list of items.
20    */
21   private Ship playersShip;
22 
23   /**
24    * the name of the meteor. Commands can be given to rock, too, by
25    * placing the name, rock, to the left of a dot.
26    */
27   private Meteor rock;
28 
29   /**
30    * setup is a command defined for Games. It is called, automatically,
31    * by FANG, once before the game begins. Here we build a new ship and
32    * a new rock, adding each one to the game. We do some customization
33    * on the ship, too.
34    */
35   @Override
36   public void setup() {
37     playersShip = new Ship(this);
38     /* where should the ship appear on the screen? upper-left corner is
39      * (0.0, 0.0), lower-right corner is (1.0, 1.0) so x-coordinates get
40      * bigger to the right, y-coordinates get bigger going downward.
41      */
42     playersShip.setLocation(0.50.5);
43 
44     /* tell the ship what kind of sprites its bullets can hit and what
45      * kinds of sprites can strike it (costing it a life). */
46     playersShip.setTarget(Meteor.class);
47     playersShip.addCollision(Meteor.class);
48 
49     /* show the score and remaining life counter */
50     playersShip.showLives();
51     playersShip.showScore();
52 
53     addSprite(playersShip);
54 
55     /* create, position, and add the meteor */
56     rock = new Meteor(this);
57     rock.setLocation(0.80.8);
58     addSprite(rock);
59   }
60 }
61 
62 //Uploaded on Mon Mar 29 21:42:10 EDT 2010


Download/View scg/ch01/CommentedMeteors.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