home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / de86gnzn / examples / boinkaroids / bigoobie.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.3 KB  |  112 lines

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