home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / Gamelication / examples / Boinkaroids / RCS / Asteroid.java,v next >
Encoding:
Text File  |  1998-04-19  |  5.9 KB  |  309 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.15.01;    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.  * Asteroid.java
  36.  * @@author    Mark G. Tacchi (mtacchi@@next.com) 
  37.  * @@version    0.8
  38.  * Mar 11/1996
  39. *
  40.  * A generic Asteroid class which handles varying sizes of asteroids.  Images
  41.  * should have filenames with corresponding S, M, L, and G appended to them
  42.  * (example asteroidM.gif).
  43.  * This Actor collides with Bullets and Ships.  It is responsible for creating
  44.  * an explosion object.
  45.  *
  46. */
  47.  
  48.  
  49. import java.lang.Math;
  50.  
  51. import com.next.gt.*;
  52.  
  53. public class Asteroid extends Actor {
  54.  
  55.     //
  56.     // Size of the Asteroid.
  57.     //
  58.     public static final     int    SMALL_SIZE= 0,
  59.                     MEDIUM_SIZE= 1,
  60.                     LARGE_SIZE= 2;
  61.     int size;
  62.   
  63.     //
  64.     // The filename prefix.
  65.     //
  66.     String name;
  67.           
  68. Asteroid(Gamelication theOwner, Asteroid explodee, String theName, int theSize) {
  69.     super();
  70.  
  71.     String[] theImageName= {"S", "M", "L", "G"};
  72.     java.awt.Image theImage;
  73.  
  74.     owner= theOwner;
  75.     size= theSize;
  76.     name= theName;
  77.   
  78.     if (theSize==LARGE_SIZE) {
  79.         x= (Math.random()*512);
  80.         y= (Math.random()*512);
  81.         velocity_x= (double)((int)Gamelication.randBetween(0.5,1.5)*2 - 1) * Gamelication.randBetween(8.,32.);
  82.         velocity_y= (double)((int)Gamelication.randBetween(0.5,1.5)*2 - 1) * Gamelication.randBetween(8.,32.);
  83.     }
  84.     else {
  85.         x= explodee.x;
  86.         y= explodee.y;
  87.             velocity_x= explodee.velocity_x * Gamelication.randBetween(0.6,1.4);
  88.             velocity_y= explodee.velocity_y * Gamelication.randBetween(0.6,1.4);
  89.     
  90.     }
  91.     theImage = owner.getImage(owner.getCodeBase(), "images/" +theName + theImageName[theSize] + ".gif");
  92.     setImage (theImage, 4, 32);
  93.     currentFrame= (int)Gamelication.randBetween(0, numFrames);
  94. } /*Asteroid()*/
  95.  
  96.  
  97. /**
  98.  * Explode asteroid.
  99.  */
  100. public void explode()
  101. {
  102.     Explosion anExplosion;
  103.   
  104.     //
  105.     // create explosion if smallest asteroid
  106.     //
  107.     if (size==SMALL_SIZE) {
  108.         anExplosion= new Explosion(owner, this);
  109.         owner.actorManager.addActor(anExplosion);
  110.     }
  111.     else { 
  112.         owner.play(owner.getCodeBase(), "sounds/explode1.au");
  113.     }
  114.  
  115.     //
  116.     // split off into smaller bits
  117.     //
  118.     if (size==LARGE_SIZE) {
  119.         for (int i=0; i<2; i++) {
  120.             owner.actorManager.addActor(new Asteroid(owner, this, name, 
  121.                                  MEDIUM_SIZE));
  122.             ((Boinkaroids)owner).addOneBadGuy();
  123.         } /*next_i*/
  124.     }
  125.     else if (size==MEDIUM_SIZE) {
  126.         for (int i=0; i<2; i++) {
  127.             owner.actorManager.addActor(new Asteroid(owner, this, name, 
  128.                                  SMALL_SIZE));
  129.             ((Boinkaroids)owner).addOneBadGuy();
  130.         } /*next_i*/
  131.     }
  132.  
  133.     //
  134.     // give credit for hitting me, increase score
  135.     //
  136.     owner.scoreManager.addToScore((2-size) * 200 + 100);
  137.   
  138.     //
  139.     // i'm dead, i should schedule to be removed
  140.     //
  141.     owner.actorManager.removeActor(this);
  142.   
  143.     //
  144.     // tell the Gamelication that there is one less bad guy
  145.     //
  146.     ((Boinkaroids)owner).removeOneBadGuy();
  147. } /*explode*/
  148.  
  149.  
  150. /**
  151.  * Handle collision with an actor.
  152.  */
  153. protected void collideWithActor (Actor theActor){
  154.     String theActorClassName= theActor.getClass().getName();
  155.     if (theActorClassName.equals("Bullet") ||
  156.             theActorClassName.equals("Ship") ) {
  157.         explode();
  158.     } /*endif*/
  159.   
  160. } /*collideWithActor*/
  161.  
  162. } /*Asteroid*/
  163. @
  164.  
  165.  
  166. 1.2
  167. log
  168. @*** empty log message ***
  169. @
  170. text
  171. @d90 1
  172. a90 1
  173.             ((Boinkaroids)owner).badGuyCount++;
  174. d97 1
  175. a97 1
  176.             ((Boinkaroids)owner).badGuyCount++;
  177. d114 1
  178. a114 1
  179.     ((Boinkaroids)owner).badGuyCount--;
  180. @
  181.  
  182.  
  183. 1.1
  184. log
  185. @Initial revision
  186. @
  187. text
  188. @d16 1
  189. a16 1
  190. //import java.applet.Applet;
  191. d23 5
  192. a27 5
  193.   //
  194.   // Size of the Asteroid.
  195.   //
  196.   public static final     int    SMALL_SIZE= 0,
  197.                       MEDIUM_SIZE= 1,
  198. d29 1
  199. a29 1
  200.   int                size;
  201. d31 4
  202. a34 4
  203.   //
  204.   // The filename prefix.
  205.   //
  206.   String            name;
  207. d37 1
  208. a37 1
  209.   super();
  210. d39 2
  211. a40 2
  212.   String[]                    theImageName= {"S", "M", "L", "G"};
  213.  java.awt.Image            theImage;
  214. d42 3
  215. a44 3
  216.   owner= theOwner;
  217.   size= theSize;
  218.   name= theName;
  219. d46 11
  220. a56 11
  221.   if (theSize==LARGE_SIZE) {
  222.     x= (Math.random()*512);
  223.     y= (Math.random()*512);
  224.     velocity_x= (double)((int)Gamelication.randBetween(0.5,1.5)*2 - 1) * Gamelication.randBetween(8.,32.);
  225.     velocity_y= (double)((int)Gamelication.randBetween(0.5,1.5)*2 - 1) * Gamelication.randBetween(8.,32.);
  226.   }
  227.   else {
  228.     x= explodee.x;
  229.     y= explodee.y;
  230.     velocity_x= explodee.velocity_x * Gamelication.randBetween(0.6,1.4);
  231.     velocity_y= explodee.velocity_y * Gamelication.randBetween(0.6,1.4);
  232. d58 4
  233. a61 6
  234.   }
  235.   theImage = owner.getImage(owner.getCodeBase(), "images/" +theName + theImageName[theSize] + ".gif");
  236.   setImage (theImage, 4, 32);
  237.  
  238.   currentFrame= (int)Gamelication.randBetween(0, numFrames);
  239.   
  240. a64 1
  241.  
  242. d70 1
  243. a70 1
  244.   Explosion anExplosion;
  245. d72 10
  246. a81 11
  247.   //
  248.   // create explosion if smallest asteroid
  249.   //
  250.   if (size==SMALL_SIZE) {
  251.     anExplosion= new Explosion(owner, this);
  252.     owner.actorManager.addActor(anExplosion);
  253.   }
  254.   else { 
  255.     owner.play(owner.getCodeBase(), "sounds/explode1.au");
  256.   }
  257.   
  258. d83 17
  259. a99 8
  260.   //
  261.   // split off into smaller bits
  262.   //
  263.   if (size==LARGE_SIZE) {
  264.     for (int i=0; i<2; i++) {
  265.       owner.actorManager.addActor(new Asteroid(owner, this, name, MEDIUM_SIZE));
  266.       ((Boinkaroids)owner).badGuyCount++;
  267.     } /*next_i*/
  268. d101 4
  269. a104 7
  270.   }
  271.   else if (size==MEDIUM_SIZE) {
  272.     for (int i=0; i<2; i++) {
  273.       owner.actorManager.addActor(new Asteroid(owner, this, name, SMALL_SIZE));
  274.       ((Boinkaroids)owner).badGuyCount++;
  275.     } /*next_i*/
  276.   }
  277. d106 4
  278. d111 4
  279. a114 15
  280.   //
  281.   // give credit for hitting me, increase score
  282.   //
  283.   owner.scoreManager.addToScore((2-size) * 200 + 100);
  284.   
  285.   //
  286.   // i'm dead, i should schedule to be removed
  287.   //
  288.   owner.actorManager.removeActor(this);
  289.   
  290.   //
  291.   // tell the Gamelication that there is one less bad guy
  292.   //
  293.   ((Boinkaroids)owner).badGuyCount--;
  294.   
  295. a117 1
  296.  
  297. d121 6
  298. a126 3
  299. protected void collideWithActor (Actor theActor)
  300. {
  301.   String theActorClassName= theActor.getClass().getName();
  302. a127 5
  303.   if (theActorClassName.equals("Bullet") ||
  304.       theActorClassName.equals("Ship") ) {
  305.     explode();
  306.   } /*endif*/
  307.   
  308. @
  309.