From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch01;
02
03 importimport means to make the classes and/or packages available in this program scg.ch01.spacesprites.*; // get all space sprites
04 importimport means to make the classes and/or packages available in this program fang2.core.Game;
05
06 /** Asteroids-clone game */
07 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Meteors
08 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
09 privateprivate is used to restrict access to the current class only Ship playersShip; // Ship = component type for game
10 privateprivate is used to restrict access to the current class only Meteor rock; // Meteor = component type for game
11
12 //Called (automatically) by FANG before the game starts
13 @Override
14 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
15 playersShip =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Ship(thisthis means the current object (the implicit parameter)); // get new component from system
16 playersShip.setColor(getColor("SCG Red"));
17 playersShip.setLocation(0.2, 0.8); // id.command(parameters)
18 // what to shoot, what to run into
19 playersShip.setTarget(Meteor.classclass is a group of fields and methods used for making objects);
20 playersShip.addCollision(Meteor.classclass is a group of fields and methods used for making objects);
21 // show the score and remaining life counter
22 playersShip.showLives();
23 playersShip.showScore();
24 addSprite(playersShip); // add ship to game
25
26 rock =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Meteor(thisthis means the current object (the implicit parameter)); // get new component
27 rock.setLocation(0.8, 0.8); // position
28 addSprite(rock); // add rock to game
29 }close braces end code blocks and must match an earlier open brace
30 }close braces end code blocks and must match an earlier open brace
31
32 //Uploaded on Mon Mar 29 21:40:22 EDT 2010
|
Download/View scg/ch01/Meteors.java