home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-02 | 1.9 KB | 94 lines |
- /* Explosion.java - Generic explosion. */
-
- /*
- * Copyright (C) 1996 Mark Boyns <boyns@sdsu.edu>
- *
- * Missile Commando II
- * <URL:http://www.sdsu.edu/~boyns/java/mcii/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- import java.awt.Graphics;
- import java.awt.Color;
- import java.awt.Point;
-
- class Explosion extends GameObject
- {
- int x, y;
- int size;
- Color color;
-
- double growScale = 0.10;
- double shrinkScale = 0.15;
-
- boolean growing = true;
- double scale = 0.10;
-
- Explosion (int x, int y, int size)
- {
- this.x = x;
- this.y = y;
- this.size = size;
- color = Color.red;
- }
-
- void erase (Graphics g)
- {
- g.setColor (skyColor);
- int stage = (int)((size) * scale);
- g.fillOval (x - stage/2, y - stage/2, stage, stage);
- }
-
- void paint (Graphics g)
- {
- if (!alive)
- {
- return;
- }
-
- if (growing)
- {
- scale += growScale;
- if (scale >= 1.0)
- {
- growing = false;
- }
- }
- else
- {
- erase (g);
-
- scale -= shrinkScale;
- if (scale < 0.05)
- {
- alive = false;
- }
- }
-
- if (alive)
- {
- g.setColor (color);
- int stage = (int)((size) * scale);
- g.fillOval (x - stage/2, y - stage/2, stage, stage);
- }
- }
-
- int currentSize ()
- {
- return (int)(size * scale) / 2;
- }
- }
-