home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class MissileCommando extends Applet implements Runnable {
- final String version = "MCII 1.1";
- final int worldWidth = 500;
- final int worldHeight = 300;
- final int scoreHeight = 25;
- final int controlsHeight = 50;
- final int screenWidth = 500;
- final int screenHeight = 375;
- final int baseWidth = 64;
- final int baseHeight = 32;
- final int baseGap = 30;
- final int maxBases = 5;
- final int missilePoints = 75;
- final int mrvPoints = 150;
- final int bombPoints;
- final int extraShotPoints = 10;
- final int extraBasePoints = 50;
- final int rebuildBasePoints = 10000;
- AudioClip missileSound;
- AudioClip missileExplosionSound;
- AudioClip mrvExplosionSound;
- AudioClip baseExplosionSound;
- AudioClip bombSound;
- boolean playing = false;
- boolean readyToPlay = false;
- boolean clearScreen = false;
- boolean paused = false;
- boolean soundEnabled = true;
- Thread thread;
- GameObjectMover mover;
- Controls controls;
- Vector bases;
- Vector missiles;
- Vector shots;
- Vector mrvs;
- Vector explosions;
- Vector bombs;
- Vector bombDebris;
- int score;
- int extraBaseScore;
- int level;
- int shotCount;
- int missileCount;
- int missileSpeed;
- int missileDelay;
- int mrvSpeed;
- int bombSpeed;
- Color skyColor = new Color(148, 198, 231);
- Graphics world;
- MediaTracker tracker;
- Image baseImage;
- Image mrvImage;
- Image bombImage;
- Font font;
- FontMetrics fontMetrics;
- String screenMessage;
-
- public void init() {
- this.font = new Font("TimesRoman", 1, 20);
- this.fontMetrics = ((Component)this).getFontMetrics(this.font);
- ((Component)this).setFont(this.font);
- this.tracker = new MediaTracker(this);
- this.baseImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), "images/base.gif");
- this.tracker.addImage(this.baseImage, 1);
- this.mrvImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), "images/mrv.gif");
- this.tracker.addImage(this.mrvImage, 1);
- this.bombImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), "images/bomb.gif");
- this.tracker.addImage(this.bombImage, 1);
- this.missileSound = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), "sounds/Rocket.au");
- this.missileExplosionSound = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), "sounds/Oomph.au");
- this.mrvExplosionSound = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), "sounds/Oomph.au");
- this.baseExplosionSound = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), "sounds/Explosion-2.au");
- this.bombSound = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), "sounds/ship_alarm.au");
- ((Component)this).setBackground(Color.white);
- ((Container)this).setLayout(new BorderLayout());
- this.controls = new Controls(this);
- ((Container)this).add("South", this.controls);
- ((Applet)this).resize(500, 375);
- this.thread = new Thread(this);
- this.thread.start();
- }
-
- public void start() {
- if (this.thread == null) {
- this.thread = new Thread(this);
- this.thread.start();
- }
-
- }
-
- public void stop() {
- if (this.thread != null && this.thread.isAlive()) {
- this.thread.stop();
- this.thread = null;
- }
-
- if (this.mover != null && this.mover.isAlive()) {
- this.mover.stop();
- this.mover = null;
- }
-
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (this.playing) {
- this.createShot(var2, var3 - 25);
- }
-
- return true;
- }
-
- void startGame() {
- this.readyToPlay = true;
- }
-
- void quitGame() {
- this.playing = false;
- }
-
- void resetScore() {
- this.clearScreen = true;
- this.score = 0;
- this.extraBaseScore = 0;
- this.level = 0;
- this.message((String)null);
- }
-
- void resetGame() {
- this.clearScreen = true;
- this.missiles = new Vector(100);
- this.shots = new Vector(100);
- this.mrvs = new Vector(100);
- this.explosions = new Vector(100);
- this.bombs = new Vector(100);
- this.bombDebris = new Vector(100);
- this.createBases();
- this.message((String)null);
- }
-
- void suspendGame() {
- if (this.thread != null && this.playing) {
- this.thread.suspend();
- if (this.mover != null && this.mover.isAlive()) {
- this.mover.suspend();
- }
-
- this.paused = true;
- this.clearScreen = true;
- ((Component)this).repaint();
- }
-
- }
-
- void resumeGame() {
- if (this.thread != null && this.playing) {
- this.thread.resume();
- if (this.mover != null && this.mover.isAlive()) {
- this.mover.resume();
- }
-
- this.paused = false;
- this.clearScreen = true;
- }
-
- }
-
- void enableSound() {
- this.soundEnabled = true;
- }
-
- void disableSound() {
- this.soundEnabled = false;
- }
-
- public void run() {
- ((Applet)this).showStatus("Loading images...");
- this.tracker.checkAll(true);
-
- try {
- this.tracker.waitForAll();
- } catch (Exception var9) {
- return;
- }
-
- ((Applet)this).showStatus("");
- this.resetGame();
- this.resetScore();
-
- while(true) {
- if (!this.playing && this.readyToPlay) {
- this.resetGame();
- this.resetScore();
- this.playing = true;
- this.readyToPlay = false;
- }
-
- if (this.playing) {
- ++this.level;
- } else if (this.level == 0) {
- this.level = 1;
- }
-
- if (this.playing) {
- this.missileDelay = 2000 - (this.level - 1) * 200;
- if (this.missileDelay < 500) {
- this.missileDelay = 500;
- }
- } else {
- this.missileDelay = 500;
- }
-
- this.missileSpeed = 5;
- this.mrvSpeed = 6;
- this.bombSpeed = 4;
- this.missileCount = 5 + (this.level - 1) * 5;
- this.shotCount = this.missileCount * 2;
- this.message("Level " + this.level);
-
- try {
- Thread.sleep(3000L);
- } catch (Exception var8) {
- }
-
- this.message((String)null);
- this.mover = new GameObjectMover(100, this);
- this.mover.start();
-
- while(this.missileCount > 0) {
- int var1 = this.missileSpeed;
- if (this.level > 1 && Math.random() > (double)0.75F) {
- var1 += (int)(Math.random() * (double)this.missileSpeed);
- }
-
- this.createMissile(var1);
- --this.missileCount;
- if (this.mrvs.size() < this.level) {
- double var2 = Math.random();
- if (var2 > 0.7) {
- this.createMRV(this.mrvSpeed);
- }
- }
-
- if (this.level > 1 && this.bombs.size() < 2) {
- double var12 = Math.random();
- if (var12 > 0.85) {
- this.createBomb(this.bombSpeed);
- }
- }
-
- if (!this.playing) {
- this.starWars();
- }
-
- if (!this.playing && this.readyToPlay) {
- break;
- }
-
- try {
- Thread.sleep((long)this.missileDelay);
- } catch (Exception var7) {
- }
- }
-
- if (!this.playing && this.readyToPlay) {
- this.mover.stop();
- } else {
- while((this.missiles.size() > 0 || this.mrvs.size() > 0 || this.explosions.size() > 0 || this.bombs.size() > 0 || this.bombDebris.size() > 0 || this.shots.size() > 0) && (this.playing || !this.readyToPlay)) {
- if (!this.playing && (this.missiles.size() > 0 || this.mrvs.size() > 0 || this.bombs.size() > 0)) {
- this.starWars();
- }
-
- try {
- Thread.sleep(500L);
- } catch (Exception var6) {
- }
- }
-
- this.mover.stop();
- int var10 = this.shotCount * 10;
- var10 += this.countAliveBases() * 50;
- this.incrementScore(var10);
- if (this.playing) {
- this.message("Bonus: " + var10);
-
- try {
- Thread.sleep(2000L);
- } catch (Exception var5) {
- }
-
- this.message((String)null);
- }
-
- this.rebuildBases();
- if (this.countAliveBases() == 0) {
- this.playing = false;
- this.mover = new GameObjectMover(400, this);
- this.mover.start();
- this.destroyWorld();
-
- while(this.explosions.size() > 0) {
- try {
- Thread.sleep(500L);
- } catch (Exception var4) {
- }
- }
-
- this.mover.stop();
- this.resetGame();
- }
- }
- }
- }
-
- void starWarsFireAt(Vector var1) {
- Enumeration var4 = var1.elements();
-
- while(var4.hasMoreElements()) {
- GameObject var5 = (GameObject)var4.nextElement();
- int var2;
- int var3;
- if (var5 instanceof Missile) {
- Missile var6 = (Missile)var5;
- var2 = (int)var6.x;
- var3 = (int)var6.y;
- } else if (var5 instanceof MRV) {
- MRV var7 = (MRV)var5;
- var2 = var7.x;
- var3 = var7.y;
- } else if (var5 instanceof Bomb) {
- Bomb var8 = (Bomb)var5;
- var2 = var8.x;
- var3 = var8.y;
- } else {
- var2 = 250;
- var3 = 150;
- }
-
- if (var3 > 60) {
- byte var9;
- if (Math.random() > (double)0.5F) {
- var9 = 1;
- } else {
- var9 = -1;
- }
-
- this.shots.addElement(new Shot(var2 + var9 * (int)(Math.random() * (double)40.0F), var3 + var9 * (int)(Math.random() * (double)40.0F), 60));
- }
- }
-
- }
-
- void starWars() {
- this.starWarsFireAt(this.missiles);
- this.starWarsFireAt(this.mrvs);
- this.starWarsFireAt(this.bombs);
- }
-
- void createShot(int var1, int var2) {
- if (this.shotCount > 0) {
- this.shots.addElement(new Shot(var1, var2, 60));
- --this.shotCount;
- }
-
- }
-
- void createMissile(int var1, int var2, int var3) {
- int var4 = 30 + (int)(Math.random() * (double)470.0F);
- short var5 = 299;
- if (this.soundEnabled && this.missileSound != null && this.playing) {
- this.missileSound.play();
- }
-
- this.missiles.addElement(new Missile(var1, var2, var4, var5, var3));
- }
-
- void createMissile(int var1) {
- int var2 = (int)(Math.random() * (double)500.0F);
- byte var3 = 1;
- this.createMissile(var2, var3, var1);
- }
-
- void destroyMissile(Missile var1) {
- if (this.soundEnabled && this.missileExplosionSound != null && this.playing) {
- this.missileExplosionSound.play();
- }
-
- ((GameObject)var1).explode();
- this.createExplosion((int)var1.x, (int)var1.y, 20);
- this.incrementScore(75);
- }
-
- void createMRV(int var1) {
- int var2 = (int)(Math.random() * (double)500.0F);
- byte var3 = 1;
- short var4 = 299;
- this.mrvs.addElement(new MRV(var2, var3, var4, var1, this.mrvImage, this));
- }
-
- void destroyMRV(MRV var1) {
- if (this.soundEnabled && this.mrvExplosionSound != null && this.playing) {
- this.mrvExplosionSound.play();
- }
-
- ((GameObject)var1).explode();
- this.createExplosion(var1.x, var1.y, 10);
- this.incrementScore(150);
- }
-
- void createBomb(int var1) {
- if (this.soundEnabled && this.bombSound != null && this.playing) {
- this.bombSound.play();
- }
-
- int var2 = (int)(Math.random() * (double)500.0F);
- byte var3 = 1;
- short var4 = 299;
- this.bombs.addElement(new Bomb(var2, var3, var2, var4, var1, this.bombImage, this));
- }
-
- void destroyBomb(Bomb var1) {
- ((GameObject)var1).explode();
- this.createBombDebris(var1.x, var1.y);
- }
-
- void createBombDebris(int var1, int var2) {
- this.bombDebris.addElement(new BombDebris(var1, var2, 200));
- }
-
- void createBases() {
- this.bases = new Vector(5);
- int var1 = 0;
-
- for(int var2 = 30; var1 < 5; ++var1) {
- this.bases.addElement(new Base(var2, 268, 64, 32, this.baseImage, this));
- var2 += 94;
- }
-
- }
-
- int countAliveBases() {
- int var1 = 0;
-
- for(int var2 = 0; var2 < 5; ++var2) {
- Base var3 = (Base)this.bases.elementAt(var2);
- if (((GameObject)var3).alive()) {
- ++var1;
- }
- }
-
- return var1;
- }
-
- void destroyBase(Base var1, Missile var2) {
- if (this.soundEnabled && this.baseExplosionSound != null && this.playing) {
- this.baseExplosionSound.play();
- }
-
- ((GameObject)var2).explode();
- ((GameObject)var1).explode();
- this.createExplosion((int)var2.x, (int)var2.y, 100);
- }
-
- void destroyBase(Base var1, MRV var2) {
- if (this.soundEnabled && this.baseExplosionSound != null && this.playing) {
- this.baseExplosionSound.play();
- }
-
- ((GameObject)var2).explode();
- ((GameObject)var1).explode();
- this.createExplosion(var2.x, var2.y, 100);
- }
-
- void destroyBase(Base var1, BombDebris var2) {
- if (this.soundEnabled && this.baseExplosionSound != null && this.playing) {
- this.baseExplosionSound.play();
- }
-
- ((GameObject)var1).explode();
- this.createExplosion(var1.x + var1.w / 2, var1.y + var1.h / 2, 100);
- }
-
- void rebuildBases() {
- int[] var1 = new int[5];
-
- for(int var2 = 0; var2 < var1.length; ++var2) {
- var1[var2] = -1;
- }
-
- int var3;
- for(int var4 = 0; var4 < 5; var1[var3] = var4++) {
- var3 = (int)(Math.random() * (double)5.0F);
-
- while(var1[var3] != -1) {
- ++var3;
- if (var3 == 5) {
- var3 = 0;
- }
- }
- }
-
- for(int var5 = 0; var5 < 5; ++var5) {
- Base var6 = (Base)this.bases.elementAt(var1[var5]);
- if (!((GameObject)var6).alive() && this.extraBaseScore >= 10000) {
- this.extraBaseScore -= 10000;
- var6.rebuild();
- }
- }
-
- }
-
- void createExplosion(int var1, int var2, int var3) {
- this.explosions.addElement(new Explosion(var1, var2, var3));
- }
-
- void incrementScore(int var1) {
- if (this.playing) {
- this.score += var1;
- this.extraBaseScore += var1;
- }
-
- }
-
- void destroyWorld() {
- for(int var1 = 0; var1 < 10; ++var1) {
- int var2 = (int)(Math.random() * (double)500.0F);
- int var3 = (int)(Math.random() * (double)300.0F);
- this.createExplosion(var2, var3, 100);
- }
-
- }
-
- public void update(Graphics var1) {
- this.paint(var1);
- }
-
- void paintGameObjects(Vector var1, Graphics var2) {
- if (var1 != null) {
- Enumeration var3 = var1.elements();
-
- while(var3.hasMoreElements()) {
- GameObject var4 = (GameObject)var3.nextElement();
- var4.paint(var2);
- }
-
- }
- }
-
- void message(String var1) {
- if (var1 != null) {
- this.screenMessage = var1;
- } else {
- this.screenMessage = null;
- this.clearScreen = true;
- }
-
- ((Component)this).repaint();
- }
-
- void paintMessage(String var1, Graphics var2) {
- this.fontMetrics.getHeight();
- int var3 = this.fontMetrics.stringWidth(var1);
- var2.setColor(Color.black);
- var2.drawString(var1, 250 - var3 / 2, 150);
- }
-
- void paintStatus(Graphics var1) {
- StringBuffer var2 = new StringBuffer();
- var2.append("Score: ");
- var2.append(this.score);
- var2.append(" Level: ");
- var2.append(this.level);
- var2.append(" Shots: ");
- var2.append(this.shotCount);
- int var3 = this.fontMetrics.getHeight();
- int var4 = this.fontMetrics.stringWidth(var2.toString());
- int var5 = 250 - var4 / 2;
- var1.setColor(Color.white);
- var1.fillRect(0, 0, 500, 25);
- var1.setColor(Color.black);
- var1.drawString(var2.toString(), var5, var3);
- var4 = this.fontMetrics.stringWidth("MCII 1.1");
- var1.drawString("MCII 1.1", 500 - var4, var3);
- }
-
- public void paint(Graphics var1) {
- if (this.world == null) {
- this.world = var1.create(0, 25, 500, 300);
- }
-
- if (this.clearScreen) {
- var1.setColor(Color.white);
- var1.fillRect(0, 0, 500, 300);
- this.world.setColor(this.skyColor);
- this.world.fillRect(0, 0, 500, 300);
- this.clearScreen = false;
- }
-
- if (this.paused) {
- this.paintMessage("PAUSED", this.world);
- } else {
- this.paintStatus(var1);
- this.paintGameObjects(this.mrvs, this.world);
- this.paintGameObjects(this.missiles, this.world);
- this.paintGameObjects(this.bombs, this.world);
- this.paintGameObjects(this.bases, this.world);
- this.paintGameObjects(this.shots, this.world);
- this.paintGameObjects(this.explosions, this.world);
- this.paintGameObjects(this.bombDebris, this.world);
- if (!this.playing) {
- this.paintMessage("GAME OVER", this.world);
- } else {
- if (this.screenMessage != null) {
- this.paintMessage(this.screenMessage, this.world);
- }
-
- }
- }
- }
- }
-