old-java-games

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

commit ec09e02576dab12558a3ac7318da561efc151e77
parent e03f206e92732747765c05da8f411d5de8e86070
Author: mpizzzle <michael.770211@gmail.com>
Date:   Sat,  2 Mar 2019 12:35:23 +0000

moving reaper assets

Diffstat:
RReaper/bod.gif -> Reaper/Assets/bod.gif | 0
RReaper/bunny.gif -> Reaper/Assets/bunny.gif | 0
RReaper/bus.gif -> Reaper/Assets/bus.gif | 0
RReaper/fire hydrant.gif -> Reaper/Assets/fire hydrant.gif | 0
RReaper/g.gif -> Reaper/Assets/g.gif | 0
RReaper/gr.gif -> Reaper/Assets/gr.gif | 0
RReaper/gri.gif -> Reaper/Assets/gri.gif | 0
RReaper/grim.gif -> Reaper/Assets/grim.gif | 0
RReaper/grimr.gif -> Reaper/Assets/grimr.gif | 0
RReaper/grimre.gif -> Reaper/Assets/grimre.gif | 0
RReaper/grimrea.gif -> Reaper/Assets/grimrea.gif | 0
RReaper/grimreap.gif -> Reaper/Assets/grimreap.gif | 0
RReaper/grimreape.gif -> Reaper/Assets/grimreape.gif | 0
RReaper/grimreaper.gif -> Reaper/Assets/grimreaper.gif | 0
RReaper/grimreaperenemydeafeat.gif -> Reaper/Assets/grimreaperenemydeafeat.gif | 0
RReaper/grimreaperenemydeafeat2.gif -> Reaper/Assets/grimreaperenemydeafeat2.gif | 0
RReaper/grimreaperwriting.gif -> Reaper/Assets/grimreaperwriting.gif | 0
RReaper/missioncomplete.gif -> Reaper/Assets/missioncomplete.gif | 0
RReaper/one two.gif -> Reaper/Assets/one two.gif | 0
RReaper/paddle.gif -> Reaper/Assets/paddle.gif | 0
RReaper/reaperdead.gif -> Reaper/Assets/reaperdead.gif | 0
RReaper/rsqr.gif -> Reaper/Assets/rsqr.gif | 0
RReaper/rsqrfon.gif -> Reaper/Assets/rsqrfon.gif | 0
RReaper/rsqrkickfon.gif -> Reaper/Assets/rsqrkickfon.gif | 0
RReaper/run1.gif -> Reaper/Assets/run1.gif | 0
RReaper/run1left.gif -> Reaper/Assets/run1left.gif | 0
RReaper/run2.gif -> Reaper/Assets/run2.gif | 0
RReaper/run2left.gif -> Reaper/Assets/run2left.gif | 0
RReaper/two two.gif -> Reaper/Assets/two two.gif | 0
RReaper/warp.gif -> Reaper/Assets/warp.gif | 0
DReaper/ReaperArea.java | 188-------------------------------------------------------------------------------
DReaper/ReaperFrame.java | 11-----------
DReaper/ReaperGame.java | 827-------------------------------------------------------------------------------
AReaper/src/ReaperArea.java | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AReaper/src/ReaperGame.java | 825+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 files changed, 1011 insertions(+), 1026 deletions(-)

