home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / Gamelication / examples / Boinkaroids / Bigoobie.java < prev    next >
Encoding:
Java Source  |  1998-04-20  |  2.2 KB  |  101 lines

  1. /**
  2. *
  3.  * Bigoobie.java
  4.  * @author    Mark G. Tacchi (mtacchi@next.com) 
  5.  * @version    0.8
  6.  * Mar 18/1996
  7. *
  8. * A Bigoobie transparent shell containing two orbiting goobies.  They take
  9.  * a number of hits and then pop.
  10.  *
  11.  * Bigoobies harm ships and bullets harm Bigoobies.
  12.  *
  13. */
  14.  
  15. import java.lang.Math;
  16. import com.next.gt.*;
  17.  
  18. public class Bigoobie extends Actor {
  19.     //
  20.     // This actor has to be hit this many times before dying.
  21.     //
  22.     public int attackResistance= 3;
  23.   
  24. Bigoobie(Boinkaroids theOwner) {
  25.     super();
  26.     java.awt.Image            theImage;
  27.     java.awt.MediaTracker        tracker;
  28.     owner= theOwner;
  29.   
  30.     theImage = owner.getImage(owner.getCodeBase(), "images/bigoobie.gif");
  31.     tracker = new java.awt.MediaTracker(theOwner);
  32.     tracker.addImage(theImage, 0);
  33.     
  34.     try{
  35.         tracker.waitForID(0);
  36.     } 
  37.     catch (InterruptedException e) {}
  38.     
  39.     x= (Math.random()*512);
  40.     y= (Math.random()*512);
  41.     velocity_x= (double)((int)Gamelication.randBetween(0.5,1.5)*2 - 1) * Gamelication.randBetween(16.,48.);
  42.     velocity_y= (double)((int)Gamelication.randBetween(0.5,1.5)*2 - 1) * Gamelication.randBetween(16.,48.);
  43.     setImage (theImage, 4, 12);
  44.     currentFrame= (int)Gamelication.randBetween(0, numFrames);
  45.  
  46. } /*Bigoobie()*/
  47.  
  48.  
  49. /**
  50.  * Explode goobie.
  51.  */
  52. public void explode()
  53. {
  54.     //
  55.     //  free the 2 goobies
  56.     //
  57.     for (int i= 0; i<2; i++) {
  58.         owner.actorManager.addActor(new Goobie(owner, this));
  59.         ((Boinkaroids)owner).addOneBadGuy();
  60.     } /*next_i*/
  61.  
  62.     //
  63.     // play explode sound
  64.     //
  65.     owner.play(owner.getCodeBase(), "sounds/pop.au");
  66.   
  67.     //
  68.     // give credit for hitting me, increase score
  69.     //
  70.     owner.scoreManager.addToScore(500);
  71.   
  72.     //
  73.     // i'm dead, i should schedule to be removed
  74.     //
  75.     owner.actorManager.removeActor(this);
  76.   
  77.     //
  78.     // tell the Gamelication that there is one less bad guy
  79.     //
  80.     ((Boinkaroids)owner).removeOneBadGuy();    
  81. } /*explode*/
  82.  
  83.  
  84. /**
  85.  * Handle collision with an actor.
  86.  */
  87. protected void collideWithActor (Actor theActor){
  88.     String theActorClassName= theActor.getClass().getName();
  89.     if (theActorClassName.equals("Bullet") ||
  90.             theActorClassName.equals("Ship") ) {
  91.         if (--attackResistance<0) {
  92.             explode();
  93.         }
  94.         else {
  95.             owner.play(owner.getCodeBase(), "sounds/futility.au");
  96.         }
  97.     } /*endif*/ 
  98. } /*collideWithActor*/
  99.  
  100. } /*Bigoobie*/
  101.