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

  1. head    1.3;
  2. access;
  3. symbols;
  4. locks; strict;
  5. comment    @# @;
  6.  
  7.  
  8. 1.3
  9. date    98.04.15.16.30.07;    author mds1274;    state Exp;
  10. branches;
  11. next    1.2;
  12.  
  13. 1.2
  14. date    98.04.15.16.03.49;    author jgh8962;    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.  * Bullet.java
  36.  * @@author    Mark G. Tacchi (mtacchi@@next.com) 
  37.  * @@version    0.8
  38.  * Mar 12/1996
  39. *
  40.  * A Bullet is created by the Ship object when it is sent a fire message.
  41.  * Bullets live for a specified time to live (ttl).
  42.  *
  43.  * This Actor collides with all but Ships and Explosions.
  44.  *
  45.  */
  46.  
  47. import java.awt.*;
  48. import com.next.gt.*;
  49.  
  50. public class Bullet extends Actor {
  51.  
  52.     //
  53.     // variable used to compare against for auto death
  54.     //
  55.     long startTime;
  56.   
  57.     //
  58.     // time to live
  59.     //
  60.     long ttl= 1750;
  61.   
  62.     //
  63.     // the ship object
  64.     //
  65.     Ship    explodee;
  66.  
  67.    
  68. Bullet(Gamelication theOwner, Ship theExplodee) {
  69.     super();
  70.   
  71.     double            explodeeVelocity= theExplodee.getSpeed();
  72.     double            explodeeTheta= theExplodee.getTheta();
  73.     Image            theImage;
  74.   
  75.     owner= theOwner;
  76.     explodee= theExplodee;
  77.   
  78.     x= (explodee.x + (explodee.width/2.0));
  79.     y= (explodee.y + (explodee.height/2.0));
  80.   
  81.     theImage= owner.getImage(owner.getCodeBase(), "images/bullet.gif");    
  82.     setImage (theImage, 4, 16);
  83.       
  84.     velocity_x= Math.cos(explodeeTheta)*(explodeeVelocity + 150.);
  85.     velocity_y= Math.sin(explodeeTheta+Math.PI)*(explodeeVelocity + 150.);
  86.  
  87.     x+= (velocity_x * .1);
  88.     y+= (velocity_y * .1);
  89.  
  90.     startTime= owner.currentTickTimeMillis;
  91. } /*Bullet()*/
  92.  
  93.  
  94. /**
  95.  * Override tick to implement a timed death.
  96.  */
  97. public void tick(){
  98.     super.tick();
  99.     
  100.     if (owner.currentTickTimeMillis - startTime > ttl) {
  101.         if (explodee.numBullets>0)
  102.             explodee.numBullets--;    
  103.         owner.actorManager.removeActor (this);
  104.     } /*endif*/
  105. } /*tick*/
  106.  
  107.  
  108.  
  109. /**
  110.  * Handle collision with an actor.
  111.  */
  112. protected void collideWithActor (Actor theActor){
  113.     String theActorClassName= theActor.getClass().getName();
  114.   
  115.     if (theActorClassName.equals("Asteroid") ||
  116.             theActorClassName.equals("Bigoobie")) {
  117.         if (explodee.numBullets>0)
  118.             explodee.numBullets--;
  119.         owner.actorManager.removeActor(this);
  120.     } /*endif*/
  121.   
  122. } /*collideWithActor*/
  123.  
  124. } /*Bullet*/
  125. @
  126.  
  127.  
  128. 1.2
  129. log
  130. @*** empty log message ***
  131. @
  132. text
  133. @a15 1
  134.  
  135. d20 4
  136. a23 4
  137.   //
  138.   // variable used to compare against for auto death
  139.   //
  140.   long startTime;
  141. d25 4
  142. a28 4
  143.   //
  144.   // time to live
  145.   //
  146.   long ttl= 1750;
  147. d30 5
  148. a34 4
  149.   //
  150.   // the ship object
  151.   //
  152.   Ship    explodee;
  153. d37 1
  154. a37 1
  155.   super();
  156. d39 3
  157. a41 3
  158.   double            explodeeVelocity= theExplodee.getSpeed();
  159.   double            explodeeTheta= theExplodee.getTheta();
  160.   Image                theImage;
  161. d43 2
  162. a44 2
  163.   owner= theOwner;
  164.   explodee= theExplodee;
  165. d46 2
  166. a47 2
  167.   x= (explodee.x + (explodee.width/2.0));
  168.   y= (explodee.y + (explodee.height/2.0));
  169. d49 2
  170. a50 2
  171.   theImage= owner.getImage(owner.getCodeBase(), "images/bullet.gif");    
  172.   setImage (theImage, 4, 16);
  173. d52 2
  174. a53 2
  175.   velocity_x= Math.cos(explodeeTheta)*(explodeeVelocity + 150.);
  176.   velocity_y= Math.sin(explodeeTheta+Math.PI)*(explodeeVelocity + 150.);
  177. d55 2
  178. a56 3
  179.   x+= (velocity_x * .1);
  180.   y+= (velocity_y * .1);
  181.  
  182. d58 1
  183. a58 2
  184.   startTime= owner.currentTickTimeMillis;
  185.  
  186. a61 1
  187.  
  188. d65 2
  189. a66 3
  190. public void tick()
  191. {
  192.   super.tick();
  193. d68 5
  194. a72 5
  195.   if (owner.currentTickTimeMillis - startTime > ttl) {
  196.     if (explodee.numBullets>0)explodee.numBullets--;
  197.       owner.actorManager.removeActor (this);
  198.   } /*endif*/
  199.   
  200. d80 2
  201. a81 3
  202. protected void collideWithActor (Actor theActor)
  203. {
  204.   String theActorClassName= theActor.getClass().getName();
  205. d83 6
  206. a88 5
  207.   if (theActorClassName.equals("Asteroid") ||
  208.       theActorClassName.equals("Bigoobie")) {
  209.         if (explodee.numBullets>0)explodee.numBullets--;
  210.     owner.actorManager.removeActor(this);
  211.   } /*endif*/
  212. d91 1
  213. @
  214.  
  215.  
  216. 1.1
  217. log
  218. @Initial revision
  219. @
  220. text
  221. @d29 1
  222. a29 1
  223.   long ttl= 1500;
  224. @
  225.