old-java-games

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit be102abf63d0616bd23a64df5f974d89800d303e
parent 25c3d018051bd7de06e582d1633ee4a8e753eaaf
Author: mpizzzle <michael.770211@gmail.com>
Date:   Sat,  2 Mar 2019 12:01:55 +0000

moved Link assets

Diffstat:
M.gitignore | 2+-
DCaveGame.html | 8--------
MCaveGame/src/Bridge.java | 28+++++++++++++++-------------
MCaveGame/src/Cave2.java | 28+++++++++++++++-------------
MCaveGame/src/CaveArea.java | 156+++++++++++++++++++++++++++++++++++++++++--------------------------------------
MCaveGame/src/CaveGame.java | 86++++++++++++++++++++++++++++++++++++-------------------------------------------
MCaveGame/src/Cavern.java | 28+++++++++++++++-------------
MCaveGame/src/FirstCave.java | 28+++++++++++++++-------------
MCaveGame/src/FirstRoom.java | 22++++++++++++----------
MCaveGame/src/Hole.java | 28+++++++++++++++-------------
MCaveGame/src/HotRoom.java | 28+++++++++++++++-------------
MCaveGame/src/LeftDoor.java | 26++++++++++++++------------
MCaveGame/src/River.java | 28+++++++++++++++-------------
MCaveGame/src/Rope.java | 28+++++++++++++++-------------
MCaveGame/src/WayOut.java | 28+++++++++++++++-------------
DLink.html | 8--------
RLink/bigboss1.1.gif -> Link/Assets/bigboss1.1.gif | 0
RLink/bigboss1.2.gif -> Link/Assets/bigboss1.2.gif | 0
RLink/bigboss1.3.gif -> Link/Assets/bigboss1.3.gif | 0
RLink/blob.gif -> Link/Assets/blob.gif | 0
RLink/bluegem.gif -> Link/Assets/bluegem.gif | 0
RLink/boss1.1.gif -> Link/Assets/boss1.1.gif | 0
RLink/boss1.2.gif -> Link/Assets/boss1.2.gif | 0
RLink/boss1.3.gif -> Link/Assets/boss1.3.gif | 0
RLink/gemstand(with gems).gif -> Link/Assets/gemstand(with gems).gif | 0
RLink/gemstand(without gems).gif -> Link/Assets/gemstand(without gems).gif | 0
RLink/goldskullata.gif -> Link/Assets/goldskullata.gif | 0
RLink/greengem.gif -> Link/Assets/greengem.gif | 0
RLink/link atack left.gif -> Link/Assets/link atack left.gif | 0
RLink/link atack left2.gif -> Link/Assets/link atack left2.gif | 0
RLink/link atack right.gif -> Link/Assets/link atack right.gif | 0
RLink/link atack right2.gif -> Link/Assets/link atack right2.gif | 0
RLink/link jump left.gif -> Link/Assets/link jump left.gif | 0
RLink/link jump right.gif -> Link/Assets/link jump right.gif | 0
RLink/link shield left2.gif -> Link/Assets/link shield left2.gif | 0
RLink/link shield right2.gif -> Link/Assets/link shield right2.gif | 0
RLink/link slash left 1.gif -> Link/Assets/link slash left 1.gif | 0
RLink/link slash left2.gif -> Link/Assets/link slash left2.gif | 0
RLink/link slash left3.gif -> Link/Assets/link slash left3.gif | 0
RLink/link slash left4.gif -> Link/Assets/link slash left4.gif | 0
RLink/link slash left5.gif -> Link/Assets/link slash left5.gif | 0
RLink/link slash right 1.gif -> Link/Assets/link slash right 1.gif | 0
RLink/link slash right2.gif -> Link/Assets/link slash right2.gif | 0
RLink/link slash right3.gif -> Link/Assets/link slash right3.gif | 0
RLink/link slash right4.gif -> Link/Assets/link slash right4.gif | 0
RLink/link slash right5.gif -> Link/Assets/link slash right5.gif | 0
RLink/link.ico -> Link/Assets/link.ico | 0
RLink/linkcrouchright.gif -> Link/Assets/linkcrouchright.gif | 0
RLink/linkshieldleft.gif -> Link/Assets/linkshieldleft.gif | 0
RLink/linkshieldleft2.gif -> Link/Assets/linkshieldleft2.gif | 0
RLink/linkshieldright.gif -> Link/Assets/linkshieldright.gif | 0
RLink/linkshieldright2.gif -> Link/Assets/linkshieldright2.gif | 0
RLink/linkstandleft.gif -> Link/Assets/linkstandleft.gif | 0
RLink/linkstandleft2.gif -> Link/Assets/linkstandleft2.gif | 0
RLink/linkstandright.gif -> Link/Assets/linkstandright.gif | 0
RLink/linkstandright2.gif -> Link/Assets/linkstandright2.gif | 0
RLink/linksworddown.gif -> Link/Assets/linksworddown.gif | 0
RLink/linkswordleft.gif -> Link/Assets/linkswordleft.gif | 0
RLink/linkswordleft2.gif -> Link/Assets/linkswordleft2.gif | 0
RLink/linkswordright.gif -> Link/Assets/linkswordright.gif | 0
RLink/linkswordright2.gif -> Link/Assets/linkswordright2.gif | 0
RLink/madblob.gif -> Link/Assets/madblob.gif | 0
RLink/metor.gif -> Link/Assets/metor.gif | 0
RLink/octo.gif -> Link/Assets/octo.gif | 0
RLink/octopellets.gif -> Link/Assets/octopellets.gif | 0
RLink/princess Zelda.gif -> Link/Assets/princess Zelda.gif | 0
RLink/redgem.gif -> Link/Assets/redgem.gif | 0
RLink/rock.gif -> Link/Assets/rock.gif | 0
RLink/spider.gif -> Link/Assets/spider.gif | 0
RLink/yellowgem.gif -> Link/Assets/yellowgem.gif | 0
DLink/LinkArea.java | 145-------------------------------------------------------------------------------
DLink/LinkFrame.java | 11-----------
DLink/LinkGame.java | 544-------------------------------------------------------------------------------
ALink/src/LinkArea.java | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ALink/src/LinkGame.java | 545+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DMario.html | 8--------
DPong.html | 8--------
MPong/src/PongGame.java | 2+-
DReaper.html | 8--------
DTank.html | 8--------
DZombies.html | 8--------
Dautogen_Reaper.html | 8--------
Dautogen_asteroids.html | 8--------
83 files changed, 971 insertions(+), 1035 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -9,4 +9,4 @@ resource.h thumbs.db CaveGame/mp3s/ #java.policy.applet -/.metadata/* +/.metadata/ diff --git a/CaveGame.html b/CaveGame.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Cave Game</TITLE> -</HEAD> -<BODY> -<APPLET CODE="CaveGame.CaveGame.class" WIDTH=800 HEIGHT=600 X=200 Y=0></APPLET> -</BODY> -</HTML> diff --git a/CaveGame/src/Bridge.java b/CaveGame/src/Bridge.java @@ -1,33 +1,35 @@ public class Bridge implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public Bridge (CaveGame parent, CaveArea area) { + + public Bridge(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.bridge; - myParent.showStatus("On the Bridge"); - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACbridge; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); + System.out.println("On the Bridge"); + /* + * if (myarea.currentmusic != null) myarea.currentmusic.stop(); + * myarea.currentmusic = myarea.acbridge; if (myarea.currentmusic != null) + * myarea.currentmusic.loop(); + */ myArea.repaint(); } - + public CaveInterface processA() { // do nothing - return(this); + return (this); } - + public CaveInterface processB() { // do nothing - return(this); + return (this); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/Cave2.java b/CaveGame/src/Cave2.java @@ -1,33 +1,35 @@ public class Cave2 implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public Cave2 (CaveGame parent, CaveArea area) { + + public Cave2(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.secondCave; - myParent.showStatus("In the second Cave"); - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACsecondCave; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); + System.out.println("In the second Cave"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACsecondCave; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ myArea.repaint(); } - + public CaveInterface processA() { // do nothing - return(this); + return (this); } - + public CaveInterface processB() { // do nothing - return(this); + return (this); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/CaveArea.java b/CaveGame/src/CaveArea.java @@ -1,103 +1,109 @@ import java.awt.*; -import java.applet.AudioClip; -import java.net.*; +import java.io.File; +import java.io.IOException; +//import java.applet.AudioClip; -public class CaveArea extends Panel { - +import javax.imageio.ImageIO; +import javax.swing.JPanel; + +public class CaveArea extends JPanel { + private static final long serialVersionUID = -7163898717940240890L; CaveGame myApplet = null; Image title[] = new Image[10]; - MediaTracker mt=null; + MediaTracker mt = null; Image firstRoom, leftDoor, firstCave; Image river, bridge; Image cavern, hole, rope; Image hotRoom, secondCave, gameComplete; Image currentImage; - - AudioClip ACfirstRoom, ACleftDoor, ACfirstCave; - AudioClip ACriver, ACbridge; - AudioClip ACcavern, AChole, ACrope; - AudioClip AChotRoom, ACsecondCave, ACgameComplete; - AudioClip currentMusic; - + + /* + * AudioClip ACfirstRoom, ACleftDoor, ACfirstCave; AudioClip ACriver, ACbridge; + * AudioClip ACcavern, AChole, ACrope; AudioClip AChotRoom, ACsecondCave, + * ACgameComplete; AudioClip currentMusic; + */ public CaveArea(CaveGame parent) { - mt=new MediaTracker(parent); + mt = new MediaTracker(parent); myApplet = parent; - - firstRoom = load(parent, "1ST ROOM.gif"); - leftDoor = load(parent, "GAMER PICKS A.gif"); - firstCave = load(parent, "GAMER PICKS C.gif"); - river = load(parent, "GAMER PICKS B.gif"); - bridge = load(parent, "GAMER PICKS B THEN A.gif"); - cavern = load(parent, "GAMER PICKS B THEN B.gif"); - hole = load(parent, "GAMER PICKS B THEN B THEN B.gif"); - rope = load(parent, "GAMER PICKS B THEN B THEN C.gif"); - hotRoom = load(parent, "GAMER PICKS B THEN B THEN A.gif"); - secondCave = load(parent, "GAMER PICKS B THEN B THEN A THEN B.gif"); - gameComplete = load(parent, "GAME COMPLETE.gif"); - - ACfirstRoom = loadSound(parent, "The Prophecy.mp3"); - ACleftDoor = loadSound(parent, "The Black Rider.mp3"); - ACfirstCave = loadSound(parent, "The Shadow of the Past.mp3"); - ACriver = loadSound(parent, "The Great River.mp3"); - ACbridge = loadSound(parent, "Flight to the Ford.mp3"); - ACcavern = loadSound(parent, "A Journey in the Dark.mp3"); - AChole = loadSound(parent, "A Knife in the Dark.mp3"); - ACrope = loadSound(parent, "Amon Hen.mp3"); - AChotRoom = loadSound(parent, "The Bridge of Khazad Dhum.mp3"); - ACsecondCave = loadSound(parent, "The Treason of Isengard.mp3"); - ACgameComplete = loadSound(parent, "Concerning Hobbits.mp3"); - - } - - Image load(CaveGame parent, String picture) { - Image im = parent.getImage(myApplet.getCodeBase(), "CaveGame\\" + picture); - checkImage(im, picture); - return(im); - } - - AudioClip loadSound(CaveGame parent, String soundfile) { - AudioClip s = null; - s = parent.getAudioClip(myApplet.getCodeBase(), "CaveGame\\"+soundfile); - checkAudio(s, soundfile); - return (s); + + firstRoom = load(parent, "1ST ROOM.gif"); + leftDoor = load(parent, "GAMER PICKS A.gif"); + firstCave = load(parent, "GAMER PICKS C.gif"); + river = load(parent, "GAMER PICKS B.gif"); + bridge = load(parent, "GAMER PICKS B THEN A.gif"); + cavern = load(parent, "GAMER PICKS B THEN B.gif"); + hole = load(parent, "GAMER PICKS B THEN B THEN B.gif"); + rope = load(parent, "GAMER PICKS B THEN B THEN C.gif"); + hotRoom = load(parent, "GAMER PICKS B THEN B THEN A.gif"); + secondCave = load(parent, "GAMER PICKS B THEN B THEN A THEN B.gif"); + gameComplete = load(parent, "GAME COMPLETE.gif"); + + /* + * ACfirstRoom = loadSound(parent, "The Prophecy.mp3"); ACleftDoor = + * loadSound(parent, "The Black Rider.mp3"); ACfirstCave = loadSound(parent, + * "The Shadow of the Past.mp3"); ACriver = loadSound(parent, + * "The Great River.mp3"); ACbridge = loadSound(parent, + * "Flight to the Ford.mp3"); ACcavern = loadSound(parent, + * "A Journey in the Dark.mp3"); AChole = loadSound(parent, + * "A Knife in the Dark.mp3"); ACrope = loadSound(parent, "Amon Hen.mp3"); + * AChotRoom = loadSound(parent, "The Bridge of Khazad Dhum.mp3"); ACsecondCave + * = loadSound(parent, "The Treason of Isengard.mp3"); ACgameComplete = + * loadSound(parent, "Concerning Hobbits.mp3"); + */ } - - void checkAudio(AudioClip ac, String name) { - if (ac == null) System.out.println("Audio Clip Not found: "+name.toString()); + + Image load(CaveGame parent, String picture) { + try { + Image im = ImageIO.read(new File("../Assets/" + picture)); + checkImage(im, picture); + return (im); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; } - + + /* + * AudioClip loadSound(CaveGame parent, String soundfile) { AudioClip s = null; + * s = parent.getAudioClip(myApplet.getCodeBase(), "CaveGame\\" + soundfile); + * checkAudio(s, soundfile); return (s); } + * + * void checkAudio(AudioClip ac, String name) { if (ac == null) + * System.out.println("Audio Clip Not found: " + name.toString()); } + */ void checkImage(Image image, String name) { if (mt != null) { - mt.addImage(image,0); + mt.addImage(image, 0); try { - mt.waitForID(0,5000); - } - catch (InterruptedException ie) { + mt.waitForID(0, 5000); + } catch (InterruptedException ie) { // nothing to do } - if (mt.isErrorID(0)) System.out.println("Image Not found: "+name.toString()); + if (mt.isErrorID(0)) + System.out.println("Image Not found: " + name.toString()); } } - - public synchronized void paint (Graphics g) { - if (myApplet == null) return; - final int w = getBounds().width; - final int h = getBounds().height; + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + + if (myApplet == null) + return; + g.setColor(Color.white); - FontMetrics fm = getFontMetrics(getFont()); - g.setColor(Color.black); - int asc = fm.getAscent() + 4; - - g.drawImage(currentImage, 0, 0,Color.white, null); - + g.drawImage(currentImage, 0, 0, Color.white, null); } - + public void showTitle(Graphics g) { for (int i = 0; i < 10; i++) { - g.drawImage(title[i], myApplet.getBounds().width/2, getBounds().height/2,Color.white, null); - try {Thread.sleep(50);} - catch (Exception e) {} + g.drawImage(title[i], myApplet.getBounds().width / 2, getBounds().height / 2, Color.white, null); + try { + Thread.sleep(50); + } catch (Exception e) { + } } } diff --git a/CaveGame/src/CaveGame.java b/CaveGame/src/CaveGame.java @@ -1,83 +1,75 @@ +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.JPanel; + //* Copyright (c) Mary Percival 2003 */ /* CaveGame game Created December 2003 */ -import java.awt.*; -import java.awt.event.*; -import java.applet.*; - -public class CaveGame extends JPanel implements KeyListener { - - static boolean finished = false; - CaveArea area; +public class CaveGame extends JPanel implements KeyListener, Runnable { + private static final long serialVersionUID = -4869537669824700402L; + private static CaveArea area; CaveInterface currentCavern; - + // ************************************************************* - public void init() { + public static void main(String[] args) { + CaveGame caveGame = new CaveGame(); - setLayout(null); - setBackground(Color.white); + caveGame.setLayout(null); + caveGame.setBackground(Color.white); + + area = new CaveArea(caveGame); + caveGame.add(area); - area = new CaveArea(this); - add(area); - - FontMetrics fm = getFontMetrics(getFont()); area.setVisible(true); - area.setBounds(0,0,getBounds().width,getBounds().height); + area.setBounds(0, 0, caveGame.getBounds().width, caveGame.getBounds().height); + area.setBounds(0, 0, 1000, 1000); - addKeyListener(this); - area.addKeyListener(this); + caveGame.addKeyListener(caveGame); + area.addKeyListener(caveGame); area.requestFocus(); - start(); - } - + caveGame.start(); + EventQueue.invokeLater(caveGame); + } + public void start() { currentCavern = new FirstRoom(this, area); currentCavern.display(); area.repaint(); - showStatus("CaveGame Started"); + System.out.println("CaveGame Started"); } - - public void finished() { - finished = true; - System.exit(0); - } - - public String getAppletInfo() { - return ("CaveGame Game"); - } - + // this class will use just the key pressed event public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_A) { currentCavern = currentCavern.processA(); currentCavern.display(); area.repaint(); - } - else if (e.getKeyCode() == KeyEvent.VK_B) { + } else if (e.getKeyCode() == KeyEvent.VK_B) { currentCavern = currentCavern.processB(); currentCavern.display(); area.repaint(); - } - else if (e.getKeyCode() == KeyEvent.VK_C) { + } else if (e.getKeyCode() == KeyEvent.VK_C) { currentCavern = currentCavern.processC(); currentCavern.display(); area.repaint(); - } - else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { start(); area.repaint(); } } - - synchronized void die() { - showStatus("The Player is dead. Press the Enter key to restart"); - finished = true; - } - + public void keyReleased(KeyEvent e) { } - + public void keyTyped(KeyEvent e) { } - + + @Override + public void run() { + // TODO Auto-generated method stub + + } } \ No newline at end of file diff --git a/CaveGame/src/Cavern.java b/CaveGame/src/Cavern.java @@ -1,30 +1,32 @@ public class Cavern implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public Cavern (CaveGame parent, CaveArea area) { + + public Cavern(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.cavern; - myParent.showStatus("In the Cavern"); - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACcavern; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); + System.out.println("In the Cavern"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACcavern; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ myArea.repaint(); } - + public CaveInterface processA() { - return(new HotRoom(myParent, myArea)); + return (new HotRoom(myParent, myArea)); } - + public CaveInterface processB() { - return(new Hole(myParent, myArea)); + return (new Hole(myParent, myArea)); } - + public CaveInterface processC() { - return(new Rope(myParent, myArea)); + return (new Rope(myParent, myArea)); } } \ No newline at end of file diff --git a/CaveGame/src/FirstCave.java b/CaveGame/src/FirstCave.java @@ -1,33 +1,35 @@ public class FirstCave implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public FirstCave (CaveGame parent, CaveArea area) { + + public FirstCave(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.firstCave; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACfirstCave; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("In the First Cave"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACfirstCave; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("In the First Cave"); myArea.repaint(); } - + public CaveInterface processA() { // do nothing - return(this); + return (this); } - + public CaveInterface processB() { // do nothing - return(this); + return (this); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/FirstRoom.java b/CaveGame/src/FirstRoom.java @@ -1,29 +1,31 @@ -public class FirstRoom implements CaveInterface{ +public class FirstRoom implements CaveInterface { CaveGame myParent; CaveArea myArea; - + public FirstRoom(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.firstRoom; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACfirstRoom; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("Just Inside the Entrance"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACfirstRoom; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("Just Inside the Entrance"); myArea.repaint(); } - + public CaveInterface processA() { return new LeftDoor(myParent, myArea); } - + public CaveInterface processB() { return new River(myParent, myArea); } - + public CaveInterface processC() { return new FirstCave(myParent, myArea); } diff --git a/CaveGame/src/Hole.java b/CaveGame/src/Hole.java @@ -1,33 +1,35 @@ public class Hole implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public Hole (CaveGame parent, CaveArea area) { + + public Hole(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.hole; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.AChole; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("In the Hole"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.AChole; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("In the Hole"); myArea.repaint(); } - + public CaveInterface processA() { // do nothing - return(this); + return (this); } - + public CaveInterface processB() { // do nothing - return(this); + return (this); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/HotRoom.java b/CaveGame/src/HotRoom.java @@ -1,31 +1,33 @@ public class HotRoom implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public HotRoom (CaveGame parent, CaveArea area) { + + public HotRoom(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.hotRoom; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.AChotRoom; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("In the Hot Room"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.AChotRoom; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("In the Hot Room"); myArea.repaint(); } - + public CaveInterface processA() { - return(new WayOut(myParent, myArea)); + return (new WayOut(myParent, myArea)); } - + public CaveInterface processB() { - return(new Cave2(myParent, myArea)); + return (new Cave2(myParent, myArea)); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/LeftDoor.java b/CaveGame/src/LeftDoor.java @@ -1,33 +1,35 @@ public class LeftDoor implements CaveInterface { CaveGame myParent; CaveArea myArea; - + public LeftDoor(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.leftDoor; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACleftDoor; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("Through the Left Door"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACleftDoor; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("Through the Left Door"); myArea.repaint(); } - + public CaveInterface processA() { // do nothing - return(this); + return (this); } - + public CaveInterface processB() { // do nothing - return(this); + return (this); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/River.java b/CaveGame/src/River.java @@ -1,31 +1,33 @@ public class River implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public River (CaveGame parent, CaveArea area) { + + public River(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.river; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACriver; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("By the River"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACriver; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("By the River"); myArea.repaint(); } - + public CaveInterface processA() { - return(new Bridge(myParent, myArea)); + return (new Bridge(myParent, myArea)); } - + public CaveInterface processB() { - return(new Cavern(myParent, myArea)); + return (new Cavern(myParent, myArea)); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/Rope.java b/CaveGame/src/Rope.java @@ -1,33 +1,35 @@ public class Rope implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public Rope (CaveGame parent, CaveArea area) { + + public Rope(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.rope; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACrope; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("Down the Rope"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACrope; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("Down the Rope"); myArea.repaint(); } - + public CaveInterface processA() { // do nothing - return(this); + return (this); } - + public CaveInterface processB() { // do nothing - return(this); + return (this); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/CaveGame/src/WayOut.java b/CaveGame/src/WayOut.java @@ -1,33 +1,35 @@ public class WayOut implements CaveInterface { CaveGame myParent; CaveArea myArea; - - public WayOut (CaveGame parent, CaveArea area) { + + public WayOut(CaveGame parent, CaveArea area) { myParent = parent; myArea = area; } - + public void display() { myArea.currentImage = myArea.gameComplete; - if (myArea.currentMusic != null) myArea.currentMusic.stop(); - myArea.currentMusic = myArea.ACgameComplete; - if (myArea.currentMusic != null) myArea.currentMusic.loop(); - myParent.showStatus("At the Exit"); + /* + * if (myArea.currentMusic != null) myArea.currentMusic.stop(); + * myArea.currentMusic = myArea.ACgameComplete; if (myArea.currentMusic != null) + * myArea.currentMusic.loop(); + */ + System.out.println("At the Exit"); myArea.repaint(); } - + public CaveInterface processA() { // do nothing - return(this); + return (this); } - + public CaveInterface processB() { // do nothing - return(this); + return (this); } - + public CaveInterface processC() { // do nothing - return(this); + return (this); } } \ No newline at end of file diff --git a/Link.html b/Link.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>The Adventures of Link</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Link.LinkGame.class" WIDTH=800 HEIGHT=600 X=200 Y=0></APPLET> -</BODY> -</HTML> diff --git a/Link/bigboss1.1.gif b/Link/Assets/bigboss1.1.gif Binary files differ. diff --git a/Link/bigboss1.2.gif b/Link/Assets/bigboss1.2.gif Binary files differ. diff --git a/Link/bigboss1.3.gif b/Link/Assets/bigboss1.3.gif Binary files differ. diff --git a/Link/blob.gif b/Link/Assets/blob.gif Binary files differ. diff --git a/Link/bluegem.gif b/Link/Assets/bluegem.gif Binary files differ. diff --git a/Link/boss1.1.gif b/Link/Assets/boss1.1.gif Binary files differ. diff --git a/Link/boss1.2.gif b/Link/Assets/boss1.2.gif Binary files differ. diff --git a/Link/boss1.3.gif b/Link/Assets/boss1.3.gif Binary files differ. diff --git a/Link/gemstand(with gems).gif b/Link/Assets/gemstand(with gems).gif Binary files differ. diff --git a/Link/gemstand(without gems).gif b/Link/Assets/gemstand(without gems).gif Binary files differ. diff --git a/Link/goldskullata.gif b/Link/Assets/goldskullata.gif Binary files differ. diff --git a/Link/greengem.gif b/Link/Assets/greengem.gif Binary files differ. diff --git a/Link/link atack left.gif b/Link/Assets/link atack left.gif Binary files differ. diff --git a/Link/link atack left2.gif b/Link/Assets/link atack left2.gif Binary files differ. diff --git a/Link/link atack right.gif b/Link/Assets/link atack right.gif Binary files differ. diff --git a/Link/link atack right2.gif b/Link/Assets/link atack right2.gif Binary files differ. diff --git a/Link/link jump left.gif b/Link/Assets/link jump left.gif Binary files differ. diff --git a/Link/link jump right.gif b/Link/Assets/link jump right.gif Binary files differ. diff --git a/Link/link shield left2.gif b/Link/Assets/link shield left2.gif Binary files differ. diff --git a/Link/link shield right2.gif b/Link/Assets/link shield right2.gif Binary files differ. diff --git a/Link/link slash left 1.gif b/Link/Assets/link slash left 1.gif Binary files differ. diff --git a/Link/link slash left2.gif b/Link/Assets/link slash left2.gif Binary files differ. diff --git a/Link/link slash left3.gif b/Link/Assets/link slash left3.gif Binary files differ. diff --git a/Link/link slash left4.gif b/Link/Assets/link slash left4.gif Binary files differ. diff --git a/Link/link slash left5.gif b/Link/Assets/link slash left5.gif Binary files differ. diff --git a/Link/link slash right 1.gif b/Link/Assets/link slash right 1.gif Binary files differ. diff --git a/Link/link slash right2.gif b/Link/Assets/link slash right2.gif Binary files differ. diff --git a/Link/link slash right3.gif b/Link/Assets/link slash right3.gif Binary files differ. diff --git a/Link/link slash right4.gif b/Link/Assets/link slash right4.gif Binary files differ. diff --git a/Link/link slash right5.gif b/Link/Assets/link slash right5.gif Binary files differ. diff --git a/Link/link.ico b/Link/Assets/link.ico Binary files differ. diff --git a/Link/linkcrouchright.gif b/Link/Assets/linkcrouchright.gif Binary files differ. diff --git a/Link/linkshieldleft.gif b/Link/Assets/linkshieldleft.gif Binary files differ. diff --git a/Link/linkshieldleft2.gif b/Link/Assets/linkshieldleft2.gif Binary files differ. diff --git a/Link/linkshieldright.gif b/Link/Assets/linkshieldright.gif Binary files differ. diff --git a/Link/linkshieldright2.gif b/Link/Assets/linkshieldright2.gif Binary files differ. diff --git a/Link/linkstandleft.gif b/Link/Assets/linkstandleft.gif Binary files differ. diff --git a/Link/linkstandleft2.gif b/Link/Assets/linkstandleft2.gif Binary files differ. diff --git a/Link/linkstandright.gif b/Link/Assets/linkstandright.gif Binary files differ. diff --git a/Link/linkstandright2.gif b/Link/Assets/linkstandright2.gif Binary files differ. diff --git a/Link/linksworddown.gif b/Link/Assets/linksworddown.gif Binary files differ. diff --git a/Link/linkswordleft.gif b/Link/Assets/linkswordleft.gif Binary files differ. diff --git a/Link/linkswordleft2.gif b/Link/Assets/linkswordleft2.gif Binary files differ. diff --git a/Link/linkswordright.gif b/Link/Assets/linkswordright.gif Binary files differ. diff --git a/Link/linkswordright2.gif b/Link/Assets/linkswordright2.gif Binary files differ. diff --git a/Link/madblob.gif b/Link/Assets/madblob.gif Binary files differ. diff --git a/Link/metor.gif b/Link/Assets/metor.gif Binary files differ. diff --git a/Link/octo.gif b/Link/Assets/octo.gif Binary files differ. diff --git a/Link/octopellets.gif b/Link/Assets/octopellets.gif Binary files differ. diff --git a/Link/princess Zelda.gif b/Link/Assets/princess Zelda.gif Binary files differ. diff --git a/Link/redgem.gif b/Link/Assets/redgem.gif Binary files differ. diff --git a/Link/rock.gif b/Link/Assets/rock.gif Binary files differ. diff --git a/Link/spider.gif b/Link/Assets/spider.gif Binary files differ. diff --git a/Link/yellowgem.gif b/Link/Assets/yellowgem.gif Binary files differ. diff --git a/Link/LinkArea.java b/Link/LinkArea.java @@ -1,144 +0,0 @@ -package Link; - -import java.awt.*; - -public class LinkArea extends Panel { - - static final int FLOORLEVEL = 587; - static final int FLOORWIDTH = 150; - LinkGame myApplet = null; - Image yellowgem; - Image spider; - Image obstacle; - Image redgem; - Image octopellets; - Image octo; - Image madblob; - Image heroswordright; - Image heroswordleft; - Image herostand; - Image hero1; - Image hero2; - Image herostandleft; - Image hero1left; - Image hero2left; - Image heroshieldright; - Image heroshieldleft; - Image greengem; - Image bluegem; - Image goldskullata; - Image gemstandgems; - Image gemstandempty; - Image blob; - MediaTracker mt=null; - - public LinkArea(LinkGame parent) { - mt=new MediaTracker(parent); - myApplet = parent; - yellowgem = load(myApplet, "yellowgem.gif"); - spider = load(myApplet, "spider.gif"); - obstacle = load(myApplet, "rock.gif"); - redgem = load(myApplet, "redgem.gif"); - octopellets = load(myApplet, "octopellets.gif"); - octo = load(myApplet, "octo.gif"); - madblob = load(myApplet, "madblob.gif"); - heroswordright = load(myApplet, "linkswordright.gif"); - heroswordleft = load(myApplet, "linkswordleft.gif"); - herostand = load(myApplet, "linkstandright.gif"); - hero1 = load(myApplet, "linkstandright.gif"); - hero2 = load(myApplet, "linkstandright2.gif"); - herostandleft = load(myApplet, "linkstandleft.gif"); - hero1left = load(myApplet, "linkstandleft.gif"); - hero2left = load(myApplet, "linkstandleft2.gif"); - heroshieldright = load(myApplet, "linkshieldright.gif"); - heroshieldleft = load(myApplet, "linkshieldleft.gif"); - greengem = load(myApplet, "greengem.gif"); - bluegem = load(myApplet, "bluegem.gif"); - goldskullata = load(myApplet, "goldskullata.gif"); - gemstandgems = load(myApplet, "gemstand(with gems).gif"); - gemstandempty = load(myApplet, "gemstand(without gems).gif"); - blob = load(myApplet, "blob.gif"); - } - void checkImage(Image image, String name) { - if (mt != null) { - mt.addImage(image,0); - try { - mt.waitForID(0,5000); - } - catch (InterruptedException ie) { - // nothing to do - } - if (mt.isErrorID(0)) System.out.println("Image Not found: "+name.toString()); - } - } - - Image load(LinkGame parent, String picture) { - Image im = parent.getImage(myApplet.getCodeBase(), "Link\\" + picture); - checkImage(im, picture); - return(im); - } - - public synchronized void paint (Graphics g) { - Image obstacleimage; - if (myApplet == null) return; - final int w = getBounds().width; - final int h = getBounds().height; - g.setColor(Color.white); - g.fillRect(0, 0, w, h); - FontMetrics fm = getFontMetrics(getFont()); - - g.setColor(Color.black); - int asc = fm.getAscent() + 4; - /* - // paint the floor - for (int pos=0; pos < w; pos+=FLOORWIDTH) { - g.drawImage(floor,pos, FLOORLEVEL,Color.black, null); - } - */ - - if (myApplet.obstaclePositions != null) { - // show the obstacles - for (int i=0; i < myApplet.obstaclePositions.length; i++) { - obstacleimage = myApplet.getObstacleImage(i); - g.drawImage(obstacleimage, myApplet.obstaclePositions[myApplet.level-1][i].x, myApplet.obstaclePositions[myApplet.level-1][i].y-4,Color.white, null); - } - } - - /* - // show the enemies - for (int i=0; i < myApplet.enemyPositions.length; i++) { - if (myApplet.enemyPositions[i].x > -1) - g.drawImage(enemyImage, myApplet.enemyPositions[i].x, myApplet.enemyPositions[i].y,null); - } - } - */ - // draw Hero (on top of preceding images) - if (myApplet.playerPosition != null) { - // show the player - Image herosimage = myApplet.getHeroImage(); - /* - if (myApplet.herocrouching) { - if (myApplet.heroleft) - herosimage = herocrouchleft; - else - herosimage = herocrouch; - } - if (myApplet.jumping) { - if (myApplet.heroleft) - herosimage = herojumpleft; - else - herosimage = herojump; - } - */ - g.drawImage(herosimage, myApplet.playerPosition.x, myApplet.playerPosition.y,/*Color.white,*/ null); - } - /* - // draw warp image (on top of Hero) - if (myApplet.warpzone != null) { - // show the warp zone at the end of the level - g.drawImage(herowarp, myApplet.warpzone.x, myApplet.warpzone.y,Color.white, null); - } - */ - - } -}- \ No newline at end of file diff --git a/Link/LinkFrame.java b/Link/LinkFrame.java @@ -1,10 +0,0 @@ -package Link; - -import java.awt.Frame; - -public class LinkFrame extends Frame { - - public LinkFrame() { - setBounds(200, 200, 200, 150); - } -}- \ No newline at end of file diff --git a/Link/LinkGame.java b/Link/LinkGame.java @@ -1,544 +0,0 @@ -/* Copyright (c) Mary Percival 2003 */ -/* Link game Created May 2003 */ - -package Link; - -import java.awt.*; -import java.awt.event.*; -import java.applet.*; - -public class LinkGame extends Applet implements KeyListener, Runnable { - // all member variables 'static' because shared with the enemy action thread - static LinkArea area; - static boolean finished = false; - static boolean ingame = false; - static boolean juststarted = false; - static int level = 1; - static Point[] enemyPositions; - static Point playerPosition; - static Point[][] obstaclePositions; - static int direction[]; - Thread timer; - static int enemyNumber=1, enemiesRemaining=1, obstacleNumber=1; - static boolean herocrouching = false; - static final int MAXLEVELS = 1; - static final int levellengths[] = new int[MAXLEVELS]; - boolean hasWeaponOut=false; - - static int LEFT=-1; - static int RIGHT=1; - - // the next 2 constants are overridden in init once we know the screen size - static int RIGHTEDGE = 789; - static int BOTTOMEDGE = 900; - // - static Point IMAGESIZE=new Point(152,107); - static Point HEROPOS = new Point(63,28); - static final int LEFTEDGE = -15; - static final int TOPEDGE = -10; - static final int FALLAMOUNT=16; // amount he falls each time interval - static final int RISEAMOUNT=16; // amount he rises each time interval - static int GROUNDLEVEL = 500; - static int XAMOUNT=5; - static int YAMOUNT=5; - static int JUMPAMOUNT=70; - static final int X = 1; - static final int Y = 2; - static final int NOT=3; - static final int DELAY = 60; - - static int heroImageNo = 0; - static final int OBSTACLEIMAGES = 1; - static final int HEROIMAGES = 4; - static Image[] heroImages = new Image[HEROIMAGES]; - static Image[] obstacleImages = new Image[OBSTACLEIMAGES]; // obstacles don't move - static int obstacleImageNo[]; - static boolean heroleft = false; - static boolean jumping = false; - static Point warpzone; - //static boolean superjump = false; - static final int JUMPDURATION=5; - static final int SUPERJUMPDURATION=8; - static final int LEFTOFOBSTACLE = 27; - static final int RIGHTOFOBSTACLE = 33; - static int[] keysdown = new int[4]; - static final int LEFTDOWN=0; - static final int RIGHTDOWN=1; - static final int DOWNDOWN=2; - static final int SPACEDOWN=3; - - static final int OBSTACLEHEIGHT=42; - boolean onTheWayUp=false; - static int startPosY = GROUNDLEVEL; - - public void init() { - - setLayout(null); - setBackground(Color.white); - - area = new LinkArea(this); - add(area); - FontMetrics fm = getFontMetrics(getFont()); - XAMOUNT = 12; - YAMOUNT = 12; - RIGHTEDGE = (getBounds().width/XAMOUNT)*XAMOUNT +LEFTEDGE; - BOTTOMEDGE = getBounds().height - 1; - setVisible(true); - area.setBounds(0,0,getBounds().width,BOTTOMEDGE); - area.setVisible(true); - - addKeyListener(this); - area.addKeyListener(this); - area.requestFocus(); - - levellengths[0] = RIGHTEDGE; - obstacleImages[0] = area.obstacle; - - timer = new Thread(this); - timer.start(); - - } - - public void start() { - // called by Applet Viewer or Browser - doLevel(1); - } - - synchronized void faceRight() { - heroImages[0] = area.herostand; - heroImages[1] = area.hero1; - heroImages[2] = area.herostand; - heroImages[3] = area.hero2; - heroImageNo = 0; - heroleft=false; - } - - synchronized void faceLeft() { - heroImages[0] = area.herostandleft; - heroImages[1] = area.hero1left; - heroImages[2] = area.herostandleft; - heroImages[3] = area.hero2left; - heroImageNo = 0; - heroleft=true; - } - - synchronized void getSwordOut() { - hasWeaponOut = true; - if (heroleft) { - heroImages[0] = area.heroswordleft; - heroImages[1] = area.heroswordleft; - heroImages[2] = area.heroswordleft; - heroImages[3] = area.heroswordleft; - } - else { - heroImages[0] = area.heroswordright; - heroImages[1] = area.heroswordright; - heroImages[2] = area.heroswordright; - heroImages[3] = area.heroswordright; - } - heroImageNo = 0; - } - - synchronized void getShieldOut() { - hasWeaponOut = true; - if (heroleft) { - heroImages[0] = area.heroshieldleft; - heroImages[1] = area.heroshieldleft; - heroImages[2] = area.heroshieldleft; - heroImages[3] = area.heroshieldleft; - } - else { - heroImages[0] = area.heroshieldright; - heroImages[1] = area.heroshieldright; - heroImages[2] = area.heroshieldright; - heroImages[3] = area.heroshieldright; - } - heroImageNo = 0; - } - - synchronized void putWeaponAway() { - hasWeaponOut = false; - if (heroleft) faceLeft(); - else faceRight(); - } - - synchronized void standStill() { - heroImageNo = 0; - } - - public void doLevel(int level) { - // this runs one 'level' - juststarted = true; - Point temppoint; - - showStatus("Started level " + level); - - // position Hero at the bottom left - playerPosition = new Point(LEFTEDGE,GROUNDLEVEL); - faceRight(); - - // initialise obstacle states - obstacleImageNo = new int[obstacleNumber]; - obstacleImageNo[0] = 0; - - // initialise the arrays of enemies, etc - enemyPositions = new Point[enemyNumber]; - obstaclePositions = new Point[MAXLEVELS][obstacleNumber]; - direction = new int[enemyNumber]; - for (int i=0; i < enemyNumber; i++) { - enemyPositions[i] = new Point(RIGHTEDGE, GROUNDLEVEL); - direction[i] = LEFT; - } - for (int i=0; i < obstacleNumber; i++) { - switch(level) { - case 1: - obstaclePositions[level-1][i] = new Point((RIGHTEDGE+15)/2, GROUNDLEVEL); - System.out.println("Obstacle positioned at (" + (RIGHTEDGE-LEFTEDGE)/2+", " + GROUNDLEVEL + ")"); - break; - default: - } - } - - // position the warp zone at the end of the level - warpzone = new Point(levellengths[level-1], GROUNDLEVEL); - - // paint the panel here - //area.repaint(); - ingame = true; - } - - Point randomPosition() { - return new Point( (int) (Math.random() * RIGHTEDGE) / XAMOUNT * XAMOUNT, - (int) (Math.random() * BOTTOMEDGE) / YAMOUNT * YAMOUNT); - } - - boolean isPlayerPosition(Point p) { - return(p.x == playerPosition.x && p.y == playerPosition.y); - } - - boolean isEnemyPosition(Point p) { - for (int i = 0 ; i < enemyNumber; i++) { - if(p.x == enemyPositions[i].x && p.y == enemyPositions[i].y) return(true); - } - return(false); - } - - boolean isObstaclePosition(Point p) { - for (int i = 0 ; i < obstacleNumber; i++) { - if(isObstacleX(p) != -1 && isObstacleY(p) != -1) { - return(true); - } - } - return(false); - } - - boolean checkIfBlockingObstacle(Point p) { - boolean result = false; - for (int i = 0 ; i < obstacleNumber; i++) { - if(isObstacleX(p) != -1 && isBlockingObstacleY(p) != -1) { - //piranhaPopping[i] = false; - result = true; - } - //else piranhaPopping[i] = true; - } - if (!result) startPosY = GROUNDLEVEL; - return(result); - } - - int isObstacleX(Point p) { - int obstaclex; - for (int i = 0 ; i < obstacleNumber; i++) { - // if x is >= obstacleposition - (LEFTOFOBSTACLE) and x <= obstacleposition + (RIGHTOFOBSTACLE) - obstaclex = obstaclePositions[level-1][i].x; - if(p.x >= (obstaclex - LEFTOFOBSTACLE) && p.x <= (obstaclex + RIGHTOFOBSTACLE)) - return(i); // return the number of the matching obstacle - } - return(-1); - } - - int isBlockingObstacleY(Point p) { - for (int i = 0 ; i < obstacleNumber; i++) { - if(p.y <= obstaclePositions[level-1][i].y-OBSTACLEHEIGHT) return(i); - } - return(-1); - } - - int isObstacleY(Point p) { - for (int i = 0 ; i < obstacleNumber; i++) { - if(p.y > obstaclePositions[level-1][i].y-OBSTACLEHEIGHT) return(i); - } - return(-1); - } - - public void finished() { - finished = true; - System.exit(0); - } - - public String getAppletInfo() { - return ("Link Game"); - } - - int randomMove() { - // return + or - value (randomly) - if (Math.random() >= 0.5) return(24); - else return(-24); - } - - private synchronized void incKeysDown(int whichone) { - keysdown[whichone] = 1; - } - - private synchronized void decKeysDown(int whichone) { - keysdown[whichone] = 0; - } - - // this class will use just the key pressed event - public void keyPressed(KeyEvent e) { - if (ingame) { - if (! - ((e.getKeyCode() == KeyEvent.VK_LEFT && playerPosition.x <= (LEFTEDGE + XAMOUNT)) || - (e.getKeyCode() == KeyEvent.VK_RIGHT && playerPosition.x >= (RIGHTEDGE - XAMOUNT)))) { - // valid move: move the player and then move the enemies - if (e.getKeyCode() == KeyEvent.VK_DOWN) { - herocrouching = true; - incKeysDown(DOWNDOWN); - } - else if (e.getKeyCode() == KeyEvent.VK_LEFT) { - incKeysDown(LEFTDOWN); - leftPressed(); - } - else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - incKeysDown(RIGHTDOWN); - rightPressed(); - } - else if (e.getKeyCode() == KeyEvent.VK_SPACE) { - //System.out.println("Jump when jumping is " + jumping); - if (!jumping) { - //incKeysDown(SPACEDOWN); - startPosY = playerPosition.y; - jumping = true; - onTheWayUp=true; - } - } - else if (e.getKeyCode() == KeyEvent.VK_Z) { - getSwordOut(); - } - else if (e.getKeyCode() == KeyEvent.VK_X) { - getShieldOut(); - } - if (isEnemyPosition(playerPosition)) { - showStatus("The Player ran into an enemy!! Press the Enter key to restart the level"); - ingame = false; - } - //area.repaint(); - //showStatus("Hero's position = (" + playerPosition.x + ", " + playerPosition.y + ")"); - showStatus(" "); - } // if valid key press - } - else if (e.getKeyCode() == KeyEvent.VK_ENTER) { - doLevel(level++); - } - } - - void leftPressed() { - if (!herocrouching) { - //superjump = true; // if jumping - // if Hero was facing right, turn him left - if (!heroleft && !hasWeaponOut) - faceLeft(); - else { - // if the target position is not occupied by a obstacle... - for (int i=0; i < obstacleNumber; i++) { - if (isObstaclePosition(new Point(playerPosition.x-XAMOUNT, playerPosition.y))) - return; // can't move - } - playerPosition.x -= XAMOUNT; - incrementHeroImage(); - } - } - } - - void rightPressed() { - if (!herocrouching) { - //superjump = true; // if jumping - // if Hero was facing left, turn him right - if (heroleft && !hasWeaponOut) - faceRight(); - else { - for (int i=0; i < obstacleNumber; i++) { - if (isObstaclePosition(new Point(playerPosition.x+XAMOUNT, playerPosition.y))) - return; // can't move - } - playerPosition.x += XAMOUNT; - incrementHeroImage(); - } - } - } - - public void run() { - while (true) { - if (juststarted) { - try {Thread.sleep(750);} - catch (Exception e) {} - area.repaint(); - juststarted = false; - } - try {Thread.sleep(DELAY);} - catch (InterruptedException e){} - if (ingame) { - //System.out.println("Run: BEFORE: Hero's position = (" + playerPosition.x + ", " + playerPosition.y + ")"); - if (keysdown[LEFTDOWN] == 0 && - keysdown[RIGHTDOWN] == 0 && - keysdown[DOWNDOWN] == 0 /*&& - keysdown[SPACEDOWN] == 0*/) standStill(); - - if (keysdown[LEFTDOWN] > 0) leftPressed(); - else if (keysdown[RIGHTDOWN] > 0) rightPressed(); - - // for each obstacle, cycle through the piranha pictures - for (int i=0; i < obstacleNumber; i++) { - incrementObstacleImage(i); - } - - /* - // for each enemy, move the enemy in the direction it was going - for (int i=0; i < enemyPositions.length; i++) { - if (!deadHero(enemyPositions[i])) { - enemyPositions[i] = move(enemyPositions[i], direction[i]); - } - // if there is a obstacle at that position, fall into it and decrement count of enemies - // and set that enemy's position to -1, -1 - if (isObstaclePosition(enemyPositions[i])) { - showStatus("A enemy fell into a obstacle"); - - enemyPositions[i] = new Point(-1, -1); - enemiesRemaining--; - showStatus(enemyNumber-enemiesRemaining + " down, " + enemiesRemaining + " to go..."); - } - // if player is caught by a enemy or all enemies are gone, end the game - if (isPlayerPosition(enemyPositions[i])) { - showStatus("\"Mmm! Brains...\". The Player is dead. Press the Enter key to restart the level"); - level--; // because it will be incremented in a minute and we want to stay on the same 'level' - ingame = false; - } - } - if (enemiesRemaining == 0) { - showStatus("All the enemies are gone -- you won!! Press the Enter key to start the next level"); - enemyNumber++; - if (obstacleNumber > 2) obstacleNumber--; - ingame = false; - } - */ - if (onTheWayUp) { - //System.out.println("OnTheWayUp. Start Y Position =" + startPosY); - if (playerPosition.y > startPosY-JUMPAMOUNT) - playerPosition = new Point(playerPosition.x, playerPosition.y - RISEAMOUNT); - else { - onTheWayUp=false; - } - } - else { - int obstacleno = isObstacleX(playerPosition); - if (obstacleno == -1) { // no obstacle at this position - if (onTheWayUp == false) { - if (playerPosition.y < startPosY) - playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); - else jumping = false; - } - } - else { - Point obstaclepos = obstaclePositions[level-1][obstacleno]; - // if hero's y position <= obstacle's height - if (playerPosition.y <= (obstaclepos.y-OBSTACLEHEIGHT)) { // can't land on the obstacle if just < (??!) - // allow hero to land on the obstacle - //System.out.println("Allow Hero to land (or stay) on obstacle"); - jumping=false; - playerPosition = new Point(playerPosition.x, obstaclepos.y-OBSTACLEHEIGHT); - // if the piranha was up, Hero dies - if (obstacleImages[obstacleImageNo[obstacleno]] != area.obstacle) { - System.out.println("Hero dies!!"); - ingame=false; - - } - /* - else { - // otherwise stop this Piranha - piranhaPopping[obstacleno] = false; - } - */ - } - else { - if (onTheWayUp == false) { - if (playerPosition.y < startPosY) - playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); - else jumping = false; - } - } - } - } - checkIfBlockingObstacle(playerPosition); - //System.out.println("Run: AFTER: Hero's position = (" + playerPosition.x + ", " + playerPosition.y + ")"); - area.repaint(); - } - } - } - - synchronized void incrementObstacleImage(int i) { - obstacleImageNo[i]++; - if (obstacleImageNo[i] == OBSTACLEIMAGES) obstacleImageNo[i] = 0; - } - - synchronized void incrementHeroImage() { - heroImageNo++; - if (heroImageNo == HEROIMAGES) heroImageNo = 0; - } - - Point move(Point start, int direction) { - return(new Point(start.x + direction, start.y)); - } - - boolean deadHero(Point p) { - return(p.x == -1 && p.y ==-1); - } - - public void keyReleased(KeyEvent e) { - boolean needrepaint = false; - if (e.getKeyCode() == KeyEvent.VK_DOWN) { - herocrouching = false; - decKeysDown(DOWNDOWN); - needrepaint = true; - } - /* - else if (e.getKeyCode() == KeyEvent.VK_SPACE) { - decKeysDown(SPACEDOWN); - } - */ - else if (e.getKeyCode() == KeyEvent.VK_LEFT) { - decKeysDown(LEFTDOWN); - //superjump = false; - } - else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - decKeysDown(RIGHTDOWN); - //superjump = false; - } - else putWeaponAway(); - //if (needrepaint) area.repaint(); - } - - public void keyTyped(KeyEvent e) { - } - - synchronized Image getHeroImage() { - return(heroImages[heroImageNo]); - } - - synchronized Image getObstacleImage(int obstaclenum) { - return(obstacleImages[obstacleImageNo[obstaclenum]]); - } - - -} - - - diff --git a/Link/src/LinkArea.java b/Link/src/LinkArea.java @@ -0,0 +1,142 @@ +import java.awt.*; + +public class LinkArea extends Panel { + + static final int FLOORLEVEL = 587; + static final int FLOORWIDTH = 150; + LinkGame myApplet = null; + Image yellowgem; + Image spider; + Image obstacle; + Image redgem; + Image octopellets; + Image octo; + Image madblob; + Image heroswordright; + Image heroswordleft; + Image herostand; + Image hero1; + Image hero2; + Image herostandleft; + Image hero1left; + Image hero2left; + Image heroshieldright; + Image heroshieldleft; + Image greengem; + Image bluegem; + Image goldskullata; + Image gemstandgems; + Image gemstandempty; + Image blob; + MediaTracker mt=null; + + public LinkArea(LinkGame parent) { + mt=new MediaTracker(parent); + myApplet = parent; + yellowgem = load(myApplet, "yellowgem.gif"); + spider = load(myApplet, "spider.gif"); + obstacle = load(myApplet, "rock.gif"); + redgem = load(myApplet, "redgem.gif"); + octopellets = load(myApplet, "octopellets.gif"); + octo = load(myApplet, "octo.gif"); + madblob = load(myApplet, "madblob.gif"); + heroswordright = load(myApplet, "linkswordright.gif"); + heroswordleft = load(myApplet, "linkswordleft.gif"); + herostand = load(myApplet, "linkstandright.gif"); + hero1 = load(myApplet, "linkstandright.gif"); + hero2 = load(myApplet, "linkstandright2.gif"); + herostandleft = load(myApplet, "linkstandleft.gif"); + hero1left = load(myApplet, "linkstandleft.gif"); + hero2left = load(myApplet, "linkstandleft2.gif"); + heroshieldright = load(myApplet, "linkshieldright.gif"); + heroshieldleft = load(myApplet, "linkshieldleft.gif"); + greengem = load(myApplet, "greengem.gif"); + bluegem = load(myApplet, "bluegem.gif"); + goldskullata = load(myApplet, "goldskullata.gif"); + gemstandgems = load(myApplet, "gemstand(with gems).gif"); + gemstandempty = load(myApplet, "gemstand(without gems).gif"); + blob = load(myApplet, "blob.gif"); + } + void checkImage(Image image, String name) { + if (mt != null) { + mt.addImage(image,0); + try { + mt.waitForID(0,5000); + } + catch (InterruptedException ie) { + // nothing to do + } + if (mt.isErrorID(0)) System.out.println("Image Not found: "+name.toString()); + } + } + + Image load(LinkGame parent, String picture) { + Image im = parent.getImage(myApplet.getCodeBase(), "Link\\" + picture); + checkImage(im, picture); + return(im); + } + + public synchronized void paint (Graphics g) { + Image obstacleimage; + if (myApplet == null) return; + final int w = getBounds().width; + final int h = getBounds().height; + g.setColor(Color.white); + g.fillRect(0, 0, w, h); + FontMetrics fm = getFontMetrics(getFont()); + + g.setColor(Color.black); + int asc = fm.getAscent() + 4; + /* + // paint the floor + for (int pos=0; pos < w; pos+=FLOORWIDTH) { + g.drawImage(floor,pos, FLOORLEVEL,Color.black, null); + } + */ + + if (myApplet.obstaclePositions != null) { + // show the obstacles + for (int i=0; i < myApplet.obstaclePositions.length; i++) { + obstacleimage = myApplet.getObstacleImage(i); + g.drawImage(obstacleimage, myApplet.obstaclePositions[myApplet.level-1][i].x, myApplet.obstaclePositions[myApplet.level-1][i].y-4,Color.white, null); + } + } + + /* + // show the enemies + for (int i=0; i < myApplet.enemyPositions.length; i++) { + if (myApplet.enemyPositions[i].x > -1) + g.drawImage(enemyImage, myApplet.enemyPositions[i].x, myApplet.enemyPositions[i].y,null); + } + } + */ + // draw Hero (on top of preceding images) + if (myApplet.playerPosition != null) { + // show the player + Image herosimage = myApplet.getHeroImage(); + /* + if (myApplet.herocrouching) { + if (myApplet.heroleft) + herosimage = herocrouchleft; + else + herosimage = herocrouch; + } + if (myApplet.jumping) { + if (myApplet.heroleft) + herosimage = herojumpleft; + else + herosimage = herojump; + } + */ + g.drawImage(herosimage, myApplet.playerPosition.x, myApplet.playerPosition.y,/*Color.white,*/ null); + } + /* + // draw warp image (on top of Hero) + if (myApplet.warpzone != null) { + // show the warp zone at the end of the level + g.drawImage(herowarp, myApplet.warpzone.x, myApplet.warpzone.y,Color.white, null); + } + */ + + } +}+ \ No newline at end of file diff --git a/Link/src/LinkGame.java b/Link/src/LinkGame.java @@ -0,0 +1,545 @@ +import java.awt.Color; +import java.awt.Image; +import java.awt.Point; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.JFrame; + +/* Copyright (c) Mary Percival 2003 */ +/* Link game Created May 2003 */ + +public class LinkGame extends JFrame implements KeyListener, Runnable { + private static final long serialVersionUID = 136423218680421502L; + // all member variables 'static' because shared with the enemy action thread + static LinkArea area; + static boolean finished = false; + static boolean ingame = false; + static boolean juststarted = false; + static int level = 1; + static Point[] enemyPositions; + static Point playerPosition; + static Point[][] obstaclePositions; + static int direction[]; + Thread timer; + static int enemyNumber=1, enemiesRemaining=1, obstacleNumber=1; + static boolean herocrouching = false; + static final int MAXLEVELS = 1; + static final int levellengths[] = new int[MAXLEVELS]; + boolean hasWeaponOut=false; + + static int LEFT=-1; + static int RIGHT=1; + + // the next 2 constants are overridden in init once we know the screen size + static int RIGHTEDGE = 789; + static int BOTTOMEDGE = 900; + // + static Point IMAGESIZE=new Point(152,107); + static Point HEROPOS = new Point(63,28); + static final int LEFTEDGE = -15; + static final int TOPEDGE = -10; + static final int FALLAMOUNT=16; // amount he falls each time interval + static final int RISEAMOUNT=16; // amount he rises each time interval + static int GROUNDLEVEL = 500; + static int XAMOUNT=5; + static int YAMOUNT=5; + static int JUMPAMOUNT=70; + static final int X = 1; + static final int Y = 2; + static final int NOT=3; + static final int DELAY = 60; + + static int heroImageNo = 0; + static final int OBSTACLEIMAGES = 1; + static final int HEROIMAGES = 4; + static Image[] heroImages = new Image[HEROIMAGES]; + static Image[] obstacleImages = new Image[OBSTACLEIMAGES]; // obstacles don't move + static int obstacleImageNo[]; + static boolean heroleft = false; + static boolean jumping = false; + static Point warpzone; + //static boolean superjump = false; + static final int JUMPDURATION=5; + static final int SUPERJUMPDURATION=8; + static final int LEFTOFOBSTACLE = 27; + static final int RIGHTOFOBSTACLE = 33; + static int[] keysdown = new int[4]; + static final int LEFTDOWN=0; + static final int RIGHTDOWN=1; + static final int DOWNDOWN=2; + static final int SPACEDOWN=3; + + static final int OBSTACLEHEIGHT=42; + boolean onTheWayUp=false; + static int startPosY = GROUNDLEVEL; + + public void init() { + + setLayout(null); + setBackground(Color.white); + + area = new LinkArea(this); + add(area); + XAMOUNT = 12; + YAMOUNT = 12; + RIGHTEDGE = (getBounds().width/XAMOUNT)*XAMOUNT +LEFTEDGE; + BOTTOMEDGE = getBounds().height - 1; + setVisible(true); + area.setBounds(0,0,getBounds().width,BOTTOMEDGE); + area.setVisible(true); + + addKeyListener(this); + area.addKeyListener(this); + area.requestFocus(); + + levellengths[0] = RIGHTEDGE; + obstacleImages[0] = area.obstacle; + + timer = new Thread(this); + timer.start(); + + } + + public void start() { + // called by Applet Viewer or Browser + doLevel(1); + } + + synchronized void faceRight() { + heroImages[0] = area.herostand; + heroImages[1] = area.hero1; + heroImages[2] = area.herostand; + heroImages[3] = area.hero2; + heroImageNo = 0; + heroleft=false; + } + + synchronized void faceLeft() { + heroImages[0] = area.herostandleft; + heroImages[1] = area.hero1left; + heroImages[2] = area.herostandleft; + heroImages[3] = area.hero2left; + heroImageNo = 0; + heroleft=true; + } + + synchronized void getSwordOut() { + hasWeaponOut = true; + if (heroleft) { + heroImages[0] = area.heroswordleft; + heroImages[1] = area.heroswordleft; + heroImages[2] = area.heroswordleft; + heroImages[3] = area.heroswordleft; + } + else { + heroImages[0] = area.heroswordright; + heroImages[1] = area.heroswordright; + heroImages[2] = area.heroswordright; + heroImages[3] = area.heroswordright; + } + heroImageNo = 0; + } + + synchronized void getShieldOut() { + hasWeaponOut = true; + if (heroleft) { + heroImages[0] = area.heroshieldleft; + heroImages[1] = area.heroshieldleft; + heroImages[2] = area.heroshieldleft; + heroImages[3] = area.heroshieldleft; + } + else { + heroImages[0] = area.heroshieldright; + heroImages[1] = area.heroshieldright; + heroImages[2] = area.heroshieldright; + heroImages[3] = area.heroshieldright; + } + heroImageNo = 0; + } + + synchronized void putWeaponAway() { + hasWeaponOut = false; + if (heroleft) faceLeft(); + else faceRight(); + } + + synchronized void standStill() { + heroImageNo = 0; + } + + public void doLevel(int level) { + // this runs one 'level' + juststarted = true; + + System.out.println("Started level " + level); + + // position Hero at the bottom left + playerPosition = new Point(LEFTEDGE,GROUNDLEVEL); + faceRight(); + + // initialise obstacle states + obstacleImageNo = new int[obstacleNumber]; + obstacleImageNo[0] = 0; + + // initialise the arrays of enemies, etc + enemyPositions = new Point[enemyNumber]; + obstaclePositions = new Point[MAXLEVELS][obstacleNumber]; + direction = new int[enemyNumber]; + for (int i=0; i < enemyNumber; i++) { + enemyPositions[i] = new Point(RIGHTEDGE, GROUNDLEVEL); + direction[i] = LEFT; + } + for (int i=0; i < obstacleNumber; i++) { + switch(level) { + case 1: + obstaclePositions[level-1][i] = new Point((RIGHTEDGE+15)/2, GROUNDLEVEL); + System.out.println("Obstacle positioned at (" + (RIGHTEDGE-LEFTEDGE)/2+", " + GROUNDLEVEL + ")"); + break; + default: + } + } + + // position the warp zone at the end of the level + warpzone = new Point(levellengths[level-1], GROUNDLEVEL); + + // paint the panel here + //area.repaint(); + ingame = true; + } + + Point randomPosition() { + return new Point( (int) (Math.random() * RIGHTEDGE) / XAMOUNT * XAMOUNT, + (int) (Math.random() * BOTTOMEDGE) / YAMOUNT * YAMOUNT); + } + + boolean isPlayerPosition(Point p) { + return(p.x == playerPosition.x && p.y == playerPosition.y); + } + + boolean isEnemyPosition(Point p) { + for (int i = 0 ; i < enemyNumber; i++) { + if(p.x == enemyPositions[i].x && p.y == enemyPositions[i].y) return(true); + } + return(false); + } + + boolean isObstaclePosition(Point p) { + for (int i = 0 ; i < obstacleNumber; i++) { + if(isObstacleX(p) != -1 && isObstacleY(p) != -1) { + return(true); + } + } + return(false); + } + + boolean checkIfBlockingObstacle(Point p) { + boolean result = false; + for (int i = 0 ; i < obstacleNumber; i++) { + if(isObstacleX(p) != -1 && isBlockingObstacleY(p) != -1) { + //piranhaPopping[i] = false; + result = true; + } + //else piranhaPopping[i] = true; + } + if (!result) startPosY = GROUNDLEVEL; + return(result); + } + + int isObstacleX(Point p) { + int obstaclex; + for (int i = 0 ; i < obstacleNumber; i++) { + // if x is >= obstacleposition - (LEFTOFOBSTACLE) and x <= obstacleposition + (RIGHTOFOBSTACLE) + obstaclex = obstaclePositions[level-1][i].x; + if(p.x >= (obstaclex - LEFTOFOBSTACLE) && p.x <= (obstaclex + RIGHTOFOBSTACLE)) + return(i); // return the number of the matching obstacle + } + return(-1); + } + + int isBlockingObstacleY(Point p) { + for (int i = 0 ; i < obstacleNumber; i++) { + if(p.y <= obstaclePositions[level-1][i].y-OBSTACLEHEIGHT) return(i); + } + return(-1); + } + + int isObstacleY(Point p) { + for (int i = 0 ; i < obstacleNumber; i++) { + if(p.y > obstaclePositions[level-1][i].y-OBSTACLEHEIGHT) return(i); + } + return(-1); + } + + public void finished() { + finished = true; + System.exit(0); + } + + public String getAppletInfo() { + return ("Link Game"); + } + + int randomMove() { + // return + or - value (randomly) + if (Math.random() >= 0.5) return(24); + else return(-24); + } + + private synchronized void incKeysDown(int whichone) { + keysdown[whichone] = 1; + } + + private synchronized void decKeysDown(int whichone) { + keysdown[whichone] = 0; + } + + // this class will use just the key pressed event + public void keyPressed(KeyEvent e) { + if (ingame) { + if (! + ((e.getKeyCode() == KeyEvent.VK_LEFT && playerPosition.x <= (LEFTEDGE + XAMOUNT)) || + (e.getKeyCode() == KeyEvent.VK_RIGHT && playerPosition.x >= (RIGHTEDGE - XAMOUNT)))) { + // valid move: move the player and then move the enemies + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + herocrouching = true; + incKeysDown(DOWNDOWN); + } + else if (e.getKeyCode() == KeyEvent.VK_LEFT) { + incKeysDown(LEFTDOWN); + leftPressed(); + } + else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { + incKeysDown(RIGHTDOWN); + rightPressed(); + } + else if (e.getKeyCode() == KeyEvent.VK_SPACE) { + //System.out.println("Jump when jumping is " + jumping); + if (!jumping) { + //incKeysDown(SPACEDOWN); + startPosY = playerPosition.y; + jumping = true; + onTheWayUp=true; + } + } + else if (e.getKeyCode() == KeyEvent.VK_Z) { + getSwordOut(); + } + else if (e.getKeyCode() == KeyEvent.VK_X) { + getShieldOut(); + } + if (isEnemyPosition(playerPosition)) { + System.out.println("The Player ran into an enemy!! Press the Enter key to restart the level"); + ingame = false; + } + //area.repaint(); + //System.out.println("Hero's position = (" + playerPosition.x + ", " + playerPosition.y + ")"); + System.out.println(" "); + } // if valid key press + } + else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + doLevel(level++); + } + } + + void leftPressed() { + if (!herocrouching) { + //superjump = true; // if jumping + // if Hero was facing right, turn him left + if (!heroleft && !hasWeaponOut) + faceLeft(); + else { + // if the target position is not occupied by a obstacle... + for (int i=0; i < obstacleNumber; i++) { + if (isObstaclePosition(new Point(playerPosition.x-XAMOUNT, playerPosition.y))) + return; // can't move + } + playerPosition.x -= XAMOUNT; + incrementHeroImage(); + } + } + } + + void rightPressed() { + if (!herocrouching) { + //superjump = true; // if jumping + // if Hero was facing left, turn him right + if (heroleft && !hasWeaponOut) + faceRight(); + else { + for (int i=0; i < obstacleNumber; i++) { + if (isObstaclePosition(new Point(playerPosition.x+XAMOUNT, playerPosition.y))) + return; // can't move + } + playerPosition.x += XAMOUNT; + incrementHeroImage(); + } + } + } + + public void run() { + while (true) { + if (juststarted) { + try {Thread.sleep(750);} + catch (Exception e) {} + area.repaint(); + juststarted = false; + } + try {Thread.sleep(DELAY);} + catch (InterruptedException e){} + if (ingame) { + //System.out.println("Run: BEFORE: Hero's position = (" + playerPosition.x + ", " + playerPosition.y + ")"); + if (keysdown[LEFTDOWN] == 0 && + keysdown[RIGHTDOWN] == 0 && + keysdown[DOWNDOWN] == 0 /*&& + keysdown[SPACEDOWN] == 0*/) standStill(); + + if (keysdown[LEFTDOWN] > 0) leftPressed(); + else if (keysdown[RIGHTDOWN] > 0) rightPressed(); + + // for each obstacle, cycle through the piranha pictures + for (int i=0; i < obstacleNumber; i++) { + incrementObstacleImage(i); + } + + /* + // for each enemy, move the enemy in the direction it was going + for (int i=0; i < enemyPositions.length; i++) { + if (!deadHero(enemyPositions[i])) { + enemyPositions[i] = move(enemyPositions[i], direction[i]); + } + // if there is a obstacle at that position, fall into it and decrement count of enemies + // and set that enemy's position to -1, -1 + if (isObstaclePosition(enemyPositions[i])) { + System.out.println("A enemy fell into a obstacle"); + + enemyPositions[i] = new Point(-1, -1); + enemiesRemaining--; + System.out.println(enemyNumber-enemiesRemaining + " down, " + enemiesRemaining + " to go..."); + } + // if player is caught by a enemy or all enemies are gone, end the game + if (isPlayerPosition(enemyPositions[i])) { + System.out.println("\"Mmm! Brains...\". The Player is dead. Press the Enter key to restart the level"); + level--; // because it will be incremented in a minute and we want to stay on the same 'level' + ingame = false; + } + } + if (enemiesRemaining == 0) { + System.out.println("All the enemies are gone -- you won!! Press the Enter key to start the next level"); + enemyNumber++; + if (obstacleNumber > 2) obstacleNumber--; + ingame = false; + } + */ + if (onTheWayUp) { + //System.out.println("OnTheWayUp. Start Y Position =" + startPosY); + if (playerPosition.y > startPosY-JUMPAMOUNT) + playerPosition = new Point(playerPosition.x, playerPosition.y - RISEAMOUNT); + else { + onTheWayUp=false; + } + } + else { + int obstacleno = isObstacleX(playerPosition); + if (obstacleno == -1) { // no obstacle at this position + if (onTheWayUp == false) { + if (playerPosition.y < startPosY) + playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); + else jumping = false; + } + } + else { + Point obstaclepos = obstaclePositions[level-1][obstacleno]; + // if hero's y position <= obstacle's height + if (playerPosition.y <= (obstaclepos.y-OBSTACLEHEIGHT)) { // can't land on the obstacle if just < (??!) + // allow hero to land on the obstacle + //System.out.println("Allow Hero to land (or stay) on obstacle"); + jumping=false; + playerPosition = new Point(playerPosition.x, obstaclepos.y-OBSTACLEHEIGHT); + // if the piranha was up, Hero dies + if (obstacleImages[obstacleImageNo[obstacleno]] != area.obstacle) { + System.out.println("Hero dies!!"); + ingame=false; + + } + /* + else { + // otherwise stop this Piranha + piranhaPopping[obstacleno] = false; + } + */ + } + else { + if (onTheWayUp == false) { + if (playerPosition.y < startPosY) + playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); + else jumping = false; + } + } + } + } + checkIfBlockingObstacle(playerPosition); + //System.out.println("Run: AFTER: Hero's position = (" + playerPosition.x + ", " + playerPosition.y + ")"); + area.repaint(); + } + } + } + + synchronized void incrementObstacleImage(int i) { + obstacleImageNo[i]++; + if (obstacleImageNo[i] == OBSTACLEIMAGES) obstacleImageNo[i] = 0; + } + + synchronized void incrementHeroImage() { + heroImageNo++; + if (heroImageNo == HEROIMAGES) heroImageNo = 0; + } + + Point move(Point start, int direction) { + return(new Point(start.x + direction, start.y)); + } + + boolean deadHero(Point p) { + return(p.x == -1 && p.y ==-1); + } + + public void keyReleased(KeyEvent e) { + boolean needrepaint = false; + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + herocrouching = false; + decKeysDown(DOWNDOWN); + needrepaint = true; + } + /* + else if (e.getKeyCode() == KeyEvent.VK_SPACE) { + decKeysDown(SPACEDOWN); + } + */ + else if (e.getKeyCode() == KeyEvent.VK_LEFT) { + decKeysDown(LEFTDOWN); + //superjump = false; + } + else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { + decKeysDown(RIGHTDOWN); + //superjump = false; + } + else putWeaponAway(); + //if (needrepaint) area.repaint(); + } + + public void keyTyped(KeyEvent e) { + } + + synchronized Image getHeroImage() { + return(heroImages[heroImageNo]); + } + + synchronized Image getObstacleImage(int obstaclenum) { + return(obstacleImages[obstacleImageNo[obstaclenum]]); + } + + +} + + + diff --git a/Mario.html b/Mario.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Mario Game</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Mario.MarioGame.class" WIDTH=800 HEIGHT=600 X=200 Y=0></APPLET> -</BODY> -</HTML> diff --git a/Pong.html b/Pong.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Pong Game</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Pong.PongGame.class" WIDTH=800 HEIGHT=600 X=200 Y=0></APPLET> -</BODY> -</HTML> diff --git a/Pong/src/PongGame.java b/Pong/src/PongGame.java @@ -79,7 +79,7 @@ public class PongGame extends JFrame implements KeyListener, Runnable { goingDown[i] = true; } - // showStatus("Started level " + level); + // System.out.println("Started level " + level); // randomly position 1 player, x balls playerPosition = new Point(RIGHTEDGE - 20, 0); diff --git a/Reaper.html b/Reaper.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Reaper Game</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Reaper.ReaperGame.class" WIDTH=800 HEIGHT=600 X=200 Y=0></APPLET> -</BODY> -</HTML> diff --git a/Tank.html b/Tank.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Tank Game</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Tank.TankGame.class" WIDTH=800 HEIGHT=600 X=200 Y=0></APPLET> -</BODY> -</HTML> diff --git a/Zombies.html b/Zombies.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Zombie Game</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Zombie.ZombieGame.class" WIDTH=800 HEIGHT=600 X=200 Y=0></APPLET> -</BODY> -</HTML> diff --git a/autogen_Reaper.html b/autogen_Reaper.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Autogenerated HTML</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Reaper.ReaperGame.class" WIDTH=430 HEIGHT=270></APPLET> -</BODY> -</HTML> diff --git a/autogen_asteroids.html b/autogen_asteroids.html @@ -1,8 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Autogenerated HTML</TITLE> -</HEAD> -<BODY> -<APPLET CODE="Asteroids.class" WIDTH=430 HEIGHT=270></APPLET> -</BODY> -</HTML>