diff --git a/Reaper/bod.gif b/Reaper/Assets/bod.gif Binary files differ. diff --git a/Reaper/bunny.gif b/Reaper/Assets/bunny.gif Binary files differ. diff --git a/Reaper/bus.gif b/Reaper/Assets/bus.gif Binary files differ. diff --git a/Reaper/fire hydrant.gif b/Reaper/Assets/fire hydrant.gif Binary files differ. diff --git a/Reaper/g.gif b/Reaper/Assets/g.gif Binary files differ. diff --git a/Reaper/gr.gif b/Reaper/Assets/gr.gif Binary files differ. diff --git a/Reaper/gri.gif b/Reaper/Assets/gri.gif Binary files differ. diff --git a/Reaper/grim.gif b/Reaper/Assets/grim.gif Binary files differ. diff --git a/Reaper/grimr.gif b/Reaper/Assets/grimr.gif Binary files differ. diff --git a/Reaper/grimre.gif b/Reaper/Assets/grimre.gif Binary files differ. diff --git a/Reaper/grimrea.gif b/Reaper/Assets/grimrea.gif Binary files differ. diff --git a/Reaper/grimreap.gif b/Reaper/Assets/grimreap.gif Binary files differ. diff --git a/Reaper/grimreape.gif b/Reaper/Assets/grimreape.gif Binary files differ. diff --git a/Reaper/grimreaper.gif b/Reaper/Assets/grimreaper.gif Binary files differ. diff --git a/Reaper/grimreaperenemydeafeat.gif b/Reaper/Assets/grimreaperenemydeafeat.gif Binary files differ. diff --git a/Reaper/grimreaperenemydeafeat2.gif b/Reaper/Assets/grimreaperenemydeafeat2.gif Binary files differ. diff --git a/Reaper/grimreaperwriting.gif b/Reaper/Assets/grimreaperwriting.gif Binary files differ. diff --git a/Reaper/missioncomplete.gif b/Reaper/Assets/missioncomplete.gif Binary files differ. diff --git a/Reaper/one two.gif b/Reaper/Assets/one two.gif Binary files differ. diff --git a/Reaper/paddle.gif b/Reaper/Assets/paddle.gif Binary files differ. diff --git a/Reaper/reaperdead.gif b/Reaper/Assets/reaperdead.gif Binary files differ. diff --git a/Reaper/rsqr.gif b/Reaper/Assets/rsqr.gif Binary files differ. diff --git a/Reaper/rsqrfon.gif b/Reaper/Assets/rsqrfon.gif Binary files differ. diff --git a/Reaper/rsqrkickfon.gif b/Reaper/Assets/rsqrkickfon.gif Binary files differ. diff --git a/Reaper/run1.gif b/Reaper/Assets/run1.gif Binary files differ. diff --git a/Reaper/run1left.gif b/Reaper/Assets/run1left.gif Binary files differ. diff --git a/Reaper/run2.gif b/Reaper/Assets/run2.gif Binary files differ. diff --git a/Reaper/run2left.gif b/Reaper/Assets/run2left.gif Binary files differ. diff --git a/Reaper/two two.gif b/Reaper/Assets/two two.gif Binary files differ. diff --git a/Reaper/warp.gif b/Reaper/Assets/warp.gif Binary files differ. diff --git a/Reaper/ReaperArea.java b/Reaper/ReaperArea.java @@ -1,187 +0,0 @@ -package Reaper; - -import java.awt.*; - -public class ReaperArea extends Panel { - - static int FLOORLEVEL = 589; - static final int FLOORWIDTH = 150; - static int FLOORDIFF = 605-FLOORLEVEL; - ReaperGame myApplet = null; - Image reaperwarp; - Image reaper1; - Image reaper1left; - Image reaper2; - Image reaper2left; - Image reapercrouch; - Image reapercrouchleft; - Image reaperjump; - Image reaperjumpleft; - Image obstacle; - Image tallobstacle; - Image reaperstand; - Image reaperstandleft; - Image levelcomplete; - Image reaperdead; - Image squishedrunner; - Image runner, runner2, runnerleft, runner2left; - Image title[] = new Image[10]; - MediaTracker mt=null; - boolean showingMessage = false; - boolean starting=true; - - public ReaperArea(ReaperGame parent) { - mt=new MediaTracker(parent); - myApplet = parent; - - runner = load(parent, "run1.gif"); - runnerleft = load(parent, "run1left.gif"); - runner2 = load(parent, "run2.gif"); - runner2left = load(parent, "run2left.gif"); - - squishedrunner = load(parent, "run1.gif"); - - reaper1 = load(parent, "grimreaper.gif"); - reaper1left = load(parent, "grimreaper.gif"); - reaper2 = load(parent, "grimreaper.gif"); - reaper2left = load(parent, "grimreaper.gif"); - reapercrouch = load(parent, "grimreaper.gif"); - reapercrouchleft = load(parent, "grimreaper.gif"); - reaperjump = load(parent, "grimreaper.gif"); - reaperjumpleft = load(parent, "grimreaper.gif"); - - obstacle = load(parent, "fire hydrant.gif"); - tallobstacle = load(parent, "bus.gif"); - reaperstand = load(parent, "grimreaper.gif"); - reaperstandleft = load(parent, "grimreaper.gif"); - - levelcomplete = load(parent, "missioncomplete.gif"); - reaperdead = load(parent, "reaperdead.gif"); - reaperwarp = load(parent, "warp.gif"); - - title[0] = load(parent, "g.gif"); - title[1] = load(parent, "gr.gif"); - title[2] = load(parent, "gri.gif"); - title[3] = load(parent, "grim.gif"); - title[4] = load(parent, "grimr.gif"); - title[5] = load(parent, "grimre.gif"); - title[6] = load(parent, "grimrea.gif"); - title[7] = load(parent, "grimreap.gif"); - title[8] = load(parent, "grimreape.gif"); - title[9] = load(parent, "grimreaperwriting.gif"); - - } - - Image load(ReaperGame parent, String picture) { - Image im = parent.getImage(myApplet.getCodeBase(), "Reaper\\" + picture); - checkImage(im, picture); - return(im); - } - - 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()); - } - } - - public synchronized void paint (Graphics g) { - Image obstacleimage, preyimage; - if (myApplet == null) return; - final int w = getBounds().width; - final int h = getBounds().height; - g.setColor(Color.white); - g.fillRect(0, 0, w, FLOORLEVEL); // don't white wash the floor! - FontMetrics fm = getFontMetrics(getFont()); - - g.setColor(Color.black); - int asc = fm.getAscent() + 4; - - // paint the floor - if (myApplet.floors[myApplet.level-1] != null) { - for (int pos=0; pos < w; pos+=FLOORWIDTH) { - g.drawImage(myApplet.floors[myApplet.level-1],pos, FLOORLEVEL,Color.black, null); - } - } - if (!myApplet.juststarted) { - if (myApplet.obstaclePositions != null) { - myApplet.changePageIfNecessary(); - // show the obstacles from right to left (because obstacles have white space to their left but not their right) - for (int i=myApplet.obstacleNumber-1; i >= 0; i--) { - obstacleimage = myApplet.getObstacleImage(i); - if (myApplet.isTall[i]) obstacleimage = tallobstacle; // only one image for this for now - g.drawImage(obstacleimage, myApplet.obstaclePositions[i].x-(myApplet.page*myApplet.PAGEWIDTH), myApplet.obstaclePositions[i].y,Color.white, null); - } - } - - // show the prey - if (myApplet.preyPositions != null) { - for (int i=0; i < myApplet.preyNumber; i++) { - //if (!myApplet.preyDead[i]) { - preyimage = myApplet.getEnemyImage(i); - g.drawImage(preyimage, myApplet.preyPositions[i].x-(myApplet.page*myApplet.PAGEWIDTH), myApplet.preyPositions[i].y,null); - //} - } - } - - // draw Hero (on top of preceding images) - if (myApplet.playerPosition != null) { - // show the player - Image reapersimage = myApplet.getHeroImage(); - if (myApplet.reapercrouching) { - if (myApplet.reaperleft) - reapersimage = reapercrouchleft; - else - reapersimage = reapercrouch; - } - if (myApplet.jumping) { - if (myApplet.reaperleft) - reapersimage = reaperjumpleft; - else - reapersimage = reaperjump; - } - g.drawImage(reapersimage, myApplet.playerPosition.x-(myApplet.page*myApplet.PAGEWIDTH), 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(reaperwarp, myApplet.warpzone.x-(myApplet.page*myApplet.PAGEWIDTH), myApplet.warpzone.y,Color.white, null); - } - - if (myApplet.ingame == false && !myApplet.juststarted) { - if (myApplet.dead) { - // Reaper is dead (?!) - g.drawImage(reaperdead, myApplet.getBounds().width/2, getBounds().height/2,Color.white, null); - } - else { - // level complete - g.drawImage(levelcomplete, myApplet.getBounds().width/2, getBounds().height/2,Color.white, null); - } - showingMessage=true; - } - else - showingMessage = false; - if (starting) { - showTitle(g); - starting=false; - } - - myApplet.setSomethingChangedSinceRepaint(false); - } - - 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) {} - } - } -}- \ No newline at end of file diff --git a/Reaper/ReaperFrame.java b/Reaper/ReaperFrame.java @@ -1,10 +0,0 @@ -package Reaper; - -import java.awt.Frame; - -public class ReaperFrame extends Frame { - - public ReaperFrame() { - setBounds(200, 200, 200, 150); - } -}- \ No newline at end of file diff --git a/Reaper/ReaperGame.java b/Reaper/ReaperGame.java @@ -1,827 +0,0 @@ -//* Copyright (c) Mary Percival 2003 */ -/* Reaper game Created May 2003 */ - -package Reaper; - -import java.awt.*; -import java.awt.event.*; -import java.applet.*; - -public class ReaperGame extends Applet implements KeyListener, Runnable { - - boolean easymode = true; - static int MAXLEVEL = 1; - static int level = 1; - - // the levels so far are: - // 1 beginner level: 4 fire hydrants & 1 runner - - static int LEFT=1; - static int RIGHT=0; - // the next 2 constants are overridden in init once we know the screen size - static int RIGHTEDGE = 789; - static int BOTTOMEDGE = 900; - static int PAGEWIDTH=741; - - static Point IMAGESIZE=new Point(152,107); - static final int LEFTEDGE = 0; - static final int TOPEDGE = -10; - static int GROUNDLEVEL = 503; - static int startPosY; - static int JUMPAMOUNT=70; - static int BOUNCEAMOUNT=48; - static final int FALLAMOUNT=16; // amount he falls each time interval - static final int RISEAMOUNT=16; // amount he rises each time interval - static final int XAMOUNT=12; - - static final int X = 1; - static final int Y = 2; - static final int NOT=3; - static final int DELAY = 50; - - static final int OBSTACLEIMAGES = 1; // static obstacles - unlike reaper obstacles - static final int HEROIMAGES = 4; - static final int PREYIMAGES=3; - - // ---------------------------------------------------------------------------------------------- - // PREY TYPES - // ---------------------------------------------------------------------------------------------- - static final int PREYTYPES=1; // runner - static final int RUNNER=0; - - // prey positions (height) - static final int RUNNERHEIGHT =GROUNDLEVEL-20; - static int preyHeight[] = new int[PREYTYPES]; - - static final int preySize[] = {27}; - static final int preyTopSpace[] = { 4}; - - static final int SPACE_FROM_X_TO_REAPER=55; - static final int REAPERHEIGHT=86; - static final int REAPEROFFSET=21; - static final int REAPERCROUCHOFFSET=39; - static final int REAPERSTANDINGSIZE = 65; - static final int REAPERCROUCHINGSIZE = 45; - - static final int JUMPDURATION=5; - static final int SUPERJUMPDURATION=8; - static final int REAPERLEFTOFOBSTACLE = 45; // fudge factor because Reaper image is diff size to obstacle image - static final int REAPERRIGHTOFOBSTACLE = 10; // fudge factor because Reaper image is diff size to obstacle image - static final int PREYLEFTOFOBSTACLE = 33; // fudge factor for prey images - static final int PREYRIGHTOFOBSTACLE = 7; // >49 causes panic! - static final int REAPERLEFTOFPREY=73; - static final int REAPERRIGHTOFPREY=-23; - - 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; - static final int TALLOBSTACLEDIFF=28; - static final int OBSTACLEWIDTH=40; - int GROUNDDIFF=605-GROUNDLEVEL; - - // all member variables 'static' because shared with the prey action thread - static ReaperArea area; - Thread timer; - static boolean finished = false; - static boolean ingame = false; - static boolean juststarted = true; - static Point warpzone; - static int[] keysdown = new int[4]; - static Point[] preyPositions; - static Point playerPosition; - static Point[] obstaclePositions; - static boolean[] piranhaPopping; // one for each obstacle - static boolean[] hasPiranha; // one for each obstacle - static boolean[] isTall; // one for each obstacle - static int preyDirection[]; - static int preyNumber=1, preyRemaining=1, obstacleNumber=1; - static boolean reapercrouching = false; - static boolean onTheWayUp=false; - static boolean bouncing=false; - static boolean wasbouncing = false; - static boolean dead = false; - static int page = 0; - static int reaperImageNo = 0; - static int preyImageNo[]; - static int levellength=1482; - static Image[] reaperImages = new Image[HEROIMAGES]; - static Image[] obstacleImages = new Image[OBSTACLEIMAGES]; // obstacle, piranhapeep, piranha peepy etc - static Image[] squished = new Image[PREYTYPES]; // squished images for each prey type - static Image[][][] preyImages = new Image[PREYTYPES][2][PREYIMAGES]; // left right left right or whatever - static int obstacleImageNo[]; // what is the current image for obstacle n - static Image[][] preyImage = new Image[PREYTYPES][PREYIMAGES];// what is the current image for prey n? - static Image floors[] = new Image[MAXLEVEL]; - static int preyType[]; // what is the type of prey n? - static boolean preyDead[]; // is prey n dead? - static boolean reaperleft = false; - static boolean jumping = false; - static int preyMove[] = new int[PREYTYPES]; - boolean somethingChangedSinceRepaint=false; - - // ************************************************************* - public void init() { - - setLayout(null); - setBackground(Color.white); - - area = new ReaperArea(this); - add(area); - FontMetrics fm = getFontMetrics(getFont()); - RIGHTEDGE = (getBounds().width/XAMOUNT)*XAMOUNT +LEFTEDGE; - BOTTOMEDGE = getBounds().height - 1; - setVisible(true); - area.setBounds(0,0,getBounds().width,BOTTOMEDGE); - GROUNDLEVEL = getBounds().height-GROUNDDIFF; - startPosY = GROUNDLEVEL; - area.FLOORLEVEL = getBounds().height-area.FLOORDIFF; - area.setVisible(true); - - addKeyListener(this); - area.addKeyListener(this); - area.requestFocus(); - - for (int i=0; i < OBSTACLEIMAGES; i++) { - obstacleImages[i] = area.obstacle; - } - - preyImages[RUNNER][RIGHT][0] = area.runner; - preyImages[RUNNER][RIGHT][1] = area.runner2; - preyImages[RUNNER][LEFT][0] = area.runnerleft; - preyImages[RUNNER][LEFT][1] = area.runner2left; - - preyMove[RUNNER] = 5; - preyHeight[RUNNER] = 40; - squished[RUNNER] = area.squishedrunner; - - //for (int i=0; i < MAXLEVEL; i++) { - // floors[i] = area.floor4; - //} - - timer = new Thread(this); - timer.start(); - - } - - public void start() { - // called by Applet Viewer or Browser - doLevel(level); - } - - synchronized void faceRight() { - reaperImages[0] = area.reaperstand; - reaperImages[1] = area.reaper1; - reaperImages[2] = area.reaperstand; - reaperImages[3] = area.reaper2; - reaperImageNo = 0; - reaperleft=false; - } - - synchronized void faceLeft() { - reaperImages[0] = area.reaperstandleft; - reaperImages[1] = area.reaper1left; - reaperImages[2] = area.reaperstandleft; - reaperImages[3] = area.reaper2left; - reaperImageNo = 0; - reaperleft=true; - } - - synchronized void preyFaceRight(int preyno) { - preyImage[preyno][0] = preyImages[preyType[preyno]][RIGHT][0]; - preyImage[preyno][1] = preyImages[preyType[preyno]][RIGHT][1]; - preyDirection[preyno] = RIGHT; - } - - synchronized void preyFaceLeft(int preyno) { - preyImage[preyno][0] = preyImages[preyType[preyno]][LEFT][0]; - preyImage[preyno][1] = preyImages[preyType[preyno]][LEFT][1]; - preyDirection[preyno] = LEFT; - } - - synchronized void preyDie(int preyno) { - //displayStatus(); - preyImage[preyno][0] = squished[preyType[preyno]]; - preyImage[preyno][1] = squished[preyType[preyno]]; - } - - synchronized void standStill() { - reaperImageNo = 0; - } - - public void doLevel(int level) { - // this runs one 'level' - juststarted = true; - Point temppoint; - dead = false; - - // position reaper at the bottom left - playerPosition = new Point(LEFTEDGE,GROUNDLEVEL); - faceRight(); - - - // *********** THIS STUFF DEPENDS WHAT LEVEL YOU ARE ON ************ - switch (level) { - case 1: - obstacleNumber=4; // 4 obstacles for level 1 - preyNumber = 1; - levellength = 1482; // 2 pages - break; - default: - System.out.println("Level " + level + " has not yet been implemented"); - } - preyImage = new Image[preyNumber][PREYIMAGES];// what is the current image for prey n? - // initialise piranha states - obstacleImageNo = new int[obstacleNumber]; - hasPiranha = new boolean[obstacleNumber]; - piranhaPopping = new boolean[obstacleNumber]; - isTall = new boolean[obstacleNumber]; - - // initialise the arrays of prey, etc - preyPositions = new Point[preyNumber]; - preyType = new int[preyNumber]; - preyDead = new boolean[preyNumber]; - obstaclePositions = new Point[obstacleNumber]; - preyDirection = new int[preyNumber]; - preyImageNo = new int[preyNumber]; - - for (int i=0; i < preyNumber; i++) { - preyImageNo[i] = 0; - } - - switch (level) { - // ----------------------------------------------- - // LEVEL 1 - // ----------------------------------------------- - case 1: - for (int i=0; i < obstacleNumber; i++) { - isTall[i] = false; - piranhaPopping[i] = false; - hasPiranha[i] = false; - } - obstaclePositions[0] = new Point(400, GROUNDLEVEL); - obstaclePositions[1] = new Point(950, GROUNDLEVEL); - obstaclePositions[2] = new Point(1245, GROUNDLEVEL); //1255 for adjacent - obstaclePositions[3] = new Point(1320, GROUNDLEVEL); - - preyPositions[0] = new Point(1000, RUNNERHEIGHT); - preyType = new int[] {RUNNER}; - break; - // ----------------------------------------------- - // LEVEL 2 - // ----------------------------------------------- - default: - - } - - for (int j=0; j < preyNumber; j++) { - preyFaceRight(j); // in this game all the 'prey' are fleeing to the right - preyDead[j] = false; - } - - for (int i=0; i < obstacleNumber; i++) { - if (hasPiranha[i]) { // pick a random image number between 0 and 18 (inclusive) - obstacleImageNo[i] = (int) (Math.random() * 18) / 1; - } - else obstacleImageNo[i] = 0; - } - - // position the warp zone at the end of the level - warpzone = new Point(levellength, GROUNDLEVEL); - // *********** END OF STUFF THAT DEPENDS WHAT LEVEL YOU ARE ON ************ - - ingame = true; - showStatus("Started level " + level); - } - - boolean isPlayerPosition(Point p) { - return(p.x == playerPosition.x && p.y == playerPosition.y); - } - - int isEnemyPosition(Point p) { - for (int i = 0 ; i < preyNumber; i++) { - if(isEnemyX(p) != -1 && isEnemyY(p) != -1 && !preyDead[i]) return(i); - } - return(-1); - } - - boolean isObstaclePosition(Point p, boolean forReaper) { - int obby; - for (int i = 0 ; i < obstacleNumber; i++) { - obby = isObstacleX(p, forReaper); - if(obby != -1 && isObstacleY(p, obby, forReaper) != -1) { - return(true); - } - } - return(false); - } - - boolean checkIfBlockingObstacle(Point p) { - boolean result = false; - int obby, obby2; - obby = isObstacleX(p, true); - if(obby != -1 && isBlockingObstacleY(p, obby)) { - piranhaPopping[obby] = false; - result = true; - } - for (int i = 0 ; i < obstacleNumber; i++) { - if (i != obby || !result) { - if (hasPiranha[i]) piranhaPopping[i] = true; - } - } - if (!result) startPosY = GROUNDLEVEL; - return(result); - } - - int isObstacleX(Point p, boolean forReaper) { - int obstaclex; - for (int i = 0 ; i < obstacleNumber; i++) { - // if x is >= obstacleposition - (REAPERLEFTOFOBSTACLE) and x <= obstacleposition + (REAPERRIGHTOFOBSTACLE) - obstaclex = obstaclePositions[i].x; - if (forReaper) { - if(p.x >= (obstaclex - REAPERLEFTOFOBSTACLE) && p.x <= (obstaclex + REAPERRIGHTOFOBSTACLE)) - return(i); // return the number of the matching obstacle - } - else { - if(p.x >= (obstaclex - PREYLEFTOFOBSTACLE) && p.x <= (obstaclex + PREYRIGHTOFOBSTACLE)) - return(i); // return the number of the matching obstacle - } - } - return(-1); - } - - boolean isBlockingObstacleY(Point p, int obstaclenumber) { - String s = "Is Reaper blocking obstacle " + obstaclenumber + " which is " + (isTall[obstaclenumber] ? "" : "not ") + "tall"; - if (isTall[obstaclenumber]) { - if(p.y <= obstaclePositions[obstaclenumber].y-(OBSTACLEHEIGHT+TALLOBSTACLEDIFF)) { - //System.out.println(s+": Yes"); - return(true); - } - } - else { - if(p.y <= obstaclePositions[obstaclenumber].y-OBSTACLEHEIGHT) { - //System.out.println(s+": Yes"); - return(true); - } - } - //System.out.println(s+": No"); - return(false); - } - - int isObstacleY(Point p, int obstaclenumber, boolean forReaper) { - if (isTall[obstaclenumber]) { - if(p.y > obstaclePositions[obstaclenumber].y-(OBSTACLEHEIGHT+TALLOBSTACLEDIFF)) { - return(obstaclenumber); - } - } - else { - if(p.y > obstaclePositions[obstaclenumber].y-OBSTACLEHEIGHT) { - return(obstaclenumber); - } - } - return(-1); - } - - int isEnemyX(Point p) { - int preyx; - for (int i = 0 ; i < preyNumber; i++) { - // if x is >= preyposition - (LEFTOFPREY) and x <= preyposition + (RIGHTOFPREY) - preyx = preyPositions[i].x; - //System.out.println("Player got by prey if " + - // p.x + " >= " + (preyx - REAPERLEFTOFPREY) + " && " + p.x + " <= " + (preyx + REAPERRIGHTOFPREY)); - if(p.x >= (preyx - REAPERLEFTOFPREY) && p.x <= (preyx + REAPERRIGHTOFPREY) && !preyDead[i]) - return(i); // return the number of the matching prey - } - return(-1); - } - - int isEnemyY(Point p) { - int offset = reapercrouching ? REAPERCROUCHOFFSET : REAPEROFFSET; - for (int i = 0 ; i < preyNumber; i++) { - if(!preyDead[i] && - ((p.y+offset <= preyPositions[i].y+preySize[preyType[i]]) && - (p.y+REAPERHEIGHT) >= preyPositions[i].y)) - return(i); - } - return(-1); - } - - public void finished() { - finished = true; - System.exit(0); - } - - public String getAppletInfo() { - return ("Reaper 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 (e.getKeyCode() == KeyEvent.VK_F1) { - displayStatus(); - } - if (ingame) { - if (! - (e.getKeyCode() == KeyEvent.VK_LEFT && playerPosition.x <= (LEFTEDGE + XAMOUNT))) { - - // valid move: move the player and then move the prey - if (e.getKeyCode() == KeyEvent.VK_DOWN) { - reapercrouching = true; - incKeysDown(DOWNDOWN); - setSomethingChangedSinceRepaint(true); - } - else if (e.getKeyCode() == KeyEvent.VK_LEFT) { - incKeysDown(LEFTDOWN); - leftPressed(false); - setSomethingChangedSinceRepaint(true); - } - else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - incKeysDown(RIGHTDOWN); - rightPressed(false); - setSomethingChangedSinceRepaint(true); - } - else if (e.getKeyCode() == KeyEvent.VK_SPACE) { - if (!jumping) { - startPosY = playerPosition.y; - jumping = true; - onTheWayUp=true; - setSomethingChangedSinceRepaint(true); - } - } - if (somethingChangedSinceRepaint) { - area.repaint(); - } - } // if valid key press - } - else if (e.getKeyCode() == KeyEvent.VK_ENTER) { - if (level == MAXLEVEL || dead) doLevel(level); - else doLevel(++level); - page=0; - area.repaint(); - } - } - - /*synchronized*/ void setSomethingChangedSinceRepaint(boolean val) { - somethingChangedSinceRepaint = val; - } - - void leftPressed(boolean skid) { - if (!reapercrouching) { - // if Hero was facing right, turn him left - if (!reaperleft) - 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), true)) - return; // can't move - } - playerPosition.x -= XAMOUNT; - if (!skid) incrementHeroImage(); - } - } - } - - void rightPressed(boolean skid) { - if (!reapercrouching) { - if ((playerPosition.x + SPACE_FROM_X_TO_REAPER) >= (warpzone.x+4)) { - // level complete! - ingame=false; - } - else { - // if Hero was facing left, turn him right - if (reaperleft) - faceRight(); - else { - for (int i=0; i < obstacleNumber; i++) { - if (isObstaclePosition(new Point(playerPosition.x+XAMOUNT, playerPosition.y), true)) - return; // can't move - } - playerPosition.x += XAMOUNT; - //System.out.println("Reaper's x position is " + playerPosition.x); - if (!skid) incrementHeroImage(); - } - } - } - } - - boolean anythingVisibleChanged() { - return(somethingChangedSinceRepaint); - } - - public void run() { - boolean odd=true; // only change piranha image every other cycle - while (true) { - if (juststarted) { - try {Thread.sleep(750);} - catch (Exception e) {} - area.repaint(); - juststarted = false; - } - try {Thread.sleep(DELAY);} - catch (InterruptedException e){} - if (ingame) { - if (keysdown[LEFTDOWN] == 0 && - keysdown[RIGHTDOWN] == 0 && - keysdown[DOWNDOWN] == 0) standStill(); - - if (keysdown[LEFTDOWN] > 0) { - leftPressed(false); - setSomethingChangedSinceRepaint(true); - } - else if (keysdown[RIGHTDOWN] > 0) { - rightPressed(false); - setSomethingChangedSinceRepaint(true); - } - - if (!odd) { - // for each obstacle, cycle through the piranha pictures - for (int i=0; i < obstacleNumber; i++) { - if (piranhaPopping[i]) { - incrementObstacleImage(i); - if (isVisibleObstacle(i)) setSomethingChangedSinceRepaint(true); - } - } - } - odd = !odd; - - // for each prey, move the prey in the direction it was going - for (int i=0; i < preyNumber; i++) { - // TODO if there is a fatal obstacle at that position, fall into it and decrement count of prey - // and set that prey's position to -1, -1 - /* - if (isObstaclePosition(preyPositions[i])) { - showStatus("A prey fell into a obstacle"); - - preyPositions[i] = new Point(-1, -1); - preyRemaining--; - showStatus(preyNumber-preyRemaining + " down, " + preyRemaining + " to go..."); - } - */ - // if there is a non-fatal obstacle - if (isObstaclePosition(preyPositions[i],false)) { - // change direction - changeDirection(i); - if (isVisibleEnemy(i)) setSomethingChangedSinceRepaint(true); - } - if (!preyDead[i]) { - preyPositions[i] = move(i, preyPositions[i], preyDirection[i], odd); - if (isVisibleEnemy(i)) setSomethingChangedSinceRepaint(true); - } - - // if player is caught by a prey, end the game - int preyno = isEnemyPosition(playerPosition); - if (preyno > -1) { - int NEEDTOBEABOVE = preyPositions[preyno].y+preyTopSpace[preyno]-REAPERHEIGHT; - if (easymode) NEEDTOBEABOVE = preyPositions[preyno].y-preyHeight[preyType[preyno]]; - if ((!onTheWayUp && (playerPosition.y <=NEEDTOBEABOVE))) { - // player may have squished an prey - preyDead[preyno]=true; - preyDie(preyno); - // player bounces - bouncing = true; - startPosY = playerPosition.y; - setSomethingChangedSinceRepaint(true); - } - else { - int offset = reapercrouching ? REAPERCROUCHOFFSET : REAPEROFFSET; - if (playerPosition.y > NEEDTOBEABOVE && - (playerPosition.y+offset <= preyPositions[preyno].y+preySize[preyType[preyno]])) { - die(); - setSomethingChangedSinceRepaint(true); - } - } - } - } - if (!dead) { - if (onTheWayUp) { - if (playerPosition.y > startPosY-JUMPAMOUNT) { - playerPosition = new Point(playerPosition.x, playerPosition.y - RISEAMOUNT); - setSomethingChangedSinceRepaint(true); - } - else { - onTheWayUp=false; - } - } - else if (bouncing) { - if (playerPosition.y > startPosY-BOUNCEAMOUNT) { - playerPosition = new Point(playerPosition.x, playerPosition.y - RISEAMOUNT); - setSomethingChangedSinceRepaint(true); - } - else { - bouncing=false; - wasbouncing = true; - } - } - else { - int obstacleno = isObstacleX(playerPosition, true); - if (obstacleno == -1) { // no obstacle at this position - if (!onTheWayUp && !bouncing) { - if (playerPosition.y < startPosY) { - playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); - wasbouncing = false; - setSomethingChangedSinceRepaint(true); - } - else jumping = false; - } - } - else { - Point obstaclepos = obstaclePositions[obstacleno]; - // if reaper's y position <= obstacle's height - int thisObstacleHeight = isTall[obstacleno] ? OBSTACLEHEIGHT+TALLOBSTACLEDIFF : OBSTACLEHEIGHT; - if (playerPosition.y <= (obstaclepos.y-thisObstacleHeight) && // can't land on the obstacle if just < (??!) - (playerPosition.y+FALLAMOUNT >= (obstaclepos.y-thisObstacleHeight)) - ) { - // allow reaper to land on the obstacle - jumping=false; - if (playerPosition.y != obstaclepos.y-thisObstacleHeight) setSomethingChangedSinceRepaint(true); - playerPosition = new Point(playerPosition.x, obstaclepos.y-thisObstacleHeight); - // if the piranha was up, Hero dies - if (obstacleImages[obstacleImageNo[obstacleno]] != area.obstacle) { - die(); - } - else { - // otherwise stop this Piranha - piranhaPopping[obstacleno] = false; - } - } - else { - if (!onTheWayUp && !bouncing) { - if (playerPosition.y < startPosY) { - setSomethingChangedSinceRepaint(true); - playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); - wasbouncing = false; - } - else jumping = false; - } - } - } - } - if (!dead) { - checkIfBlockingObstacle(playerPosition); - if (playerPosition.y > GROUNDLEVEL) playerPosition.y = GROUNDLEVEL; - } - if (anythingVisibleChanged()) { - area.repaint(); - } - } - else { - if (!area.showingMessage) - area.repaint(); - } - } - } - } - - boolean isVisibleObstacle(int i) { - // TODO - this probably needs fixing when obstacle is near page boundary - return ((obstaclePositions[i].x >= page*PAGEWIDTH) && - (obstaclePositions[i].x < (page+1)*PAGEWIDTH)); - } - - boolean isVisibleEnemy(int i) { - // TODO - this probably needs fixing when prey is near page boundary - return ((preyPositions[i].x >= page*PAGEWIDTH) && - (preyPositions[i].x < (page+1)*PAGEWIDTH) && !preyDead[i]); - } - - void changeDirection(int preyno) { - if (preyDirection[preyno] == LEFT) { - preyFaceRight(preyno); - } - else { - preyFaceLeft(preyno); - } - } - - synchronized void die() { - showStatus("The Player is dead. Press the Enter key to restart the level"); - ingame=false; - dead = true; - displayStatus(); - } - - synchronized void incrementObstacleImage(int i) { - obstacleImageNo[i]++; - if (obstacleImageNo[i] == OBSTACLEIMAGES) obstacleImageNo[i] = 0; - } - - synchronized void incrementHeroImage() { - reaperImageNo++; - if (reaperImageNo == HEROIMAGES) reaperImageNo = 0; - } - - synchronized void incrementEnemyImage(int i) { - preyImageNo[i]++; - if (preyImageNo[i] > (PREYIMAGES-2) ) preyImageNo[i] = 0; - } - - Point move(int preyNo, Point start, int direction, boolean odd) { - if (odd) incrementEnemyImage(preyNo); - if (direction == LEFT) { - return(new Point(start.x -preyMove[preyType[preyNo]], start.y)); - } - else { - return(new Point(start.x +preyMove[preyType[preyNo]], start.y)); - } - } - - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_DOWN) { - reapercrouching = false; - decKeysDown(DOWNDOWN); - } - else if (e.getKeyCode() == KeyEvent.VK_LEFT) { - decKeysDown(LEFTDOWN); - } - else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - decKeysDown(RIGHTDOWN); - } - } - - public void keyTyped(KeyEvent e) { - } - - synchronized Image getHeroImage() { - return(reaperImages[reaperImageNo]); - } - - synchronized Image getObstacleImage(int obstaclenum) { - return(obstacleImages[obstacleImageNo[obstaclenum]]); - } - - synchronized Image getEnemyImage(int preyno) { - return(preyImage[preyno][preyImageNo[preyno]]); - } - - void displayStatus() { - /* - // when a certain F Key is pressed, display positions of Reaper, - // all obstacles and all prey and the end flag (warp zone) - System.out.println("--------"); - System.out.println("Reaper is " + (dead? "dead" : "alive")); - if (dead) { - int preyno = isEnemyPosition(playerPosition); - System.out.println("Reaper was killed by prey " + preyno); - } - System.out.println("In game is " + ingame); - System.out.println("Reaper is " + (onTheWayUp? "on the way up" : "not on the way up")); - System.out.println("Reaper's position is (" + playerPosition.x + ", " + playerPosition.y + ")"); - System.out.println("Reaper's visible left, bottom co-ordinates are " + (playerPosition.x + 55) + " and " + (playerPosition.y + REAPERHEIGHT)); - System.out.println("Reaper is on page " + page + " (which shows x positions from " + (page*PAGEWIDTH) + " to " + ((page+1)*PAGEWIDTH) + ")"); - System.out.println("Screen bounds are (" + getBounds().width + ", " + getBounds().height + ")"); - System.out.println(""); - for (int prey=0; prey < preyNumber; prey++) { - System.out.println("Enemy " + prey + " is " + preyTypeString(preyType[prey]) + " and is " + - (preyDead[prey] ? " " : "not ") + "dead"); - System.out.println("Enemy " + prey + " is at position (" + preyPositions[prey].x + - ", " + preyPositions[prey].y+") and has size " + preySize[preyType[prey]]); - } - //System.out.println(""); - //for (int obstacle=0; obstacle < obstacleNumber; obstacle++) { - // System.out.println("Obstacle " + obstacle + " is at position (" + obstaclePositions[obstacle].x + - // ", " + obstaclePositions[obstacle].y+")"); - //} - System.out.println(""); - System.out.println("The warp zone is positioned at (" + warpzone.x + ", " + warpzone.y + ")"); - System.out.println("========"); - */ - } - - String preyTypeString(int fortype) { - switch (fortype) { - case RUNNER: - return("RUNNER"); - default: - return("Unknown type (" + fortype + ")"); - } - } - - void changePageIfNecessary() { - if (playerPosition.x == LEFTEDGE) return; - if ((playerPosition.x+SPACE_FROM_X_TO_REAPER) > (page*PAGEWIDTH+RIGHTEDGE-XAMOUNT)) { - //System.out.println("Change page up: (" + playerPosition.x+ "+" + SPACE_FROM_X_TO_REAPER+ ") > (" + page+ "*" + PAGEWIDTH + "+" + RIGHTEDGE + "-" + XAMOUNT + ")"); - page++; - } - else if ((playerPosition.x+SPACE_FROM_X_TO_REAPER)-(page*PAGEWIDTH) < (LEFTEDGE+XAMOUNT)) { - //System.out.println("Change page down: (" + playerPosition.x+ "+" + SPACE_FROM_X_TO_REAPER+ ")-(" + page+ "*" + PAGEWIDTH + ") < (" + LEFTEDGE+ "+" + XAMOUNT+")"); - page--; - } - } -} - diff --git a/Reaper/src/ReaperArea.java b/Reaper/src/ReaperArea.java @@ -0,0 +1,185 @@ +import java.awt.*; + +public class ReaperArea extends Panel { + + static int FLOORLEVEL = 589; + static final int FLOORWIDTH = 150; + static int FLOORDIFF = 605-FLOORLEVEL; + ReaperGame myApplet = null; + Image reaperwarp; + Image reaper1; + Image reaper1left; + Image reaper2; + Image reaper2left; + Image reapercrouch; + Image reapercrouchleft; + Image reaperjump; + Image reaperjumpleft; + Image obstacle; + Image tallobstacle; + Image reaperstand; + Image reaperstandleft; + Image levelcomplete; + Image reaperdead; + Image squishedrunner; + Image runner, runner2, runnerleft, runner2left; + Image title[] = new Image[10]; + MediaTracker mt=null; + boolean showingMessage = false; + boolean starting=true; + + public ReaperArea(ReaperGame parent) { + mt=new MediaTracker(parent); + myApplet = parent; + + runner = load(parent, "run1.gif"); + runnerleft = load(parent, "run1left.gif"); + runner2 = load(parent, "run2.gif"); + runner2left = load(parent, "run2left.gif"); + + squishedrunner = load(parent, "run1.gif"); + + reaper1 = load(parent, "grimreaper.gif"); + reaper1left = load(parent, "grimreaper.gif"); + reaper2 = load(parent, "grimreaper.gif"); + reaper2left = load(parent, "grimreaper.gif"); + reapercrouch = load(parent, "grimreaper.gif"); + reapercrouchleft = load(parent, "grimreaper.gif"); + reaperjump = load(parent, "grimreaper.gif"); + reaperjumpleft = load(parent, "grimreaper.gif"); + + obstacle = load(parent, "fire hydrant.gif"); + tallobstacle = load(parent, "bus.gif"); + reaperstand = load(parent, "grimreaper.gif"); + reaperstandleft = load(parent, "grimreaper.gif"); + + levelcomplete = load(parent, "missioncomplete.gif"); + reaperdead = load(parent, "reaperdead.gif"); + reaperwarp = load(parent, "warp.gif"); + + title[0] = load(parent, "g.gif"); + title[1] = load(parent, "gr.gif"); + title[2] = load(parent, "gri.gif"); + title[3] = load(parent, "grim.gif"); + title[4] = load(parent, "grimr.gif"); + title[5] = load(parent, "grimre.gif"); + title[6] = load(parent, "grimrea.gif"); + title[7] = load(parent, "grimreap.gif"); + title[8] = load(parent, "grimreape.gif"); + title[9] = load(parent, "grimreaperwriting.gif"); + + } + + Image load(ReaperGame parent, String picture) { + Image im = parent.getImage(myApplet.getCodeBase(), "Reaper\\" + picture); + checkImage(im, picture); + return(im); + } + + 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()); + } + } + + public synchronized void paint (Graphics g) { + Image obstacleimage, preyimage; + if (myApplet == null) return; + final int w = getBounds().width; + final int h = getBounds().height; + g.setColor(Color.white); + g.fillRect(0, 0, w, FLOORLEVEL); // don't white wash the floor! + FontMetrics fm = getFontMetrics(getFont()); + + g.setColor(Color.black); + int asc = fm.getAscent() + 4; + + // paint the floor + if (myApplet.floors[myApplet.level-1] != null) { + for (int pos=0; pos < w; pos+=FLOORWIDTH) { + g.drawImage(myApplet.floors[myApplet.level-1],pos, FLOORLEVEL,Color.black, null); + } + } + if (!myApplet.juststarted) { + if (myApplet.obstaclePositions != null) { + myApplet.changePageIfNecessary(); + // show the obstacles from right to left (because obstacles have white space to their left but not their right) + for (int i=myApplet.obstacleNumber-1; i >= 0; i--) { + obstacleimage = myApplet.getObstacleImage(i); + if (myApplet.isTall[i]) obstacleimage = tallobstacle; // only one image for this for now + g.drawImage(obstacleimage, myApplet.obstaclePositions[i].x-(myApplet.page*myApplet.PAGEWIDTH), myApplet.obstaclePositions[i].y,Color.white, null); + } + } + + // show the prey + if (myApplet.preyPositions != null) { + for (int i=0; i < myApplet.preyNumber; i++) { + //if (!myApplet.preyDead[i]) { + preyimage = myApplet.getEnemyImage(i); + g.drawImage(preyimage, myApplet.preyPositions[i].x-(myApplet.page*myApplet.PAGEWIDTH), myApplet.preyPositions[i].y,null); + //} + } + } + + // draw Hero (on top of preceding images) + if (myApplet.playerPosition != null) { + // show the player + Image reapersimage = myApplet.getHeroImage(); + if (myApplet.reapercrouching) { + if (myApplet.reaperleft) + reapersimage = reapercrouchleft; + else + reapersimage = reapercrouch; + } + if (myApplet.jumping) { + if (myApplet.reaperleft) + reapersimage = reaperjumpleft; + else + reapersimage = reaperjump; + } + g.drawImage(reapersimage, myApplet.playerPosition.x-(myApplet.page*myApplet.PAGEWIDTH), 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(reaperwarp, myApplet.warpzone.x-(myApplet.page*myApplet.PAGEWIDTH), myApplet.warpzone.y,Color.white, null); + } + + if (myApplet.ingame == false && !myApplet.juststarted) { + if (myApplet.dead) { + // Reaper is dead (?!) + g.drawImage(reaperdead, myApplet.getBounds().width/2, getBounds().height/2,Color.white, null); + } + else { + // level complete + g.drawImage(levelcomplete, myApplet.getBounds().width/2, getBounds().height/2,Color.white, null); + } + showingMessage=true; + } + else + showingMessage = false; + if (starting) { + showTitle(g); + starting=false; + } + + myApplet.setSomethingChangedSinceRepaint(false); + } + + 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) {} + } + } +}+ \ No newline at end of file diff --git a/Reaper/src/ReaperGame.java b/Reaper/src/ReaperGame.java @@ -0,0 +1,825 @@ +//* Copyright (c) Mary Percival 2003 */ +/* Reaper game Created May 2003 */ + +import java.awt.*; +import java.awt.event.*; +import java.applet.*; + +public class ReaperGame extends Applet implements KeyListener, Runnable { + + boolean easymode = true; + static int MAXLEVEL = 1; + static int level = 1; + + // the levels so far are: + // 1 beginner level: 4 fire hydrants & 1 runner + + static int LEFT=1; + static int RIGHT=0; + // the next 2 constants are overridden in init once we know the screen size + static int RIGHTEDGE = 789; + static int BOTTOMEDGE = 900; + static int PAGEWIDTH=741; + + static Point IMAGESIZE=new Point(152,107); + static final int LEFTEDGE = 0; + static final int TOPEDGE = -10; + static int GROUNDLEVEL = 503; + static int startPosY; + static int JUMPAMOUNT=70; + static int BOUNCEAMOUNT=48; + static final int FALLAMOUNT=16; // amount he falls each time interval + static final int RISEAMOUNT=16; // amount he rises each time interval + static final int XAMOUNT=12; + + static final int X = 1; + static final int Y = 2; + static final int NOT=3; + static final int DELAY = 50; + + static final int OBSTACLEIMAGES = 1; // static obstacles - unlike reaper obstacles + static final int HEROIMAGES = 4; + static final int PREYIMAGES=3; + + // ---------------------------------------------------------------------------------------------- + // PREY TYPES + // ---------------------------------------------------------------------------------------------- + static final int PREYTYPES=1; // runner + static final int RUNNER=0; + + // prey positions (height) + static final int RUNNERHEIGHT =GROUNDLEVEL-20; + static int preyHeight[] = new int[PREYTYPES]; + + static final int preySize[] = {27}; + static final int preyTopSpace[] = { 4}; + + static final int SPACE_FROM_X_TO_REAPER=55; + static final int REAPERHEIGHT=86; + static final int REAPEROFFSET=21; + static final int REAPERCROUCHOFFSET=39; + static final int REAPERSTANDINGSIZE = 65; + static final int REAPERCROUCHINGSIZE = 45; + + static final int JUMPDURATION=5; + static final int SUPERJUMPDURATION=8; + static final int REAPERLEFTOFOBSTACLE = 45; // fudge factor because Reaper image is diff size to obstacle image + static final int REAPERRIGHTOFOBSTACLE = 10; // fudge factor because Reaper image is diff size to obstacle image + static final int PREYLEFTOFOBSTACLE = 33; // fudge factor for prey images + static final int PREYRIGHTOFOBSTACLE = 7; // >49 causes panic! + static final int REAPERLEFTOFPREY=73; + static final int REAPERRIGHTOFPREY=-23; + + 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; + static final int TALLOBSTACLEDIFF=28; + static final int OBSTACLEWIDTH=40; + int GROUNDDIFF=605-GROUNDLEVEL; + + // all member variables 'static' because shared with the prey action thread + static ReaperArea area; + Thread timer; + static boolean finished = false; + static boolean ingame = false; + static boolean juststarted = true; + static Point warpzone; + static int[] keysdown = new int[4]; + static Point[] preyPositions; + static Point playerPosition; + static Point[] obstaclePositions; + static boolean[] piranhaPopping; // one for each obstacle + static boolean[] hasPiranha; // one for each obstacle + static boolean[] isTall; // one for each obstacle + static int preyDirection[]; + static int preyNumber=1, preyRemaining=1, obstacleNumber=1; + static boolean reapercrouching = false; + static boolean onTheWayUp=false; + static boolean bouncing=false; + static boolean wasbouncing = false; + static boolean dead = false; + static int page = 0; + static int reaperImageNo = 0; + static int preyImageNo[]; + static int levellength=1482; + static Image[] reaperImages = new Image[HEROIMAGES]; + static Image[] obstacleImages = new Image[OBSTACLEIMAGES]; // obstacle, piranhapeep, piranha peepy etc + static Image[] squished = new Image[PREYTYPES]; // squished images for each prey type + static Image[][][] preyImages = new Image[PREYTYPES][2][PREYIMAGES]; // left right left right or whatever + static int obstacleImageNo[]; // what is the current image for obstacle n + static Image[][] preyImage = new Image[PREYTYPES][PREYIMAGES];// what is the current image for prey n? + static Image floors[] = new Image[MAXLEVEL]; + static int preyType[]; // what is the type of prey n? + static boolean preyDead[]; // is prey n dead? + static boolean reaperleft = false; + static boolean jumping = false; + static int preyMove[] = new int[PREYTYPES]; + boolean somethingChangedSinceRepaint=false; + + // ************************************************************* + public void init() { + + setLayout(null); + setBackground(Color.white); + + area = new ReaperArea(this); + add(area); + FontMetrics fm = getFontMetrics(getFont()); + RIGHTEDGE = (getBounds().width/XAMOUNT)*XAMOUNT +LEFTEDGE; + BOTTOMEDGE = getBounds().height - 1; + setVisible(true); + area.setBounds(0,0,getBounds().width,BOTTOMEDGE); + GROUNDLEVEL = getBounds().height-GROUNDDIFF; + startPosY = GROUNDLEVEL; + area.FLOORLEVEL = getBounds().height-area.FLOORDIFF; + area.setVisible(true); + + addKeyListener(this); + area.addKeyListener(this); + area.requestFocus(); + + for (int i=0; i < OBSTACLEIMAGES; i++) { + obstacleImages[i] = area.obstacle; + } + + preyImages[RUNNER][RIGHT][0] = area.runner; + preyImages[RUNNER][RIGHT][1] = area.runner2; + preyImages[RUNNER][LEFT][0] = area.runnerleft; + preyImages[RUNNER][LEFT][1] = area.runner2left; + + preyMove[RUNNER] = 5; + preyHeight[RUNNER] = 40; + squished[RUNNER] = area.squishedrunner; + + //for (int i=0; i < MAXLEVEL; i++) { + // floors[i] = area.floor4; + //} + + timer = new Thread(this); + timer.start(); + + } + + public void start() { + // called by Applet Viewer or Browser + doLevel(level); + } + + synchronized void faceRight() { + reaperImages[0] = area.reaperstand; + reaperImages[1] = area.reaper1; + reaperImages[2] = area.reaperstand; + reaperImages[3] = area.reaper2; + reaperImageNo = 0; + reaperleft=false; + } + + synchronized void faceLeft() { + reaperImages[0] = area.reaperstandleft; + reaperImages[1] = area.reaper1left; + reaperImages[2] = area.reaperstandleft; + reaperImages[3] = area.reaper2left; + reaperImageNo = 0; + reaperleft=true; + } + + synchronized void preyFaceRight(int preyno) { + preyImage[preyno][0] = preyImages[preyType[preyno]][RIGHT][0]; + preyImage[preyno][1] = preyImages[preyType[preyno]][RIGHT][1]; + preyDirection[preyno] = RIGHT; + } + + synchronized void preyFaceLeft(int preyno) { + preyImage[preyno][0] = preyImages[preyType[preyno]][LEFT][0]; + preyImage[preyno][1] = preyImages[preyType[preyno]][LEFT][1]; + preyDirection[preyno] = LEFT; + } + + synchronized void preyDie(int preyno) { + //displayStatus(); + preyImage[preyno][0] = squished[preyType[preyno]]; + preyImage[preyno][1] = squished[preyType[preyno]]; + } + + synchronized void standStill() { + reaperImageNo = 0; + } + + public void doLevel(int level) { + // this runs one 'level' + juststarted = true; + Point temppoint; + dead = false; + + // position reaper at the bottom left + playerPosition = new Point(LEFTEDGE,GROUNDLEVEL); + faceRight(); + + + // *********** THIS STUFF DEPENDS WHAT LEVEL YOU ARE ON ************ + switch (level) { + case 1: + obstacleNumber=4; // 4 obstacles for level 1 + preyNumber = 1; + levellength = 1482; // 2 pages + break; + default: + System.out.println("Level " + level + " has not yet been implemented"); + } + preyImage = new Image[preyNumber][PREYIMAGES];// what is the current image for prey n? + // initialise piranha states + obstacleImageNo = new int[obstacleNumber]; + hasPiranha = new boolean[obstacleNumber]; + piranhaPopping = new boolean[obstacleNumber]; + isTall = new boolean[obstacleNumber]; + + // initialise the arrays of prey, etc + preyPositions = new Point[preyNumber]; + preyType = new int[preyNumber]; + preyDead = new boolean[preyNumber]; + obstaclePositions = new Point[obstacleNumber]; + preyDirection = new int[preyNumber]; + preyImageNo = new int[preyNumber]; + + for (int i=0; i < preyNumber; i++) { + preyImageNo[i] = 0; + } + + switch (level) { + // ----------------------------------------------- + // LEVEL 1 + // ----------------------------------------------- + case 1: + for (int i=0; i < obstacleNumber; i++) { + isTall[i] = false; + piranhaPopping[i] = false; + hasPiranha[i] = false; + } + obstaclePositions[0] = new Point(400, GROUNDLEVEL); + obstaclePositions[1] = new Point(950, GROUNDLEVEL); + obstaclePositions[2] = new Point(1245, GROUNDLEVEL); //1255 for adjacent + obstaclePositions[3] = new Point(1320, GROUNDLEVEL); + + preyPositions[0] = new Point(1000, RUNNERHEIGHT); + preyType = new int[] {RUNNER}; + break; + // ----------------------------------------------- + // LEVEL 2 + // ----------------------------------------------- + default: + + } + + for (int j=0; j < preyNumber; j++) { + preyFaceRight(j); // in this game all the 'prey' are fleeing to the right + preyDead[j] = false; + } + + for (int i=0; i < obstacleNumber; i++) { + if (hasPiranha[i]) { // pick a random image number between 0 and 18 (inclusive) + obstacleImageNo[i] = (int) (Math.random() * 18) / 1; + } + else obstacleImageNo[i] = 0; + } + + // position the warp zone at the end of the level + warpzone = new Point(levellength, GROUNDLEVEL); + // *********** END OF STUFF THAT DEPENDS WHAT LEVEL YOU ARE ON ************ + + ingame = true; + showStatus("Started level " + level); + } + + boolean isPlayerPosition(Point p) { + return(p.x == playerPosition.x && p.y == playerPosition.y); + } + + int isEnemyPosition(Point p) { + for (int i = 0 ; i < preyNumber; i++) { + if(isEnemyX(p) != -1 && isEnemyY(p) != -1 && !preyDead[i]) return(i); + } + return(-1); + } + + boolean isObstaclePosition(Point p, boolean forReaper) { + int obby; + for (int i = 0 ; i < obstacleNumber; i++) { + obby = isObstacleX(p, forReaper); + if(obby != -1 && isObstacleY(p, obby, forReaper) != -1) { + return(true); + } + } + return(false); + } + + boolean checkIfBlockingObstacle(Point p) { + boolean result = false; + int obby, obby2; + obby = isObstacleX(p, true); + if(obby != -1 && isBlockingObstacleY(p, obby)) { + piranhaPopping[obby] = false; + result = true; + } + for (int i = 0 ; i < obstacleNumber; i++) { + if (i != obby || !result) { + if (hasPiranha[i]) piranhaPopping[i] = true; + } + } + if (!result) startPosY = GROUNDLEVEL; + return(result); + } + + int isObstacleX(Point p, boolean forReaper) { + int obstaclex; + for (int i = 0 ; i < obstacleNumber; i++) { + // if x is >= obstacleposition - (REAPERLEFTOFOBSTACLE) and x <= obstacleposition + (REAPERRIGHTOFOBSTACLE) + obstaclex = obstaclePositions[i].x; + if (forReaper) { + if(p.x >= (obstaclex - REAPERLEFTOFOBSTACLE) && p.x <= (obstaclex + REAPERRIGHTOFOBSTACLE)) + return(i); // return the number of the matching obstacle + } + else { + if(p.x >= (obstaclex - PREYLEFTOFOBSTACLE) && p.x <= (obstaclex + PREYRIGHTOFOBSTACLE)) + return(i); // return the number of the matching obstacle + } + } + return(-1); + } + + boolean isBlockingObstacleY(Point p, int obstaclenumber) { + String s = "Is Reaper blocking obstacle " + obstaclenumber + " which is " + (isTall[obstaclenumber] ? "" : "not ") + "tall"; + if (isTall[obstaclenumber]) { + if(p.y <= obstaclePositions[obstaclenumber].y-(OBSTACLEHEIGHT+TALLOBSTACLEDIFF)) { + //System.out.println(s+": Yes"); + return(true); + } + } + else { + if(p.y <= obstaclePositions[obstaclenumber].y-OBSTACLEHEIGHT) { + //System.out.println(s+": Yes"); + return(true); + } + } + //System.out.println(s+": No"); + return(false); + } + + int isObstacleY(Point p, int obstaclenumber, boolean forReaper) { + if (isTall[obstaclenumber]) { + if(p.y > obstaclePositions[obstaclenumber].y-(OBSTACLEHEIGHT+TALLOBSTACLEDIFF)) { + return(obstaclenumber); + } + } + else { + if(p.y > obstaclePositions[obstaclenumber].y-OBSTACLEHEIGHT) { + return(obstaclenumber); + } + } + return(-1); + } + + int isEnemyX(Point p) { + int preyx; + for (int i = 0 ; i < preyNumber; i++) { + // if x is >= preyposition - (LEFTOFPREY) and x <= preyposition + (RIGHTOFPREY) + preyx = preyPositions[i].x; + //System.out.println("Player got by prey if " + + // p.x + " >= " + (preyx - REAPERLEFTOFPREY) + " && " + p.x + " <= " + (preyx + REAPERRIGHTOFPREY)); + if(p.x >= (preyx - REAPERLEFTOFPREY) && p.x <= (preyx + REAPERRIGHTOFPREY) && !preyDead[i]) + return(i); // return the number of the matching prey + } + return(-1); + } + + int isEnemyY(Point p) { + int offset = reapercrouching ? REAPERCROUCHOFFSET : REAPEROFFSET; + for (int i = 0 ; i < preyNumber; i++) { + if(!preyDead[i] && + ((p.y+offset <= preyPositions[i].y+preySize[preyType[i]]) && + (p.y+REAPERHEIGHT) >= preyPositions[i].y)) + return(i); + } + return(-1); + } + + public void finished() { + finished = true; + System.exit(0); + } + + public String getAppletInfo() { + return ("Reaper 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 (e.getKeyCode() == KeyEvent.VK_F1) { + displayStatus(); + } + if (ingame) { + if (! + (e.getKeyCode() == KeyEvent.VK_LEFT && playerPosition.x <= (LEFTEDGE + XAMOUNT))) { + + // valid move: move the player and then move the prey + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + reapercrouching = true; + incKeysDown(DOWNDOWN); + setSomethingChangedSinceRepaint(true); + } + else if (e.getKeyCode() == KeyEvent.VK_LEFT) { + incKeysDown(LEFTDOWN); + leftPressed(false); + setSomethingChangedSinceRepaint(true); + } + else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { + incKeysDown(RIGHTDOWN); + rightPressed(false); + setSomethingChangedSinceRepaint(true); + } + else if (e.getKeyCode() == KeyEvent.VK_SPACE) { + if (!jumping) { + startPosY = playerPosition.y; + jumping = true; + onTheWayUp=true; + setSomethingChangedSinceRepaint(true); + } + } + if (somethingChangedSinceRepaint) { + area.repaint(); + } + } // if valid key press + } + else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + if (level == MAXLEVEL || dead) doLevel(level); + else doLevel(++level); + page=0; + area.repaint(); + } + } + + /*synchronized*/ void setSomethingChangedSinceRepaint(boolean val) { + somethingChangedSinceRepaint = val; + } + + void leftPressed(boolean skid) { + if (!reapercrouching) { + // if Hero was facing right, turn him left + if (!reaperleft) + 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), true)) + return; // can't move + } + playerPosition.x -= XAMOUNT; + if (!skid) incrementHeroImage(); + } + } + } + + void rightPressed(boolean skid) { + if (!reapercrouching) { + if ((playerPosition.x + SPACE_FROM_X_TO_REAPER) >= (warpzone.x+4)) { + // level complete! + ingame=false; + } + else { + // if Hero was facing left, turn him right + if (reaperleft) + faceRight(); + else { + for (int i=0; i < obstacleNumber; i++) { + if (isObstaclePosition(new Point(playerPosition.x+XAMOUNT, playerPosition.y), true)) + return; // can't move + } + playerPosition.x += XAMOUNT; + //System.out.println("Reaper's x position is " + playerPosition.x); + if (!skid) incrementHeroImage(); + } + } + } + } + + boolean anythingVisibleChanged() { + return(somethingChangedSinceRepaint); + } + + public void run() { + boolean odd=true; // only change piranha image every other cycle + while (true) { + if (juststarted) { + try {Thread.sleep(750);} + catch (Exception e) {} + area.repaint(); + juststarted = false; + } + try {Thread.sleep(DELAY);} + catch (InterruptedException e){} + if (ingame) { + if (keysdown[LEFTDOWN] == 0 && + keysdown[RIGHTDOWN] == 0 && + keysdown[DOWNDOWN] == 0) standStill(); + + if (keysdown[LEFTDOWN] > 0) { + leftPressed(false); + setSomethingChangedSinceRepaint(true); + } + else if (keysdown[RIGHTDOWN] > 0) { + rightPressed(false); + setSomethingChangedSinceRepaint(true); + } + + if (!odd) { + // for each obstacle, cycle through the piranha pictures + for (int i=0; i < obstacleNumber; i++) { + if (piranhaPopping[i]) { + incrementObstacleImage(i); + if (isVisibleObstacle(i)) setSomethingChangedSinceRepaint(true); + } + } + } + odd = !odd; + + // for each prey, move the prey in the direction it was going + for (int i=0; i < preyNumber; i++) { + // TODO if there is a fatal obstacle at that position, fall into it and decrement count of prey + // and set that prey's position to -1, -1 + /* + if (isObstaclePosition(preyPositions[i])) { + showStatus("A prey fell into a obstacle"); + + preyPositions[i] = new Point(-1, -1); + preyRemaining--; + showStatus(preyNumber-preyRemaining + " down, " + preyRemaining + " to go..."); + } + */ + // if there is a non-fatal obstacle + if (isObstaclePosition(preyPositions[i],false)) { + // change direction + changeDirection(i); + if (isVisibleEnemy(i)) setSomethingChangedSinceRepaint(true); + } + if (!preyDead[i]) { + preyPositions[i] = move(i, preyPositions[i], preyDirection[i], odd); + if (isVisibleEnemy(i)) setSomethingChangedSinceRepaint(true); + } + + // if player is caught by a prey, end the game + int preyno = isEnemyPosition(playerPosition); + if (preyno > -1) { + int NEEDTOBEABOVE = preyPositions[preyno].y+preyTopSpace[preyno]-REAPERHEIGHT; + if (easymode) NEEDTOBEABOVE = preyPositions[preyno].y-preyHeight[preyType[preyno]]; + if ((!onTheWayUp && (playerPosition.y <=NEEDTOBEABOVE))) { + // player may have squished an prey + preyDead[preyno]=true; + preyDie(preyno); + // player bounces + bouncing = true; + startPosY = playerPosition.y; + setSomethingChangedSinceRepaint(true); + } + else { + int offset = reapercrouching ? REAPERCROUCHOFFSET : REAPEROFFSET; + if (playerPosition.y > NEEDTOBEABOVE && + (playerPosition.y+offset <= preyPositions[preyno].y+preySize[preyType[preyno]])) { + die(); + setSomethingChangedSinceRepaint(true); + } + } + } + } + if (!dead) { + if (onTheWayUp) { + if (playerPosition.y > startPosY-JUMPAMOUNT) { + playerPosition = new Point(playerPosition.x, playerPosition.y - RISEAMOUNT); + setSomethingChangedSinceRepaint(true); + } + else { + onTheWayUp=false; + } + } + else if (bouncing) { + if (playerPosition.y > startPosY-BOUNCEAMOUNT) { + playerPosition = new Point(playerPosition.x, playerPosition.y - RISEAMOUNT); + setSomethingChangedSinceRepaint(true); + } + else { + bouncing=false; + wasbouncing = true; + } + } + else { + int obstacleno = isObstacleX(playerPosition, true); + if (obstacleno == -1) { // no obstacle at this position + if (!onTheWayUp && !bouncing) { + if (playerPosition.y < startPosY) { + playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); + wasbouncing = false; + setSomethingChangedSinceRepaint(true); + } + else jumping = false; + } + } + else { + Point obstaclepos = obstaclePositions[obstacleno]; + // if reaper's y position <= obstacle's height + int thisObstacleHeight = isTall[obstacleno] ? OBSTACLEHEIGHT+TALLOBSTACLEDIFF : OBSTACLEHEIGHT; + if (playerPosition.y <= (obstaclepos.y-thisObstacleHeight) && // can't land on the obstacle if just < (??!) + (playerPosition.y+FALLAMOUNT >= (obstaclepos.y-thisObstacleHeight)) + ) { + // allow reaper to land on the obstacle + jumping=false; + if (playerPosition.y != obstaclepos.y-thisObstacleHeight) setSomethingChangedSinceRepaint(true); + playerPosition = new Point(playerPosition.x, obstaclepos.y-thisObstacleHeight); + // if the piranha was up, Hero dies + if (obstacleImages[obstacleImageNo[obstacleno]] != area.obstacle) { + die(); + } + else { + // otherwise stop this Piranha + piranhaPopping[obstacleno] = false; + } + } + else { + if (!onTheWayUp && !bouncing) { + if (playerPosition.y < startPosY) { + setSomethingChangedSinceRepaint(true); + playerPosition = new Point(playerPosition.x, playerPosition.y+FALLAMOUNT); + wasbouncing = false; + } + else jumping = false; + } + } + } + } + if (!dead) { + checkIfBlockingObstacle(playerPosition); + if (playerPosition.y > GROUNDLEVEL) playerPosition.y = GROUNDLEVEL; + } + if (anythingVisibleChanged()) { + area.repaint(); + } + } + else { + if (!area.showingMessage) + area.repaint(); + } + } + } + } + + boolean isVisibleObstacle(int i) { + // TODO - this probably needs fixing when obstacle is near page boundary + return ((obstaclePositions[i].x >= page*PAGEWIDTH) && + (obstaclePositions[i].x < (page+1)*PAGEWIDTH)); + } + + boolean isVisibleEnemy(int i) { + // TODO - this probably needs fixing when prey is near page boundary + return ((preyPositions[i].x >= page*PAGEWIDTH) && + (preyPositions[i].x < (page+1)*PAGEWIDTH) && !preyDead[i]); + } + + void changeDirection(int preyno) { + if (preyDirection[preyno] == LEFT) { + preyFaceRight(preyno); + } + else { + preyFaceLeft(preyno); + } + } + + synchronized void die() { + showStatus("The Player is dead. Press the Enter key to restart the level"); + ingame=false; + dead = true; + displayStatus(); + } + + synchronized void incrementObstacleImage(int i) { + obstacleImageNo[i]++; + if (obstacleImageNo[i] == OBSTACLEIMAGES) obstacleImageNo[i] = 0; + } + + synchronized void incrementHeroImage() { + reaperImageNo++; + if (reaperImageNo == HEROIMAGES) reaperImageNo = 0; + } + + synchronized void incrementEnemyImage(int i) { + preyImageNo[i]++; + if (preyImageNo[i] > (PREYIMAGES-2) ) preyImageNo[i] = 0; + } + + Point move(int preyNo, Point start, int direction, boolean odd) { + if (odd) incrementEnemyImage(preyNo); + if (direction == LEFT) { + return(new Point(start.x -preyMove[preyType[preyNo]], start.y)); + } + else { + return(new Point(start.x +preyMove[preyType[preyNo]], start.y)); + } + } + + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + reapercrouching = false; + decKeysDown(DOWNDOWN); + } + else if (e.getKeyCode() == KeyEvent.VK_LEFT) { + decKeysDown(LEFTDOWN); + } + else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { + decKeysDown(RIGHTDOWN); + } + } + + public void keyTyped(KeyEvent e) { + } + + synchronized Image getHeroImage() { + return(reaperImages[reaperImageNo]); + } + + synchronized Image getObstacleImage(int obstaclenum) { + return(obstacleImages[obstacleImageNo[obstaclenum]]); + } + + synchronized Image getEnemyImage(int preyno) { + return(preyImage[preyno][preyImageNo[preyno]]); + } + + void displayStatus() { + /* + // when a certain F Key is pressed, display positions of Reaper, + // all obstacles and all prey and the end flag (warp zone) + System.out.println("--------"); + System.out.println("Reaper is " + (dead? "dead" : "alive")); + if (dead) { + int preyno = isEnemyPosition(playerPosition); + System.out.println("Reaper was killed by prey " + preyno); + } + System.out.println("In game is " + ingame); + System.out.println("Reaper is " + (onTheWayUp? "on the way up" : "not on the way up")); + System.out.println("Reaper's position is (" + playerPosition.x + ", " + playerPosition.y + ")"); + System.out.println("Reaper's visible left, bottom co-ordinates are " + (playerPosition.x + 55) + " and " + (playerPosition.y + REAPERHEIGHT)); + System.out.println("Reaper is on page " + page + " (which shows x positions from " + (page*PAGEWIDTH) + " to " + ((page+1)*PAGEWIDTH) + ")"); + System.out.println("Screen bounds are (" + getBounds().width + ", " + getBounds().height + ")"); + System.out.println(""); + for (int prey=0; prey < preyNumber; prey++) { + System.out.println("Enemy " + prey + " is " + preyTypeString(preyType[prey]) + " and is " + + (preyDead[prey] ? " " : "not ") + "dead"); + System.out.println("Enemy " + prey + " is at position (" + preyPositions[prey].x + + ", " + preyPositions[prey].y+") and has size " + preySize[preyType[prey]]); + } + //System.out.println(""); + //for (int obstacle=0; obstacle < obstacleNumber; obstacle++) { + // System.out.println("Obstacle " + obstacle + " is at position (" + obstaclePositions[obstacle].x + + // ", " + obstaclePositions[obstacle].y+")"); + //} + System.out.println(""); + System.out.println("The warp zone is positioned at (" + warpzone.x + ", " + warpzone.y + ")"); + System.out.println("========"); + */ + } + + String preyTypeString(int fortype) { + switch (fortype) { + case RUNNER: + return("RUNNER"); + default: + return("Unknown type (" + fortype + ")"); + } + } + + void changePageIfNecessary() { + if (playerPosition.x == LEFTEDGE) return; + if ((playerPosition.x+SPACE_FROM_X_TO_REAPER) > (page*PAGEWIDTH+RIGHTEDGE-XAMOUNT)) { + //System.out.println("Change page up: (" + playerPosition.x+ "+" + SPACE_FROM_X_TO_REAPER+ ") > (" + page+ "*" + PAGEWIDTH + "+" + RIGHTEDGE + "-" + XAMOUNT + ")"); + page++; + } + else if ((playerPosition.x+SPACE_FROM_X_TO_REAPER)-(page*PAGEWIDTH) < (LEFTEDGE+XAMOUNT)) { + //System.out.println("Change page down: (" + playerPosition.x+ "+" + SPACE_FROM_X_TO_REAPER+ ")-(" + page+ "*" + PAGEWIDTH + ") < (" + LEFTEDGE+ "+" + XAMOUNT+")"); + page--; + } + } +} +