home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / Gamelicator / examples / Boinkaroids / Boinkaroids.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-20  |  4.5 KB  |  147 lines

  1. import com.next.gt.BonusHandler;
  2. import com.next.gt.Gamelication;
  3. import com.next.gt.ImageManager;
  4. import com.next.gt.ScoreManager;
  5. import com.next.gt.WindowDestroyer;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Frame;
  9. import java.awt.Label;
  10. import java.awt.Rectangle;
  11. import java.awt.Window;
  12. import java.awt.event.KeyEvent;
  13. import java.awt.event.KeyListener;
  14.  
  15. public class Boinkaroids extends Gamelication implements BonusHandler, KeyListener {
  16.    public Ship player;
  17.    public int numShips;
  18.    private int badGuyCount;
  19.    public int level;
  20.    public boolean createNewPlayer = true;
  21.    private Label myLabel;
  22.    private int SAFETY_ZONE_WIDTH = 128;
  23.    private int SAFETY_ZONE_HEIGHT = 128;
  24.  
  25.    public void init() {
  26.       super.init(500, 400, "./");
  27.       Frame var1 = new Frame("Boinkaroids");
  28.       ((Component)var1).setSize(500, 500);
  29.       this.myLabel = new Label("Score: 00000000   Ships: " + this.numShips + "   Level: " + this.level);
  30.       ((Container)var1).add("South", this.myLabel);
  31.       ((Container)var1).add("Center", this);
  32.       ((Window)var1).addWindowListener(new WindowDestroyer(var1, this));
  33.       var1.setResizable(false);
  34.       super.scoreManager = new ScoreManager();
  35.       super.scoreManager.registerForBonusNotification(this, 20000);
  36.       ((Window)var1).show();
  37.       new ImageManager(this);
  38.       this.myLabel.addKeyListener(this);
  39.       this.newGame();
  40.       super.displayManager.setBackgroundTile(((Gamelication)this).getImage(((Gamelication)this).getCodeBase(), "images/background.gif"));
  41.       ((Gamelication)this).start();
  42.       ((Gamelication)this).run();
  43.    }
  44.  
  45.    public void newGame() {
  46.       super.scoreManager.setScore(0);
  47.       this.numShips = 3;
  48.       this.badGuyCount = 0;
  49.       this.level = 0;
  50.       this.removePlayer();
  51.       super.actorManager.removeAllActors();
  52.       this.createActors();
  53.    }
  54.  
  55.    public void newLevel() {
  56.       ++this.level;
  57.       super.actorManager.removeAllActors();
  58.       this.createActors();
  59.    }
  60.  
  61.    public void createActors() {
  62.       for(int var1 = 0; var1 < 2 * this.level; ++var1) {
  63.          super.actorManager.addActor(new Asteroid(this, (Asteroid)null, "gumball", 2));
  64.          this.addOneBadGuy();
  65.       }
  66.  
  67.       for(int var2 = 0; (double)var2 < (double)0.5F * (double)this.level; ++var2) {
  68.          super.actorManager.addActor(new Bigoobie(this));
  69.          this.addOneBadGuy();
  70.       }
  71.  
  72.       this.createPlayer();
  73.    }
  74.  
  75.    public void removeOneBadGuy() {
  76.       --this.badGuyCount;
  77.    }
  78.  
  79.    public void addOneBadGuy() {
  80.       ++this.badGuyCount;
  81.    }
  82.  
  83.    public void createPlayer() {
  84.       this.removePlayer();
  85.       this.player = new Ship(this);
  86.       this.myLabel.addKeyListener(this.player);
  87.       super.actorManager.addActor(this.player);
  88.       this.createNewPlayer = false;
  89.    }
  90.  
  91.    public void removePlayer() {
  92.       if (this.player != null) {
  93.          super.actorManager.removeActor(this.player);
  94.          this.myLabel.removeKeyListener(this.player);
  95.          this.player = null;
  96.       }
  97.  
  98.    }
  99.  
  100.    public void tick() {
  101.       super.tick();
  102.       this.myLabel.setText("Score: " + super.scoreManager.score + "   Ships: " + this.numShips + "   Level: " + this.level);
  103.       if (this.badGuyCount <= 0) {
  104.          this.newLevel();
  105.       }
  106.  
  107.       if (this.createNewPlayer) {
  108.          Rectangle var1 = new Rectangle(((Component)this).getSize().width / 2 - this.SAFETY_ZONE_WIDTH / 2, ((Component)this).getSize().height / 2 - this.SAFETY_ZONE_HEIGHT / 2, this.SAFETY_ZONE_WIDTH, this.SAFETY_ZONE_HEIGHT);
  109.          if (!super.actorManager.isActorIn(var1)) {
  110.             this.createNewPlayer = false;
  111.             this.createPlayer();
  112.          }
  113.       }
  114.  
  115.    }
  116.  
  117.    public void keyPressed(KeyEvent var1) {
  118.       if (var1.getKeyCode() == 112) {
  119.          this.newGame();
  120.       }
  121.  
  122.    }
  123.  
  124.    public void keyReleased(KeyEvent var1) {
  125.    }
  126.  
  127.    public void keyTyped(KeyEvent var1) {
  128.    }
  129.  
  130.    public void didAchieveBonus() {
  131.       ++this.numShips;
  132.    }
  133.  
  134.    public void decrementShipCount() {
  135.       if (this.numShips-- > 0) {
  136.          this.createNewPlayer = true;
  137.          this.removePlayer();
  138.       }
  139.  
  140.    }
  141.  
  142.    public static void main(String[] var0) {
  143.       Boinkaroids var1 = new Boinkaroids();
  144.       var1.init();
  145.    }
  146. }
  147.