home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-04-20 | 4.3 KB | 238 lines |
- /**
- *
- * Boinkaroids.java
- * @author Mark G. Tacchi (mtacchi@next.com)
- * @version 0.8
- * Mar 27/1996
- *
- * Boinkaroids is an Asteroids type game developed for the purpose of showing
- * off the Gamelet Toolkit. It makes use of all of the features within the
- * Gamelet Toolkit.
- *
- */
-
- import java.awt.*;
- import java.io.*;
- import java.awt.event.*;
- import java.util.*;
-
- import com.next.gt.*;
-
- public class Boinkaroids extends Gamelication implements BonusHandler, KeyListener{
-
- //
- // Boinkaroids variables
- //
- public Ship player = null;
- public int numShips;
- private int badGuyCount;
- public int level;
-
- //
- // Should a player be created?
- //
- public boolean createNewPlayer = true;
-
- //
- // Score label.
- //
- private Label myLabel;
-
- //
- // This area that has to be clear for a ship to enter level.
- //
- private int SAFETY_ZONE_WIDTH= 128;
- private int SAFETY_ZONE_HEIGHT= 128;
-
-
- /**
- * Initialize.
- */
- public void init() {
- super.init( 500, 400, "./" );
- Frame f = new Frame( "Boinkaroids" );
- f.setSize( 500, 500 );
- myLabel= new Label("Score: 00000000" + " Ships: " + numShips
- + " Level: "+ level);
- f.add("South",myLabel);
-
- f.add( "Center",this );
- f.addWindowListener( new WindowDestroyer( f, this ) );
- f.setResizable( false );
-
- //
- // initialize the score manager
- //
- scoreManager= new ScoreManager();
- scoreManager.registerForBonusNotification(this, 20000);
-
-
- //
- // show the main window
- //
- f.show();
-
- //
- // cache images
- //
- new ImageManager(this);
-
- myLabel.addKeyListener( this );
-
- this.newGame();
- //
- // paint background image
- //
- displayManager.setBackgroundTile (getImage(getCodeBase(), "images/background.gif"));
-
- start();
- run();
- } /*init*/
-
-
- /**
- * Set up the new game.
- */
- public void newGame() {
- scoreManager.setScore (0);
- numShips= 3;
- badGuyCount= 0;
- level= 0;
- removePlayer();
- actorManager.removeAllActors();
- this.createActors();
- } /*newGame*/
-
-
- /**
- * Advance levels.
- */
- public void newLevel() {
- level++;
- actorManager.removeAllActors();
- this.createActors();
- } /*newLevel*/
-
-
- /**
- * Create the actors for this scene.
- */
- public void createActors() {
- for (int i= 0; i< 2*level; i++) {
- actorManager.addActor (new Asteroid(this, null, "gumball",
- Asteroid.LARGE_SIZE));
- addOneBadGuy();
- } /*nexti*/
- for (int i= 0; i< 0.5*level; i++) {
- actorManager.addActor (new Bigoobie(this));
- addOneBadGuy();
- } /*next_i*/
- this.createPlayer();
- } /*createActors*/
-
- /**
- * Remove one bad guy
- */
- public void removeOneBadGuy(){
- badGuyCount--;
- }
-
- /**
- * Remove one bad guy
- */
- public void addOneBadGuy(){
- badGuyCount++;
- }
-
- /**
- * Create the player object.
- */
- public void createPlayer() {
- removePlayer();
- player = new Ship(this);
- myLabel.addKeyListener(player);
- actorManager.addActor (player);
- createNewPlayer = false;
- } /*createPlayer*/
-
-
- /**
- * Remove the player object.
- */
- public void removePlayer() {
- if (player!=null) {
- actorManager.removeActor(player);
- myLabel.removeKeyListener( player );
- player = null;
- } /*endif*/
- } /*createPlayer*/
-
-
- /**
- * Override tick to test for specific game events.
- */
- public void tick() {
- super.tick();
- myLabel.setText("Score: " + scoreManager.score + " Ships: " + numShips
- + " Level: "+ level );
-
- if (badGuyCount <= 0)
- this.newLevel();
-
- if (createNewPlayer) {
- Rectangle myRectangle= new Rectangle((int)this.getSize().width/2 - SAFETY_ZONE_WIDTH/2,
- (int)this.getSize().height/2 - SAFETY_ZONE_HEIGHT/2,
- SAFETY_ZONE_WIDTH,
- SAFETY_ZONE_HEIGHT);
- if (!actorManager.isActorIn(myRectangle)) {
- createNewPlayer = false;
- this.createPlayer();
- } /*endif*/
- } /*endif*/
- } /*tick*/
-
-
- /**
- * Handle keyboard events that control ship.
- */
- public void keyPressed( KeyEvent k ){
- if(k.getKeyCode() == k.VK_F1 )
- this.newGame();
- }
-
- public void keyReleased( KeyEvent k ){
- }
-
- public void keyTyped( KeyEvent k ){
- }
-
-
- /**
- * Give bonus ship for getting a certain score.
- */
- public void didAchieveBonus() {
- numShips++;
- } /*didAchieveBonus*/
-
-
- /**
- * Player must have died, decrement ship count.
- */
- public void decrementShipCount() {
- if (numShips-- > 0) {
- createNewPlayer= true;
- removePlayer();
- } /*endif*/
- } /*decrementShipCount*/
-
-
- /**
- * Static main to begin the application.
- */
- public static void main( String[] args ) {
- Boinkaroids boinkaroids = new Boinkaroids();
- boinkaroids.init();
- }
-
- } /*Boinkaroids*/
-