home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / MCII.EXE / MRV.java < prev    next >
Encoding:
Java Source  |  1996-09-20  |  2.5 KB  |  118 lines

  1. /* MRV.java - Maneuvering Reentry Vehicle. */
  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.Image;
  27.  
  28. class MRV extends GameObject
  29. {
  30.     final int mrvWidth = 12;
  31.     final int mrvHeight = 6;
  32.     final int jump = 10;
  33.     
  34.     int x, y, endy, speed;
  35.     Image mrvImage;
  36.     MissileCommando parent;
  37.     
  38.     MRV (int startx, int starty, int endy, int speed, Image mrvImage, MissileCommando parent)
  39.     {
  40.     this.x = startx;
  41.     this.y = starty;
  42.     this.endy = endy;
  43.     this.speed = speed;
  44.     this.mrvImage = mrvImage;
  45.     this.parent = parent;
  46.     }
  47.  
  48.     void erase (Graphics g)
  49.     {
  50.     g.setColor (skyColor);
  51.     g.fillOval (x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight);
  52.     //g.fillRect (x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight);
  53.     }
  54.  
  55.     void paint (Graphics g)
  56.     {
  57.     erase (g);
  58.     
  59.     if (!alive)
  60.     {
  61.         return;
  62.     }
  63.     else if (explode)
  64.     {
  65.         alive = false;
  66.         explode = false;
  67.         return;
  68.     }
  69.  
  70.     double chance = Math.random ();
  71.     if (chance < 0.25)
  72.     {
  73.         x -= jump;
  74.     }
  75.     else if (chance > 0.75)
  76.     {
  77.         x += jump;
  78.     }
  79.     
  80.     y += speed;
  81.  
  82.     if (y > endy)
  83.     {
  84.         alive = false;
  85.     }
  86.     
  87.     if (alive)
  88.     {
  89.         g.setColor (Color.orange);
  90.         g.fillOval (x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight);
  91.         //g.drawImage (mrvImage, x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight, parent);
  92.     }
  93.     }
  94.  
  95.     boolean collision (int x2, int y2, int range)
  96.     {
  97.     if (!alive || explode)
  98.     {
  99.         return false;
  100.     }
  101.     
  102.     int distance = (int) Math.sqrt (((x2 - x) * (x2 - x))
  103.                     + ((y2 - y) * (y2 - y)));
  104.     range += mrvWidth/2;
  105.     return distance <= range;
  106.     }
  107.  
  108.     boolean collision (int x2, int y2, int w, int h)
  109.     {
  110.     if (!alive || explode)
  111.     {
  112.         return false;
  113.     }
  114.     
  115.     return x >= x2 && x <= (x2 + w) && y >= y2 && y <= (y2 + h);
  116.     }
  117. }
  118.