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

  1. import com.next.gt.Actor;
  2. import com.next.gt.Gamelication;
  3. import java.awt.Image;
  4.  
  5. public class Asteroid extends Actor {
  6.    public static final int SMALL_SIZE = 0;
  7.    public static final int MEDIUM_SIZE = 1;
  8.    public static final int LARGE_SIZE = 2;
  9.    int size;
  10.    String name;
  11.  
  12.    Asteroid(Gamelication var1, Asteroid var2, String var3, int var4) {
  13.       String[] var5 = new String[]{"S", "M", "L", "G"};
  14.       super.owner = var1;
  15.       this.size = var4;
  16.       this.name = var3;
  17.       if (var4 == 2) {
  18.          super.x = Math.random() * (double)512.0F;
  19.          super.y = Math.random() * (double)512.0F;
  20.          super.velocity_x = (double)((int)Gamelication.randBetween((double)0.5F, (double)1.5F) * 2 - 1) * Gamelication.randBetween((double)8.0F, (double)32.0F);
  21.          super.velocity_y = (double)((int)Gamelication.randBetween((double)0.5F, (double)1.5F) * 2 - 1) * Gamelication.randBetween((double)8.0F, (double)32.0F);
  22.       } else {
  23.          super.x = var2.x;
  24.          super.y = var2.y;
  25.          super.velocity_x = var2.velocity_x * Gamelication.randBetween(0.6, 1.4);
  26.          super.velocity_y = var2.velocity_y * Gamelication.randBetween(0.6, 1.4);
  27.       }
  28.  
  29.       Image var6 = super.owner.getImage(super.owner.getCodeBase(), "images/" + var3 + var5[var4] + ".gif");
  30.       ((Actor)this).setImage(var6, 4, 32);
  31.       super.currentFrame = (int)Gamelication.randBetween((double)0.0F, (double)super.numFrames);
  32.    }
  33.  
  34.    public void explode() {
  35.       if (this.size == 0) {
  36.          Explosion var1 = new Explosion(super.owner, this);
  37.          super.owner.actorManager.addActor(var1);
  38.       } else {
  39.          super.owner.play(super.owner.getCodeBase(), "sounds/explode1.au");
  40.       }
  41.  
  42.       if (this.size == 2) {
  43.          for(int var2 = 0; var2 < 2; ++var2) {
  44.             super.owner.actorManager.addActor(new Asteroid(super.owner, this, this.name, 1));
  45.             ((Boinkaroids)super.owner).addOneBadGuy();
  46.          }
  47.       } else if (this.size == 1) {
  48.          for(int var3 = 0; var3 < 2; ++var3) {
  49.             super.owner.actorManager.addActor(new Asteroid(super.owner, this, this.name, 0));
  50.             ((Boinkaroids)super.owner).addOneBadGuy();
  51.          }
  52.       }
  53.  
  54.       super.owner.scoreManager.addToScore((2 - this.size) * 200 + 100);
  55.       super.owner.actorManager.removeActor(this);
  56.       ((Boinkaroids)super.owner).removeOneBadGuy();
  57.    }
  58.  
  59.    protected void collideWithActor(Actor var1) {
  60.       String var2 = var1.getClass().getName();
  61.       if (var2.equals("Bullet") || var2.equals("Ship")) {
  62.          this.explode();
  63.       }
  64.  
  65.    }
  66. }
  67.