home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / enxle1f6 / src / games / battle / client / clientapplet / clientarcadeanimator.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.3 KB  |  93 lines

  1. /*
  2.  * @(#)ClientArcadeAnimatr.java
  3.  */
  4.  
  5. package games.Battle.client.ClientApplet;
  6.  
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.lang.Thread;
  10.  
  11. /*
  12.  * This simple client class is used to draw the smoke and fire
  13.  * animations encountered during conflicts between oposing players
  14.  * on the Europa game board. Basically the ClientArcadeAnimator
  15.  * is started as a thread, runs for a specified number of frames
  16.  * at a given frame rate, and then dies.
  17.  *
  18.  * @author Alex Nicolaou
  19.  * @author Jay Steele
  20.  */
  21. public class ClientArcadeAnimator implements Runnable {
  22.  
  23.     /**
  24.      * The graphics device to animate on.
  25.      */
  26.     Graphics g = null;
  27.  
  28.     /**
  29.      * The x locationo of the animation on the board.
  30.      */
  31.     int x = 0; 
  32.  
  33.     /**
  34.      * The y locationo of the animation on the board.
  35.      */
  36.     int y = 0;
  37.  
  38.     /**
  39.      * The array of images to animate.
  40.      */
  41.     Image imageArray[] = null;
  42.  
  43.     /**
  44.      * The number of frames to animate per second.
  45.      */
  46.     int fps = 15;
  47.  
  48.     /**
  49.      * The total number of frames to animate before dying.
  50.      */
  51.     int duration = 15;
  52.  
  53.     /**
  54.      * Construct a ClientArcadeAnimator. This runnable, when started
  55.      * as a thread will draw the array of images to the graphics context
  56.      * at the location (x,y) for dur frames at fps frames per second.
  57.      * @param g the Graphics context
  58.      * @param x the x location to draw
  59.      * @param y the y location to draw
  60.      * @param images the array of images to animate
  61.      * @param fps the number of frames to draw per second
  62.      * @param dur the total number of frames to animate
  63.      * @see Graphics
  64.      * @see Image
  65.      */
  66.     public ClientArcadeAnimator(Graphics g, int x, int y, Image images[], 
  67.                                 int fps, int dur) 
  68.     {
  69.         this.g = g;
  70.         this.x = x;
  71.         this.y = y;
  72.         this.imageArray = images;
  73.         this.fps = fps;
  74.         this.duration = dur;
  75.     }
  76.  
  77.     /**
  78.      * The main body for the ClientArcadeAnimator runnable. The method
  79.      * just loops and delays at appropriate values to achieve the
  80.      * results specified in the contructor.
  81.      */
  82.     public void run() {
  83.         long delay = (long)((float)1000.0 / (float)fps);
  84.         for (int f=0; f<duration; f++) {
  85.             int frame = f % imageArray.length;
  86.             try { 
  87.                 Thread.currentThread().sleep(delay);
  88.             } catch ( Exception e ) {}
  89.             g.drawImage(imageArray[frame], x, y, ClientImages.applet);
  90.         }
  91.     }
  92. }
  93.