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 MeteorShower
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 rockA; // Meteor = component type for game
11 privateprivate is used to restrict access to the current class only Meteor rockB; // Meteor = component type for game
12 privateprivate is used to restrict access to the current class only Meteor rockC; // Meteor = component type for game
13
14 //Called (automatically) by FANG before the game starts
15 @Override
16 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
17 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
18 playersShip.setLocation(0.2, 0.8); // id.command(parameters)
19 // what to shoot, what to run into
20 playersShip.setTarget(Meteor.classclass is a group of fields and methods used for making objects);
21 playersShip.addCollision(Meteor.classclass is a group of fields and methods used for making objects);
22 // show the score and remaining life counter
23 playersShip.showLives();
24 playersShip.showScore();
25 addSprite(playersShip); // add ship to game
26
27 rockA =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), 4); // get new component
28 rockA.setLocation(0.8, 0.2); // position
29 addSprite(rockA); // add rock to game
30
31 rockB =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), 2); // get new component
32 rockB.setColor(getColor("yellow"));
33 rockB.setLocation(0.2, 0.2); // position
34 addSprite(rockB); // add rock to game
35
36 rockC =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
37 rockC.setColor(getColor("misty rose"));
38 rockC.setLocation(0.8, 0.8); // position
39 addSprite(rockC); // add rock to game
40 }close braces end code blocks and must match an earlier open brace
41 }close braces end code blocks and must match an earlier open brace
42
43 //Uploaded on Mon Mar 29 21:40:48 EDT 2010
|
Download/View scg/ch01/MeteorShower.java