home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / MCII.EXE / Explosion.java < prev    next >
Encoding:
Java Source  |  1996-10-02  |  1.9 KB  |  94 lines

  1. /* Explosion.java - Generic explosion. */
  2.  
  3. /* 
  4.  * Copyright (C) 1996 Mark Boyns <boyns@sdsu.edu>
  5.  *
  6.  * Missile Commando II
  7.  * <URL:http://www.sdsu.edu/~boyns/java/mcii/>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. import java.awt.Graphics;
  25. import java.awt.Color;
  26. import java.awt.Point;
  27.  
  28. class Explosion extends GameObject
  29. {
  30.     int x, y;
  31.     int size;
  32.     Color color;
  33.  
  34.     double growScale = 0.10;
  35.     double shrinkScale = 0.15;
  36.     
  37.     boolean growing = true;
  38.     double scale = 0.10;
  39.     
  40.     Explosion (int x, int y, int size)
  41.     {
  42.     this.x = x;
  43.     this.y = y;
  44.     this.size = size;
  45.     color = Color.red;
  46.     }
  47.     
  48.     void erase (Graphics g)
  49.     {
  50.     g.setColor (skyColor);
  51.     int stage = (int)((size) * scale);
  52.     g.fillOval (x - stage/2, y - stage/2, stage, stage);
  53.     }
  54.     
  55.     void paint (Graphics g)
  56.     {
  57.     if (!alive)
  58.     {
  59.         return;
  60.     }
  61.  
  62.     if (growing)
  63.     {
  64.         scale += growScale;
  65.         if (scale >= 1.0)
  66.         {
  67.         growing = false;
  68.         }
  69.     }
  70.     else
  71.     {
  72.         erase (g);
  73.         
  74.         scale -= shrinkScale;
  75.         if (scale < 0.05)
  76.         {
  77.         alive = false;
  78.         }
  79.     }
  80.  
  81.     if (alive)
  82.     {
  83.         g.setColor (color);
  84.         int stage = (int)((size) * scale);
  85.         g.fillOval (x - stage/2, y - stage/2, stage, stage);
  86.     }
  87.     }
  88.  
  89.     int currentSize ()
  90.     {
  91.     return (int)(size * scale) / 2;
  92.     }
  93. }
  94.