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

  1. import com.next.gt.Actor;
  2. import com.next.gt.Gamelication;
  3. import java.awt.Image;
  4. import java.awt.MediaTracker;
  5.  
  6. public class Goobie extends Actor {
  7.    private static double GRAVITATIONAL_PULL = (double)0.5F;
  8.  
  9.    Goobie(Gamelication var1, Bigoobie var2) {
  10.       super.owner = var1;
  11.       Image var3 = super.owner.getImage(super.owner.getCodeBase(), "images/goobie.gif");
  12.       MediaTracker var4 = new MediaTracker(var1);
  13.       var4.addImage(var3, 0);
  14.  
  15.       try {
  16.          var4.waitForID(0);
  17.       } catch (InterruptedException var5) {
  18.       }
  19.  
  20.       super.x = (double)((int)(var2.x - (double)(super.width - var2.width) / (double)2.0F));
  21.       super.y = (double)((int)(var2.y - (double)(super.height - var2.height) / (double)2.0F));
  22.       super.velocity_x = var2.velocity_x * Gamelication.randBetween(0.2, 1.4);
  23.       super.velocity_y = var2.velocity_y * Gamelication.randBetween(0.2, 1.4);
  24.       ((Actor)this).setImage(var3);
  25.    }
  26.  
  27.    public void calculateNewPosition() {
  28.       super.calculateNewPosition();
  29.       if (((Boinkaroids)super.owner).player != null) {
  30.          if (super.x > ((Boinkaroids)super.owner).player.x) {
  31.             super.velocity_x -= GRAVITATIONAL_PULL;
  32.          } else {
  33.             super.velocity_x += GRAVITATIONAL_PULL;
  34.          }
  35.  
  36.          if (super.y > ((Boinkaroids)super.owner).player.y) {
  37.             super.velocity_y -= GRAVITATIONAL_PULL;
  38.          } else {
  39.             super.velocity_y += GRAVITATIONAL_PULL;
  40.          }
  41.       }
  42.    }
  43.  
  44.    public void explode() {
  45.       super.owner.play(super.owner.getCodeBase(), "sounds/smack.au");
  46.       super.owner.scoreManager.addToScore(1000);
  47.       super.owner.actorManager.removeActor(this);
  48.       ((Boinkaroids)super.owner).removeOneBadGuy();
  49.    }
  50.  
  51.    protected void collideWithActor(Actor var1) {
  52.       String var2 = var1.getClass().getName();
  53.       if (var2.equals("Bullet") || var2.equals("Ship")) {
  54.          this.explode();
  55.       }
  56.  
  57.    }
  58. }
  59.