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

  1. /* Bomb.java - The Big One */
  2. /* 
  3.  * Copyright (C) 1996 Mark Boyns <boyns@sdsu.edu>
  4.  *
  5.  * Missile Commando II
  6.  * <URL:http://www.sdsu.edu/~boyns/java/mcii/>
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. import java.awt.Graphics;
  24. import java.awt.Color;
  25. import java.awt.Image;
  26.  
  27. class Bomb extends GameObject
  28. {
  29.     final int bombWidth = 19;
  30.     final int bombHeight = 26;
  31.     
  32.     int x, y, endx, endy, speed;
  33.     Image bombImage;
  34.     MissileCommando parent;
  35.     
  36.     Bomb (int startx, int starty, int endx, int endy, int speed, Image bombImage, MissileCommando parent)
  37.     {
  38.     this.x = startx;
  39.     this.y = starty;
  40.     this.endx = endx;
  41.     this.endy = endy;
  42.     this.speed = speed;
  43.     this.bombImage = bombImage;
  44.     this.parent = parent;
  45.     }
  46.  
  47.     void erase (Graphics g)
  48.     {
  49.     g.setColor (skyColor);
  50.     g.fillRect (x - bombWidth/2, y - bombWidth/2, bombWidth, bombHeight);
  51.     }
  52.  
  53.     void paint (Graphics g)
  54.     {
  55.     erase (g);
  56.  
  57.     if (!alive)
  58.     {
  59.         return;
  60.     }
  61.     else if (explode)
  62.     {
  63.         alive = false;
  64.         explode = false;
  65.         return;
  66.     }
  67.  
  68.     y += speed;
  69.  
  70.     if (y > endy)
  71.     {
  72.         alive = false;
  73.     }
  74.  
  75.     if (alive)
  76.     {
  77.         g.drawImage (bombImage, x - bombWidth/2, y - bombWidth/2, bombWidth, bombHeight, parent);
  78.     }
  79.     }
  80.  
  81.     boolean collision (int x2, int y2, int range)
  82.     {
  83.     if (!alive || explode)
  84.     {
  85.         return false;
  86.     }
  87.     
  88.     int distance = (int) Math.sqrt (((x2 - x) * (x2 - x))
  89.                     + ((y2 - y) * (y2 - y)));
  90.     range += bombWidth/2;
  91.     return distance <= range;
  92.     }
  93.  
  94.     boolean collision (int x2, int y2, int w, int h)
  95.     {
  96.     if (!alive || explode)
  97.     {
  98.         return false;
  99.     }
  100.     
  101.     return x >= x2 && x <= (x2 + w) && y >= y2 && y <= (y2 + h);
  102.     }
  103. }
  104.