home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-20 | 2.5 KB | 118 lines |
- /* MRV.java - Maneuvering Reentry Vehicle. */
-
- /*
- * 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.Image;
-
- class MRV extends GameObject
- {
- final int mrvWidth = 12;
- final int mrvHeight = 6;
- final int jump = 10;
-
- int x, y, endy, speed;
- Image mrvImage;
- MissileCommando parent;
-
- MRV (int startx, int starty, int endy, int speed, Image mrvImage, MissileCommando parent)
- {
- this.x = startx;
- this.y = starty;
- this.endy = endy;
- this.speed = speed;
- this.mrvImage = mrvImage;
- this.parent = parent;
- }
-
- void erase (Graphics g)
- {
- g.setColor (skyColor);
- g.fillOval (x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight);
- //g.fillRect (x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight);
- }
-
- void paint (Graphics g)
- {
- erase (g);
-
- if (!alive)
- {
- return;
- }
- else if (explode)
- {
- alive = false;
- explode = false;
- return;
- }
-
- double chance = Math.random ();
- if (chance < 0.25)
- {
- x -= jump;
- }
- else if (chance > 0.75)
- {
- x += jump;
- }
-
- y += speed;
-
- if (y > endy)
- {
- alive = false;
- }
-
- if (alive)
- {
- g.setColor (Color.orange);
- g.fillOval (x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight);
- //g.drawImage (mrvImage, x - mrvWidth/2, y - mrvHeight/2, mrvWidth, mrvHeight, parent);
- }
- }
-
- boolean collision (int x2, int y2, int range)
- {
- if (!alive || explode)
- {
- return false;
- }
-
- int distance = (int) Math.sqrt (((x2 - x) * (x2 - x))
- + ((y2 - y) * (y2 - y)));
- range += mrvWidth/2;
- return distance <= range;
- }
-
- boolean collision (int x2, int y2, int w, int h)
- {
- if (!alive || explode)
- {
- return false;
- }
-
- return x >= x2 && x <= (x2 + w) && y >= y2 && y <= (y2 + h);
- }
- }
-