home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / Gamelication / examples / Boinkaroids / RCS / Goobie.java,v < prev    next >
Encoding:
Text File  |  1998-04-19  |  4.7 KB  |  270 lines

  1. head    1.3;
  2. access;
  3. symbols;
  4. locks; strict;
  5. comment    @# @;
  6.  
  7.  
  8. 1.3
  9. date    98.04.19.17.36.50;    author mds1274;    state Exp;
  10. branches;
  11. next    1.2;
  12.  
  13. 1.2
  14. date    98.04.15.16.27.04;    author mds1274;    state Exp;
  15. branches;
  16. next    1.1;
  17.  
  18. 1.1
  19. date    98.04.10.17.53.49;    author jgh8962;    state Exp;
  20. branches;
  21. next    ;
  22.  
  23.  
  24. desc
  25. @@
  26.  
  27.  
  28. 1.3
  29. log
  30. @*** empty log message ***
  31. @
  32. text
  33. @/**
  34. *
  35.  * Goobie.java
  36.  * @@author    Mark G. Tacchi (mtacchi@@next.com) 
  37.  * @@version    0.8
  38.  * Mar 18/1996
  39. *
  40. * A goobie is just a little green thing that lives within a transparent
  41.  * shell until that shell pops.
  42.  *
  43.  * Goobies harm ships and bullets harm Goobies.
  44.  *
  45. */
  46.  
  47.  
  48. import java.lang.Math;
  49. import com.next.gt.*;
  50.  
  51. public class Goobie extends Actor {
  52.  
  53.     //
  54.     // Gravity strength toward the ship.
  55.     //
  56.     private static double    GRAVITATIONAL_PULL= 0.5;
  57.  
  58.     
  59. /**
  60.  * Constructor
  61.  */  
  62. Goobie(Gamelication theOwner, Bigoobie explodee) {
  63.     super();
  64.     java.awt.Image            theImage;
  65.     java.awt.MediaTracker        tracker;
  66.     owner= theOwner;
  67.   
  68.     theImage = owner.getImage(owner.getCodeBase(), "images/goobie.gif");
  69.     tracker = new java.awt.MediaTracker(theOwner);
  70.     tracker.addImage(theImage, 0);
  71.  
  72.     try{
  73.         tracker.waitForID(0);
  74.     } 
  75.     catch (InterruptedException e) {}
  76.   
  77.     x= (int)(explodee.x - (width - explodee.width)/2.0);
  78.     y= (int)(explodee.y - (height - explodee.height)/2.0);
  79.     velocity_x= explodee.velocity_x * Gamelication.randBetween(0.2,1.4);
  80.     velocity_y= explodee.velocity_y * Gamelication.randBetween(0.2,1.4);
  81.   
  82.     setImage (theImage);
  83.  
  84. } /*Goobie()*/
  85.  
  86.  
  87. /**
  88.  * Gravitate torwards player.
  89.  */
  90. public void calculateNewPosition() {
  91.     super.calculateNewPosition();
  92.   
  93.     //
  94.     // Is the player alive?
  95.     //
  96.     if (((Boinkaroids)owner).player==null) return;
  97.   
  98.     //
  99.     // gravitate towards player
  100.     //
  101.     if (x> ((Boinkaroids)owner).player.x) velocity_x-= GRAVITATIONAL_PULL;
  102.     else velocity_x+= GRAVITATIONAL_PULL;
  103.     if (y> ((Boinkaroids)owner).player.y) velocity_y-= GRAVITATIONAL_PULL;
  104.     else velocity_y+= GRAVITATIONAL_PULL;
  105.     
  106. } /*calculateNewPosition*/
  107.  
  108.  
  109. /**
  110.  * Explode goobie.
  111.  */
  112. public void explode(){
  113.     //
  114.     // play explode sound
  115.     //
  116.     owner.play(owner.getCodeBase(), "sounds/smack.au");
  117.   
  118.     //
  119.     // give credit for hitting me, increase score
  120.     //
  121.     owner.scoreManager.addToScore(1000);
  122.   
  123.     //
  124.     // i'm dead, i should schedule to be removed
  125.     //
  126.     owner.actorManager.removeActor(this);
  127.   
  128.     //
  129.     // tell the Gamelication that there is one less bad guy
  130.     //
  131.     ((Boinkaroids)owner).removeOneBadGuy();
  132.     
  133. } /*explode*/
  134.  
  135.  
  136. /**
  137.  * Handle collision with an actor.
  138.  */
  139. protected void collideWithActor (Actor theActor){
  140.     String theActorClassName= theActor.getClass().getName();
  141.   
  142.     if (theActorClassName.equals("Bullet") ||
  143.             theActorClassName.equals("Ship") ) {
  144.         explode();
  145.     } /*endif*/
  146. } /*collideWithActor*/
  147.  
  148. } /*Goobie*/
  149. @
  150.  
  151.  
  152. 1.2
  153. log
  154. @*** empty log message ***
  155. @
  156. text
  157. @d99 1
  158. a99 1
  159.     ((Boinkaroids)owner).badGuyCount--;
  160. @
  161.  
  162.  
  163. 1.1
  164. log
  165. @Initial revision
  166. @
  167. text
  168. @d15 1
  169. a15 1
  170. //import java.applet.Applet;
  171. a16 1
  172.  
  173. d21 9
  174. a29 5
  175.   //
  176.   // Gravity strength toward the ship.
  177.   //
  178.   private static double    GRAVITATIONAL_PULL= 0.5;
  179.   
  180. d31 4
  181. a34 5
  182.   super();
  183.  java.awt.Image            theImage;
  184.   java.awt.MediaTracker        tracker;
  185.  
  186.   owner= theOwner;
  187. d36 3
  188. a38 2
  189.   theImage = owner.getImage(owner.getCodeBase(), "images/goobie.gif");
  190.   tracker = new java.awt.MediaTracker(theOwner);
  191. d40 1
  192. a40 2
  193.   tracker.addImage(theImage, 0);
  194.   try{
  195. d42 2
  196. a43 2
  197.   } 
  198.   catch (InterruptedException e) {}
  199. d45 4
  200. a48 4
  201.   x= (int)(explodee.x - (width - explodee.width)/2.0);
  202.   y= (int)(explodee.y - (height - explodee.height)/2.0);
  203.   velocity_x= explodee.velocity_x * Gamelication.randBetween(0.2,1.4);
  204.   velocity_y= explodee.velocity_y * Gamelication.randBetween(0.2,1.4);
  205. d50 1
  206. a50 1
  207.   setImage (theImage);
  208. d59 1
  209. a59 1
  210.   super.calculateNewPosition();
  211. d61 4
  212. a64 4
  213.   //
  214.   // Is the player alive?
  215.   //
  216.   if (((Boinkaroids)owner).player==null) return;
  217. d66 7
  218. a72 7
  219.   //
  220.   // gravitate towards player
  221.   //
  222.   if (x> ((Boinkaroids)owner).player.x) velocity_x-= GRAVITATIONAL_PULL;
  223.   else velocity_x+= GRAVITATIONAL_PULL;
  224.   if (y> ((Boinkaroids)owner).player.y) velocity_y-= GRAVITATIONAL_PULL;
  225.   else velocity_y+= GRAVITATIONAL_PULL;
  226. a76 1
  227.  
  228. d80 5
  229. a84 6
  230. public void explode()
  231. {
  232.   //
  233.   // play explode sound
  234.   //
  235.   owner.play(owner.getCodeBase(), "sounds/smack.au");
  236. d86 4
  237. a89 4
  238.   //
  239.   // give credit for hitting me, increase score
  240.   //
  241.   owner.scoreManager.addToScore(1000);
  242. d91 4
  243. a94 4
  244.   //
  245.   // i'm dead, i should schedule to be removed
  246.   //
  247.   owner.actorManager.removeActor(this);
  248. d96 4
  249. a99 4
  250.   //
  251.   // tell the Gamelication that there is one less bad guy
  252.   //
  253.   ((Boinkaroids)owner).badGuyCount--;
  254. a103 2
  255.  
  256.  
  257. d107 2
  258. a108 3
  259. protected void collideWithActor (Actor theActor)
  260. {
  261.   String theActorClassName= theActor.getClass().getName();
  262. d110 4
  263. a113 5
  264.   if (theActorClassName.equals("Bullet") ||
  265.       theActorClassName.equals("Ship") ) {
  266.          explode();
  267.   } /*endif*/
  268.   
  269. @
  270.