View Game: Pitfall 4K

Pitfall 4K (http://meatfighter.com/java4k2012/pitfall4k/)

By zeroone, submitted on Dec 10, 2011
Min JRE version: 1.6
3294 downloads.
This game was submitted in the Java4K 2012 Competition.
Source code available! Show source code

(Click on game for focus)


You need Java installed to play this game.
You may use the button below to get it.

Get Java


Description

The optimal pathway through the maze can be viewed here:

http://meatfighter.com/java4k2012/pitfall4k/map.html

You can safely stand on the right tip of crocodile heads even when their mouths are open.

The object of Pitfall 4K is to guide Harry through a maze of jungle scenes, jumping over or avoiding many deadly dangers, and helping Harry grab the most treasures in the shortest possible time. You start each adventure with 2000 points. Some misfortunes will cause a deduction of points. Should you fall down a hole by accident, you will lose 100 points. Rolling logs will also cause point loss depending on how long contact is made with them.

Each treasure you find will add points to your score. There are eight of each type of treasure in the entire game, 32 in all, for a total of 112,000 points. A perfect score is 114,000 points, reached by collecting all treasures without losing any points by falling down holes or tripping on logs.

You have 20 minutes to complete each adventure. Harry has 3 lives in each game.

There are 255 jungle scenes through which Harry can travel. Each scene covered underground is equivalent to three on the surface. Pitfall 4K is a circular maze, which means that, if Harry safely goes through all 255 different scenes, he will come back to the starting point. In the course of that journey, Harry will also encounter all 32 treasures.

Pitfall Harry's Jungle Adventure is fraught with danger. Some hazards will slow him down and rob you of points, while others will stop him cold in his tracks. The lesser hazards are the open holes in the ground and rolling logs. The catastrophic hazards are the scorpions, fires, cobra rattlers, crocodiles, swamps, quicksand and tar pits. These obstacles will not cost you points, but they will cost one of Harry's 3 lives.

Instructions

Use the arrow keys or the WASD keys to move. Press any other key to jump.

Press 8 to enable a secret compass that will guide you through the optimal pathway.

User Comments

Total 2 comments:

#1 By Chema Belmont Feb 29, 2012 at 09:32:58
Found it quite impressive. The controls are very precise. I\'m starting to learn how to make games in java and I guess I\'ll find this very useful. May the Force be with you!
#2 By Krzysiek K. Nov 2, 2012 at 15:34:32
I assume you know original Pitfall on Atari 2600 was 4k? (hardware limitations) :)

You need be logged in to write comments. If you need to register click here.

Source code

Note: We recommend you copy+paste this to a better editor. Some special character encoding may have been lost.

. * */ import java.applet.Applet; import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.awt.Color; import java.util.ArrayList; public class a extends Applet implements Runnable { // keys private boolean[] a = new boolean[32768]; @Override public void start() { enableEvents(8); new Thread(this).start(); } public void run() { final float GRAVITY = 0.05f; final int JUMP_SPEED = -1; final int UPPER_FLOOR_Y = 97; final int LOWER_FLOOR_Y = 152; final int UPPER_FLOOR_LOWER_Y = 142; final int LADDER_TOP_Y = 112; final int LADDER_BOTTOM_Y = 152; final int RIGHT = 0; final int LEFT = 1; final int VK_LEFT = 0x25; final int VK_RIGHT = 0x27; final int VK_UP = 0x26; final int VK_DOWN = 0x28; final int VK_JUMP = 0x42; final int VK_PAUSE = 0x50; final int VK_HINTS = 0x38; final int BACKGROUND_0 = 0; final int BACKGROUND_1 = 1; final int BACKGROUND_2 = 2; final int BACKGROUND_3 = 3; final int SPRITE_DIGIT_0 = 0; final int SPRITE_DIGIT_1 = 1; final int SPRITE_DIGIT_2 = 2; final int SPRITE_DIGIT_3 = 3; final int SPRITE_DIGIT_4 = 4; final int SPRITE_DIGIT_5 = 5; final int SPRITE_DIGIT_6 = 6; final int SPRITE_DIGIT_7 = 7; final int SPRITE_DIGIT_8 = 8; final int SPRITE_DIGIT_9 = 9; final int SPRITE_COLON = 10; final int SPRITE_ARROW_0 = 11; final int SPRITE_ARROW_1 = 12; final int SPRITE_ARROW_2 = 13; final int SPRITE_TREE_BRANCHES = 14; final int SPRITE_WATER = 15; final int SPRITE_TAR = 16; final int SPRITE_LEAVES_0 = 17; final int SPRITE_LEAVES_1 = 18; final int SPRITE_LEAVES_2 = 19; final int SPRITE_LEAVES_3 = 20; final int SPRITE_DIAMOND_RING = 21; final int SPRITE_GOLD_BAR_0 = 22; final int SPRITE_GOLD_BAR_1 = 23; final int SPRITE_SILVER_BAR_0 = 24; final int SPRITE_SILVER_BAR_1 = 25; final int SPRITE_BRICK_WALL = 26; final int SPRITE_SCORPION_0 = 27; final int SPRITE_SCORPION_1 = 28; final int SPRITE_MONEY_BAG = 29; final int SPRITE_CROCODILE_0 = 30; final int SPRITE_CROCODILE_1 = 31; final int SPRITE_RATTLESNAKE_0 = 32; final int SPRITE_RATTLESNAKE_1 = 33; final int SPRITE_FIRE = 34; final int SPRITE_LOG = 35; final int SPRITE_COPYRIGHT_0 = 36; final int SPRITE_COPYRIGHT_1 = 37; final int SPRITE_COPYRIGHT_2 = 38; final int SPRITE_COPYRIGHT_3 = 39; final int SPRITE_COPYRIGHT_4 = 40; final int SPRITE_COPYRIGHT_5 = 41; final int SPRITE_HARRY_CLIMBING = 42; final int SPRITE_HARRY_SWINGING = 43; final int SPRITE_HARRY_STANDING = 44; final int SPRITE_HARRY_RUNNING_0 = 45; final int SPRITE_HARRY_RUNNING_1 = 46; final int SPRITE_HARRY_RUNNING_2 = 47; final int SPRITE_HARRY_RUNNING_3 = 48; final int SPRITE_HARRY_RUNNING_4 = 49; // also jumping sprite final int SCENE_LADDER = 0; final int SCENE_LADDER_AND_HOLES = 1; final int SCENE_TAR_WITH_VINE = 2; final int SCENE_QUICKSAND_WITH_VINE = 3; final int SCENE_CROCODILES = 4; final int SCENE_SHIFTING_TAR_WITH_TREASURE = 5; final int SCENE_SHIFTING_TAR_WITH_VINE = 6; final int SCENE_SHIFTING_QUICKSAND = 7; final int ITEM_1_ROLLING_LOG = 0; final int ITEM_2_CLOSE_ROLLING_LOGS = 1; final int ITEM_2_FAR_ROLLING_LOGS = 2; final int ITEM_3_ROLLING_LOGS = 3; final int ITEM_1_STATIONARY_LOG = 4; final int ITEM_3_STATIONARY_LOGS = 5; final int ITEM_FIRE = 6; final int ITEM_RATTLESNAKE = 7; final int OBJECT_ARRAY_SIZE = 8; final int OBJECT_TYPE_LOG = 0; final int OBJECT_TYPE_FIRE = 1; final int OBJECT_TYPE_RATTLESNAKE = 2; final int OBJECT_TYPE_MONEY_BAG = 3; final int OBJECT_TYPE_SILVER_BRICK = 4; final int OBJECT_TYPE_GOLD_BRICK = 5; final int OBJECT_TYPE_DIAMOND_RING = 6; final int OBJECT_TYPE_SCORPION = 7; final int OBJECT_X = 0; final int OBJECT_Y = 1; final int OBJECT_SPRITE_INDEX = 2; final int OBJECT_SPRITE_DIRECTION = 3; final int OBJECT_ROLLING = 4; final int OBJECT_TYPE = 5; final int OBJECT_SPRITE_INDEX_2 = 6; final int BROWN = 0x69690F; // a final int DARK_BROWN = 0x484800; // b final int YELLOW = 0xFCFC54; // c final int LIGHT_ORANGE = 0xECC860; // d final int ORANGE = 0xFCBC74; // e final int RED = 0xA71A1A; // f final int YELLOW_GREEN = 0x86861D; // g final int PINK = 0xE46F6F; // h final int GREEN = 0x6E9C42; // i final int BLUE = 0x2D6D98; // j final int BLACK = 0x000000; // k final int DARK_GRAY = 0x8E8E8E; // l final int WHITE = 0xECECEC; // m final int GRAY = 0xD6D6D6; // n final int DARK_GREEN = 0x355F18; // o final int DARK_YELLOW = 0xBBBB35; // p final int DARKEST_GRAY = 0x6F6F6F; // q final int DARKEST_GREEN = 0x143C00; // r final int LIGHT_GREEN = 0x5CBA5C; // s final int[] COLORS = { BROWN, // 0 DARK_BROWN, // 1 YELLOW, // 2 LIGHT_ORANGE, // 3 ORANGE, // 4 RED, // 5 YELLOW_GREEN, // 6 PINK, // 7 GREEN, // 8 BLUE, // 9 BLACK, // 10 DARK_GRAY, // 11 WHITE, // 12 GRAY, // 13 DARK_GREEN, // 14 DARK_YELLOW, // 15 DARKEST_GRAY, // 16 DARKEST_GREEN, // 17 LIGHT_GREEN, // 18 }; final Color COLOR_DARK_BROWN = new Color(DARK_BROWN); final Color COLOR_BLACK = new Color(0); final Color COLOR_DARK_GREEN = new Color(DARK_GREEN); final Color COLOR_YELLOW_GREEN = new Color(YELLOW_GREEN); final Color COLOR_GREEN = new Color(GREEN); final Color COLOR_GRAY = new Color(GRAY); final Color COLOR_DARK_YELLOW = new Color(DARK_YELLOW); final String S = " nnnn nn nn nn nn nn nn nn nn nn nn nn nn " + " nnnn nn nnn nn nn nn nn nn nnn" + "n nnnn n nn nn nn nnnn nn nn nnnnnn " + " nnnn n nn nn nn nn nn n nn nnnn n" + "n nnn n nn n nn nnnnnn nn nn nn nnnnnn " + "nn nn nnnnn nn nn n nn nnnnn nnnn nn " + " n nn nnnnn nn nn nn nn nn nn nnnn nnnnnn n n " + " nn nn nn nn nn nn nnnn nn nn nn " + "nn nnnn nnnn nn nn nn nn nnnn nnnn nn nn nn nn " + "nn nn nnnnn nn n nn nnnn nn nn " + " nn nn nn nn nn nnnnnnnnn" + "nnnnnnn nn nn nn nn nn nn n nn nnn nn" + " nn nnnnnn nnnn nn nn nnnn nnnnnn nn nn nnn nn n " + " nn nn nn b bb bb bb bb bb bb bb bb bb bb bb" + " bbb bb bb bbbbbb j jjjj jjjjjj j" + "jjjjjj jjjjjjjj k kkkk kkkkkk kkkkk" + "kk kkkkkkkkooooooo oooooo oooo oo ooooooooooooooo o oooo " + " oo ooooooo oooo o oo oooooooooo ooooo oo " + " o mmm mmmmm mmm c ccc " + "cc cc c c c c c c cc cc ccc " + " m m m m m m " + " ccccc cccccc ccccccc ccccccc cccccc ccccc m " + " m m m m m m m ccccc " + "cccccc ccccccc ccccccc cccccc ccccc m " + " m m m m m lllll llllll l" + "llllll lllllll llllll lllll m m m " + " m m m m m lllll llllll lllllll l" + "llllll llllll lllll fff fff fff fff fff fff lllllll f fff" + " f f fff f f fff f lllllll fff fff fff fff fff fff lllllll f fff f f" + " fff f f fff f lllllll " + " mmm mm mm m m m m m mm m mmmmm m mmmm mmmm " + " mm mm m m m mmm mm mm" + " m m m m m m mm mm mmmmm mmmm mmmm m mm m m" + " m m qq qq qqq a qqq qq qq qq qq qq " + " qq qq qqqq qq qq qqqq qq qq qq qqq qqq qqq qqq qqqqq " + " r rr rrrrrrrr r r " + "r rr r r rrrrrrrrrr " + " r rrr r rrr r r rrr r rr rr rrr r r" + " rrrrrrrrrr f " + " kk kkk k kk kk k k kk kkkkk" + " k qqqqq q kkkkk kqqqqq qkkkkkkk f kk " + " kkk k kk kk k k kk kkkkk kqqqqq" + " qkkkkk kqqqqq qkkkkkkk d d dd dd " + " ddd ddd dddd ddddd eeeee eeee ee bbbb bbbb" + "bb bbb bbbbb bb aa aaaa aa aaa aaaa a " + "aaaaaa aa aaa aaaa a aaaaaa aa aa a aa a a aa a a aa a a " + "a aa nnnn n n n n nnnn n n nnnnn nnn " + " " + " nnn n n n n n n nnn nnn n n " + "n nnn nnnn n nnnn nn nn n n nnnn n nn n n nn n n" + "n n n nn n nn n n n n n nn nn " + " nnnn n n n n nn n n nn n nnn n nn n n " + " n n nnn n n n nnn n n n n n n n n n n n n" + "nnnnnn n nnn n n n n n nnn n n n n n nnn n n " + "nnn n n n n nnn n n n n " + " nnn n nn n nn nn n nnnnn n n nnnnn n n nnn nnn n n " + " n nnn nnn n n n nnn nnn " + " aa hh hh h " + " s ss ssss ssss sss sss ss ooo oooo " + "oo o o o oo o o o o o oo o o o o" + " oo aa hh h hh h h h ss s ssss s" + "s ss ss ss ss oo ooo oooo oo oooo o oo " + " oo aa " + " hh hh h ss ss ss s ssss sss ss" + " ss oo oo oo oo oo oo oo " + " ooo o oo aa hh hh h ss" + " ss sss sss s sssss ssss ss oo oo " + " ooo ooo o o ooo o o o o oo o " + " aa hh hh h ss ss ss ss " + " ss sss sss oo oo ooo ooo o o ooo" + "oo o o o o o oo aa hh hh " + " h ss ss ss ss sss sss ss oo" + " ooo oooo o oo oo o oo o o o o o o " + " o aa hh hh h ss ss sss" + " sss s sssss ssss ss oo ooo ooooo oo oo " + "oo o oo o oo ooo o aa hh" + " hh h ss ss s sssss sssss s ss s ss " + " ss ooo oooo oo oo o ooo o oo oo " + " "; ArrayList queue = new ArrayList(); int[] object; object = new int[OBJECT_ARRAY_SIZE]; queue.add(object); object[OBJECT_X] = 116; object[OBJECT_Y] = 111; object[OBJECT_SPRITE_INDEX] = SPRITE_LOG; object[OBJECT_SPRITE_DIRECTION] = LEFT; boolean[] collectedTreasures = new boolean[256]; BufferedImage[][] sprites = new BufferedImage[50][2]; BufferedImage image = new BufferedImage( 152, 192, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D)image.getGraphics(); Graphics2D g2 = null; int i; int j; int k = 0; int x; int y; int z; int treasures = 32; int score = 2000; int clockMinutes = 20; int clockSeconds = 0; int clockTicks = 0; int harryX = 8; int copyrightOffset = 0; int copyrightTimer = 0; int restartDelay = 0; int screen = 196; int screenIndex = 0; int scene = SCENE_LADDER; int background = BACKGROUND_3; int harryDirection = 0; int harryOffsetY = 0; int harrySprite = SPRITE_HARRY_STANDING; int harryRunTimer = 0; int harryCrushed = 0; int timer = 0; int vineTimer = 0; int extraLives = 2; int pitOffset = 0; int pitSprite = 0; int pitTimer = 0; int crocodileTimer = 0; int crocodileSprite = SPRITE_CROCODILE_0; boolean attractMode = true; boolean jumpReleased = true; boolean hintsKeyReleased = true; boolean pauseKeyReleased = true; boolean harryJumping = false; boolean harryClimbing = false; boolean harryClimbedDown = false; boolean harrySinking = false; boolean harrySwinging = false; boolean wallOnLeft = false; boolean resetScreen = false; boolean pit = false; boolean crocodiles = false; boolean shiftingPit = false; boolean vine = false; boolean harryLanded = true; boolean hintsEnabled = false; boolean paused = false; float harryY = UPPER_FLOOR_Y; float harryVy = 0; float harryVineRadius = 0; float vineAngle = 0; float vx = 0; float vy = 0; int vineX = 0; int vineY = 0; // decompress sprites for(i = 0; i < 50;="" i++)="" {="" j="(i">< 17)="" 8="" :="" (i="">< 21)="" 4="" :="" (i="">< 42)="" 16="" :="" 22;="" sprites[i][0]="new" bufferedimage(8,="" j,="" bufferedimage.type_int_argb_pre);="" sprites[i][1]="new" bufferedimage(8,="" j,="" bufferedimage.type_int_argb_pre);="" for(y="0;" y="">< j;="" y++)="" {="" for(x="0;" x="">< 8;="" x++,="" k++)="" {="" z="(S.charAt(k)" ==' ' )="" 0="" :="" (0xff000000="" |="" colors[s.charat(k)="" -="" 'a']);="" sprites[i][0].setrgb(x,="" y,="" z);="" sprites[i][1].setrgb(7="" -="" x,="" y,="" z);="" }="" }="" }="" long="" nextframestarttime="System.nanoTime();" while(true)="" {="" do="" {="" nextframestarttime="" +="16666667;" --="" update="" starts="" ----------------------------------------------------="" if="" (!a[vk_jump])="" {="" jumpreleased="true;" if="" (!a[vk_left]="" &&="" !a[vk_right])="" {="" harryclimbeddown="true;" }="" }="" if="" (!a[vk_hints])="" {="" hintskeyreleased="true;" }="" if="" (a[vk_hints]="" &&="" hintskeyreleased)="" {="" hintskeyreleased="false;" hintsenabled="!hintsEnabled;" }="" if="" (!a[vk_pause])="" {="" pausekeyreleased="true;" }="" if="" (a[vk_pause]="" &&="" pausekeyreleased)="" {="" pausekeyreleased="false;" paused="!paused;" }="" if="" (paused)="" {="" continue;="" }="" if="" (attractmode)="" {="" copyright="" animation="" copyrighttimer++;="" if="" (copyrighttimer="">= 120 && copyrightTimer <= 184)="" {="" copyrightoffset="(copyrightTimer" -="" 120)="">> 3; } else if (copyrightTimer > 274) { copyrightTimer = 0; copyrightOffset = 0; } if (restartDelay > 0) { // to prevent triggering an immediate reset accidentally // when you lose all lives or run out of time, there is a minimum // game over delay before key input is accepted again restartDelay--; } else if (a[VK_JUMP] || a[VK_UP] || a[VK_DOWN] || a[VK_LEFT] || a[VK_RIGHT]) { // press any key to start // reset game attractMode = false; harryJumping = false; harryClimbing = false; harryClimbedDown = false; harrySinking = false; harrySwinging = false; wallOnLeft = false; resetScreen = false; pit = false; crocodiles = false; vine = false; harryLanded = true; treasures = 32; score = 2000; clockMinutes = 20; clockSeconds = 0; clockTicks = 0; harryX = 8; harryY = UPPER_FLOOR_Y; harryVy = 0; screen = 196; screenIndex = 0; scene = SCENE_LADDER; background = BACKGROUND_3; harryDirection = 0; harryOffsetY = 0; harryCrushed = 0; timer = 0; vineTimer = 0; pitTimer = 0; crocodileTimer = 0; extraLives = 2; harrySprite = SPRITE_HARRY_STANDING; collectedTreasures = new boolean[256]; queue.clear(); object = new int[OBJECT_ARRAY_SIZE]; queue.add(object); object[OBJECT_X] = 116; object[OBJECT_Y] = 111; object[OBJECT_SPRITE_INDEX] = SPRITE_LOG; object[OBJECT_SPRITE_DIRECTION] = LEFT; } } else if (restartDelay > 0) { // Harry loses a life if (--restartDelay == 0) { if (extraLives > 0) { extraLives--; harryX = 12; harryY = harryY > UPPER_FLOOR_Y ? 127 : 26; harryVy = 0; harryDirection = RIGHT; resetScreen = true; harryJumping = true; harryClimbing = false; harryCrushed = 0; } else { // game over (out of extra lives) attractMode = true; restartDelay = 255; } } } else if (harrySinking) { harrySprite = SPRITE_HARRY_STANDING; // Harry is sinking! harryY++; if (harryY > 115) { // Harry fully sunk harrySinking = false; restartDelay = 60; harryY = 26; } } else { // update timer timer++; // fix the position of the copyright notice to display Activision logo copyrightOffset = 8; // update clock if (--clockTicks < 0)="" {="" clockticks="59;" if="" (--clockseconds="">< 0)="" {="" clockseconds="59;" if="" (--clockminutes="">< 0)="" {="" game="" over="" (time="" up)="" clockminutes="0;" clockseconds="0;" attractmode="true;" restartdelay="255;" }="" }="" }="" update="" crocodiles="" if="" (++crocodiletimer="=" 210)="" {="" crocodiletimer="0;" crocodilesprite="crocodileSprite" !="SPRITE_CROCODILE_0" sprite_crocodile_0="" :="" sprite_crocodile_1;="" }="" update="" vine="" if="" (vine)="" {="" vineangle="0.393f" *="" (float)math.sin(++vinetimer="" 46f);="" vx="(float)Math.sin(vineAngle);" vy="(float)Math.cos(vineAngle);" if="" (!harryswinging="" &&="" harryjumping="" &&="" harrylanded)="" {="" line="" intersection="" test="" with="" circle="" around="" harry="" x="harryX" +="" 4;="" y="(int)(harryY" +="" 4);="" float="" b="2" *="" (72="" *="" vx="" +="" 24="" *="" vy="" -="" vx="" *="" x="" -="" vy="" *="" y);="" float="" c="5744" -="" 144="" *="" x="" +="" x="" *="" x="" -="" 48="" *="" y="" +="" y="" *="" y;="" float="" d="B" *="" b="" -="" 4="" *="" c;="" if="" (d="">= 0) { harryVineRadius = (-B - (float)Math.sqrt(D)) / 2; harrySwinging = harryVineRadius <= 76;="" }="" }="" vinex="(int)(72" +="" 76="" *="" vx);="" viney="(int)(24" +="" 76="" *="" vy);="" }="" update="" pit="" if="" (++pittimer="=" 320)="" {="" pittimer="0;" }="" pitoffset="0;" if="" (shiftingpit)="" {="" if="" (pittimer=""></=>< 20)="" {="" pitoffset="pitTimer">> 2; } else if (pitTimer < 160)="" {="" pitoffset="5;" }="" else="" if="" (pittimer="">< 180)="" {="" pitoffset="4" -="" ((pittimer="" -="" 160)="">> 2); } } // control harry if (harrySwinging) { harrySprite = SPRITE_HARRY_SWINGING; harryX = (int)(69 + harryVineRadius * vx) - harryDirection; harryY = 21 + harryVineRadius * vy; if (jumpReleased && a[VK_JUMP]) { jumpReleased = false; harrySwinging = false; harryJumping = true; harryVy = JUMP_SPEED; harryLanded = false; } } else if (harryClimbing) { if (a[VK_DOWN]) { if (++harryRunTimer == 8) { harryRunTimer = 0; harryDirection ^= 1; harryY += 4; if (harryY >= LADDER_BOTTOM_Y) { harryClimbing = false; harryY = LOWER_FLOOR_Y; harryRunTimer = 0; } harryClimbedDown = true; } } else if (a[VK_UP]) { if (harryY > LADDER_TOP_Y && ++harryRunTimer == 8) { harryRunTimer = 0; harryDirection ^= 1; harryY -= 4; } } if (((jumpReleased && a[VK_JUMP]) || (harryClimbedDown && (a[VK_LEFT] || a[VK_RIGHT]))) && harryY == LADDER_TOP_Y) { jumpReleased = false; harryJumping = true; harryVy = JUMP_SPEED; harryClimbing = false; harryY = UPPER_FLOOR_Y; } } else { if (harryCrushed == 0) { if (a[VK_LEFT]) { harryDirection = LEFT; if ((timer & 1) == 0) { if ((harryX != 37 && harryX != 89) || harryY <= upper_floor_y="" ||="" harryy="">= UPPER_FLOOR_LOWER_Y) { harryX--; } } if (++harryRunTimer == 4) { harryRunTimer = 0; if (++harrySprite > SPRITE_HARRY_RUNNING_4) { harrySprite = SPRITE_HARRY_RUNNING_0; } } } else if (a[VK_RIGHT]) { harryDirection = RIGHT; if ((timer & 1) == 0) { if ((harryX != 47 && harryX != 99) || harryY <= upper_floor_y="" ||="" harryy="">= UPPER_FLOOR_LOWER_Y) { harryX++; } } if (++harryRunTimer == 4) { harryRunTimer = 0; if (++harrySprite > SPRITE_HARRY_RUNNING_4) { harrySprite = SPRITE_HARRY_RUNNING_0; } } } else { harrySprite = SPRITE_HARRY_STANDING; } } if (scene <= scene_ladder_and_holes="" &&="" harryy=""> UPPER_FLOOR_Y) { if (wallOnLeft) { if (harryX == 4) { harrySprite = SPRITE_HARRY_STANDING; harryRunTimer = 0; harryX = 3; } else if (harryX == 15) { harrySprite = SPRITE_HARRY_STANDING; harryRunTimer = 0; harryX = 16; } } else { if (harryX == 122) { harrySprite = SPRITE_HARRY_STANDING; harryRunTimer = 0; harryX = 121; } else if (harryX == 133) { harrySprite = SPRITE_HARRY_STANDING; harryRunTimer = 0; harryX = 134; } } } if (harryJumping) { harrySprite = SPRITE_HARRY_RUNNING_4; i = (int)harryY; harryY += harryVy; harryVy += GRAVITY; if (i <= upper_floor_y="" &&="" (int)harryy="">= UPPER_FLOOR_Y) { harryJumping = false; harryLanded = true; harryY = UPPER_FLOOR_Y; } else if (i <= lower_floor_y="" &&="" (int)harryy="">= LOWER_FLOOR_Y) { harryJumping = false; harryLanded = true; harryY = LOWER_FLOOR_Y; } } else if (jumpReleased && a[VK_JUMP] && harryCrushed == 0) { jumpReleased = false; harryJumping = true; harryVy = JUMP_SPEED; } if (!harryJumping && scene <= scene_ladder_and_holes)="" {="" if="" (harryx="">= 65 && harryX <= 71="" &&="" (harryy="=" upper_floor_y="" ||="" a[vk_up]))="" {="" harry="" clings="" to="" top="" of="" ladder="" harryclimbing="true;" harryx="68;" harrysprite="SPRITE_HARRY_CLIMBING;" harryruntimer="0;" if="" (harryy="=" upper_floor_y)="" {="" harryy="LADDER_TOP_Y;" harryclimbeddown="false;" }="" else="" {="" harryy="LADDER_BOTTOM_Y;" harryclimbeddown="true;" }="" }="" else="" if="" (harryy="=" upper_floor_y="" &&="" scene="=" scene_ladder_and_holes)="" {="" if="" ((harryx="">= 37 && harryX <= 47)="" ||="" (harryx="">= 89 && harryX <= 99))="" {="" harryjumping="true;" harryy++;="" score="" -="100;" lose="" 100="" points="" for="" falling="" into="" a="" pit="" if="" (score=""></=>< 0)="" {="" score="0;" }="" }="" }="" }="" }="" harry="" sinking="" test="" harrysinking="harryY" =="UPPER_FLOOR_Y" &&="" pit="" &&="" pitoffset="">< 5="" &&="" harryx="">= 36 && harryX <= 100="" &&="" (image.getrgb(harryx,="" 119)="" &="" 0xffffff)="" !="DARK_YELLOW" &&="" (image.getrgb(harryx="" +="" 7,="" 119)="" &="" 0xffffff)="" !="DARK_YELLOW;" if="" (crocodiles)="" {="" for(i="0;" i=""></=>< 3;="" i++)="" {="" if="" (harryx=""><= 56="" +="" (i=""></=>< 4)="" &&="" harryx="">= 48 + 6 * (crocodileSprite - SPRITE_CROCODILE_0) + (i < 4))="" {="" harrysinking="false;" }="" }="" }="" process="" queue="" harryoffsety="0;" if="" (harrycrushed=""> 0) { harryCrushed--; } for(i = queue.size() - 1; i >= 0; i--) { object = queue.get(i); j = object[OBJECT_TYPE]; x = object[OBJECT_X]; y = object[OBJECT_Y]; if (j == OBJECT_TYPE_LOG) { // update logs if (object[OBJECT_ROLLING] == 1) { object[OBJECT_Y] = (timer & 15) < 2="" 112="" :="" 111;="" if="" ((timer="" &="" 3)="=" 0)="" {="" object[object_sprite_direction]="" ^="1;" }="" if="" ((timer="" &="" 1)="=" 0="" &&="" --object[object_x]="">< -8)="" {="" object[object_x]="152;" }="" }="" }="" else="" if="" (j="=" object_type_scorpion)="" {="" update="" scorpion="" if="" ((timer="" &="" 7)="=" 0)="" {="" if="" (object[object_sprite_direction]="=" left)="" {="" if="" (--object[object_x]="">< harryx="" -="" 16)="" {="" object[object_sprite_direction]="RIGHT;" }="" }="" else="" {="" if="" (++object[object_x]=""> harryX + 16) { object[OBJECT_SPRITE_DIRECTION] = LEFT; } } object[OBJECT_SPRITE_INDEX] = object[OBJECT_SPRITE_INDEX] != SPRITE_SCORPION_0 ? SPRITE_SCORPION_0 : SPRITE_SCORPION_1; } } if ((timer & 1) == 0 && Math.random() < 0.5f)="" {="" rattle="" object="" if="" (j="=" object_type_fire)="" {="" object[object_sprite_direction]="" ^="1;" }="" else="" if="" (j="=" object_type_rattlesnake="" ||="" j="=" object_type_silver_brick="" ||="" j="=" object_type_gold_brick)="" {="" object[object_sprite_index]="object[OBJECT_SPRITE_INDEX]" !="object[OBJECT_SPRITE_INDEX_2]" object[object_sprite_index_2]="" :="" object[object_sprite_index_2]="" +="" 1;="" }="" }="" if="" (!harryswinging="" &&="" harryx="">= x - 4 && harryX <= x="" +="" 4="" &&="" harryy="">= y - 16 + (j == OBJECT_TYPE_SCORPION ? 6 : 0) && harryY <= y="" +="" 1)="" {="" harry="" collides="" with="" object="" if="" (j="=" object_type_fire="" ||="" j="=" object_type_rattlesnake="" ||="" j="=" object_type_scorpion)="" {="" harry="" collides="" with="" deadly="" object="" restartdelay="60;" }="" else="" if="" (j="">= OBJECT_TYPE_MONEY_BAG && j <= object_type_diamond_ring)="" {="" harry="" collects="" teasure="" queue.remove(i);="" collectedtreasures[screenindex]="true;" score="" +="(j" -="" object_type_money_bag="" +="" 2)="" *="" 1000;="" if="" (--treasures="=" 0)="" {="" game="" over="" (collected="" all="" treasures)="" attractmode="true;" restartdelay="255;" }="" }="" else="" if="" (j="=" object_type_log)="" {="" harry="" collides="" with="" log="" if="" (!harryclimbing)="" {="" harrysprite="SPRITE_HARRY_RUNNING_4;" harryoffsety="5;" }="" if="" (object[object_rolling]="=" 1)="" {="" harrycrushed="2;" }="" score--;="" lose="" a="" point="" for="" colliding="" with="" log="" if="" (score=""></=>< 0)="" {="" score="0;" }="" }="" }="" }="" i="screen;" if="" (harryx=""> 150) { // Harry advances one screen to the right for(i = harryY > UPPER_FLOOR_Y ? 3 : 1; i > 0; i--) { screen = 0xFF & ((screen < 1)="" |="" ((1="" &="" (screen="">> 3)) ^ (1 & (screen >> 4)) ^ (1 & (screen >> 5)) ^ (1 & (screen >> 7)))); if (++screenIndex > 254) { screenIndex = 0; } } harryX = 0; } else if (harryX < -6)="" {="" harry="" advances="" one="" screen="" to="" the="" left="" for(i="harryY"> UPPER_FLOOR_Y ? 3 : 1; i > 0; i--) { screen = 0xFF & ((screen >> 1) | ((1 & (screen >> 4)) ^ (1 & (screen >> 5))^ (1 & (screen >> 6)) ^ (1 & screen)) < 7);="" if="" (--screenindex="">< 0)="" {="" screenindex="254;" }="" }="" harryx="140;" }="" if="" (i="" !="screen" ||="" resetscreen="=" true)="" {="" create="" scene="" resetscreen="false;" background="screen">> 6; scene = (screen >> 3) & 7; wallOnLeft = (screen & 128) == 0; queue.clear(); // create crocodiles crocodiles = scene == SCENE_CROCODILES; // create vine vine = scene == SCENE_TAR_WITH_VINE || scene == SCENE_QUICKSAND_WITH_VINE || scene == SCENE_SHIFTING_TAR_WITH_VINE || (scene == SCENE_CROCODILES && (screen & 2) == 2); // create pit pitSprite = scene == SCENE_TAR_WITH_VINE || scene == SCENE_SHIFTING_TAR_WITH_TREASURE || scene == SCENE_SHIFTING_TAR_WITH_VINE ? SPRITE_TAR : SPRITE_WATER; shiftingPit = scene > SCENE_CROCODILES; pitOffset = 0; if (shiftingPit) { if (pitTimer < 20)="" {="" pitoffset="pitTimer">> 2; } else if (pitTimer < 160)="" {="" pitoffset="5;" }="" else="" if="" (pittimer="">< 180)="" {="" pitoffset="4" -="" ((pittimer="" -="" 160)="">> 2); } } if (pit = (scene > SCENE_LADDER_AND_HOLES)) { // create scorpion object = new int[OBJECT_ARRAY_SIZE]; queue.add(object); object[OBJECT_X] = 68; object[OBJECT_Y] = 158; object[OBJECT_SPRITE_INDEX] = SPRITE_SCORPION_0; object[OBJECT_TYPE] = OBJECT_TYPE_SCORPION; object[OBJECT_SPRITE_DIRECTION] = harryX == 0 ? LEFT : RIGHT; } if (scene == SCENE_SHIFTING_TAR_WITH_TREASURE) { if (!collectedTreasures[screenIndex]) { // create treasure j = screen & 3; object = new int[OBJECT_ARRAY_SIZE]; queue.add(object); object[OBJECT_X] = 116; object[OBJECT_Y] = 111; object[OBJECT_SPRITE_INDEX_2] = object[OBJECT_SPRITE_INDEX] = j == 0 ? SPRITE_MONEY_BAG : j == 1 ? SPRITE_SILVER_BAR_0 : j == 2 ? SPRITE_GOLD_BAR_0 : SPRITE_DIAMOND_RING; object[OBJECT_TYPE] = j + OBJECT_TYPE_MONEY_BAG; } } else if (scene != SCENE_CROCODILES) { // create logs, rattle snakes and fire j = screen & 7; for(i = 0; i < ((j="=" item_2_close_rolling_logs="" ||="" j="=" item_2_far_rolling_logs)="" 2="" :="" ((j="=" item_3_rolling_logs="" ||="" j="=" item_3_stationary_logs)="" 3="" :="" 1));="" i++)="" {="" object="new" int[object_array_size];="" queue.add(object);="" object[object_x]="((i">< (j="=" item_2_close_rolling_logs="" 4="" :="" 5))="" +="" 116)="" %="" 160;="" object[object_y]="111;" object[object_sprite_index]="object[OBJECT_SPRITE_INDEX_2]" =="" j="=" 6="" sprite_fire="" :="" j="=" 7="" sprite_rattlesnake_0="" :="" sprite_log;="" object[object_type]="j" =="6" object_type_fire="" :="" j="=" 7="" object_type_rattlesnake="" :="" object_type_log;="" object[object_rolling]="(j">> 2) ^ 1; object[OBJECT_SPRITE_DIRECTION] = j < 6="" left="" :="" right;="" }="" }="" }="" }="" --="" update="" ends="" ------------------------------------------------------="" }="" while(nextframestarttime="">< system.nanotime());="" --="" render="" starts="" ------------------------------------------------------="" clear="" frame="" g.setcolor(color_black);="" g.fillrect(0,="" 0,="" 152,="" 210);="" draw="" forest="" g.setcolor(color_green);="" g.fillrect(0,="" 46,="" 152,="" 65);="" draw="" tree="" trunks="" and="" branches="" g.setcolor(color_dark_brown);="" for(i="0;" i="">< 2;="" i++)="" {="" j="((background" +="" 1)="">< 3)="" +="" (i="">< 5);="" if="" (background="=" 3)="" {="" j="" -="4;" }="" g.fillrect(j,="" 59,="" 4,="" 52);="" g.fillrect(140="" -="" j,="" 59,="" 4,="" 52);="" g.drawimage(sprites[sprite_tree_branches][0],="" j="" -="" 2,="" 51,="" null);="" g.drawimage(sprites[sprite_tree_branches][0],="" 138="" -="" j,="" 51,="" null);="" }="" draw="" vine="" if="" (vine)="" {="" g.drawline(72,="" 24,="" vinex,="" viney);="" }="" draw="" lower="" floor="" g.setcolor(color_yellow_green);="" g.fillrect(0,="" 174,="" 152,="" 6);="" g.fillrect(0,="" 127,="" 152,="" 15);="" draw="" upper="" floor="" g.setcolor(color_dark_yellow);="" g.fillrect(0,="" 111,="" 152,="" 11);="" if="" (scene=""><= scene_ladder_and_holes)="" {="" draw="" holes="" g.setcolor(color_black);="" if="" (scene="=" scene_ladder_and_holes)="" {="" g.fillrect(40,="" 116,="" 12,="" 26);="" left="" hole="" g.fillrect(92,="" 116,="" 12,="" 26);="" right="" hole="" }="" g.fillrect(68,="" 116,="" 8,="" 26);="" center="" hole="" draw="" ladder="" g.setcolor(color_yellow_green);="" for(i="0;" i=""></=>< 11;="" i++)="" {="" g.fillrect(70,="" 130="" +="" (i="">< 2),="" 4,="" 2);="" }="" draw="" brick="" wall="" g.drawimage(sprites[sprite_brick_wall][0],="" wallonleft="" 10="" :="" 128,="" 142,="" null);="" g.drawimage(sprites[sprite_brick_wall][0],="" wallonleft="" 10="" :="" 128,="" 158,="" null);="" }="" if="" (pit)="" {="" draw="" top="" of="" pit="" behind="" harry="" g.setclip(40,="" 111,="" 64,="" 8);="" g.drawimage(sprites[pitsprite][1],="" 40,="" 111="" +="" pitoffset,="" 32,="" 8,="" null);="" g.drawimage(sprites[pitsprite][0],="" 72,="" 111="" +="" pitoffset,="" 32,="" 8,="" null);="" if="" (crocodiles)="" {="" draw="" crocodile="" tops="" for(i="0;" i="">< 3;="" i++)="" {="" g.drawimage(sprites[crocodilesprite][0],="" 52="" +="" (i="">< 4),="" 111,="" null);="" }="" }="" g.setclip(null);="" }="" draw="" harry="" g.drawimage(sprites[harrysprite][harrydirection],="" harryx,="" harryoffsety="" +="" (int)harryy,="" null);="" if="" (scene=""> SCENE_LADDER_AND_HOLES) { // draw lower floor strip in front of Harry g.setColor(COLOR_YELLOW_GREEN); g.fillRect(0, 127, 152, 15); } // draw upper floor strip g.setColor(COLOR_DARK_YELLOW); g.fillRect(0, 122, 152, 5); if (pit) { // draw bottom of pit in front of Harry g.fillRect(40, 119, 64, 8); g.setClip(40, 119, 64, 8); g.drawImage(sprites[pitSprite][1], 40, 127 - pitOffset, 32, -8, null); g.drawImage(sprites[pitSprite][0], 72, 127 - pitOffset, 32, -8, null); if (crocodiles) { // draw crocodile bottoms for(i = 0; i < 3;="" i++)="" {="" g.drawimage(sprites[crocodilesprite][0],="" 52="" +="" (i="">< 4),="" 111,="" null);="" }="" }="" g.setclip(null);="" }="" draw="" tree="" tops="" g.setcolor(color_dark_green);="" g.fillrect(0,="" 0,="" 152,="" 51);="" draw="" tree="" leaves="" for(i="0;" i="">< 6;="" i++)="" {="" g.drawimage(sprites[sprite_leaves_3="" -="" background][1="" -="" (i="" &="" 1)],="" (i="">< 5)="" -="" 24,="" 51,="" 32,="" 8,="" null);="" }="" draw="" queue="" objects="" for(i="queue.size()" -="" 1;="" i="">= 0; i--) { object = queue.get(i); g.drawImage(sprites[object[OBJECT_SPRITE_INDEX]] [object[OBJECT_SPRITE_DIRECTION]], object[OBJECT_X], object[OBJECT_Y], null); } // draw score j = score; x = 53; do { g.drawImage(sprites[SPRITE_DIGIT_0 + (j % 10)][0], x, 3, null); x -= 8; j /= 10; } while(j > 0); // draw seconds j = clockSeconds; x = 53; do { g.drawImage(sprites[SPRITE_DIGIT_0 + (j % 10)][0], x, 16, null); x -= 8; j /= 10; } while(x > 37); // draw minutes j = clockMinutes; x = 29; do { g.drawImage(sprites[SPRITE_DIGIT_0 + (j % 10)][0], x, 16, null); x -= 8; j /= 10; } while(j > 0); // draw clock colon g.drawImage(sprites[SPRITE_COLON][0], 37, 16, null); // draw extra lives g.setColor(COLOR_GRAY); if (extraLives > 0) { g.fillRect(13, 16, 1, 8); } if (extraLives > 1) { g.fillRect(15, 16, 1, 8); } // draw copyright g.setClip(13, 183, 48, 8); for(i = 0; i < 6;="" i++)="" {="" g.drawimage(sprites[sprite_copyright_0="" +="" i][0],="" 13="" +="" (i="">< 3),="" 183="" -="" copyrightoffset,="" null);="" }="" g.setclip(null);="" if="" (hintsenabled)="" {="" hint="" map="" i="" and="" j="" are="" not="" necessary="" here,="" but="" it="" is="" easier="" to="" read!="" i="(harryY">< 124="" &&="" (screenindex="=" 11="" ||="" screenindex="=" 37="" ||="" screenindex="=" 116="" ||="" screenindex="=" 185="" ||="" screenindex="=" 224="" ||="" screenindex="=" 235))="" sprite_arrow_1="" :="" (harryy="">= 124 && (screenIndex == 25 || screenIndex == 92 || screenIndex == 179 || screenIndex == 209 || screenIndex == 226 || screenIndex == 245)) ? SPRITE_ARROW_2 : SPRITE_ARROW_0; j = harryY < 124="" &&="" ((screenindex="">= 0 && screenIndex < 11)="" ||="" (treasures="=" 30="" &&="" screenindex="">= 226 && screenIndex <= 228)="" ||="" (treasures="=" 13="" &&="" screenindex="">= 92 && screenIndex <= 95)="" ||="" (treasures="=" 1="" &&="" screenindex="">= 25 && screenIndex <= 28))="" right="" :="" left;="" g.drawimage(sprites[i][j],="" 136,="" 11,="" null);="" }="" --="" render="" ends="" --------------------------------------------------------="" show="" the="" hidden="" buffer="" if="" (g2="=" null)="" {="" g2="(Graphics2D)getGraphics();" requestfocus();="" }="" else="" {="" g2.drawimage(image,="" 0,="" 0,="" 608,="" 384,="" null);="" }="" burn="" off="" extra="" cycles="" while(nextframestarttime="" -="" system.nanotime()=""> 0) { Thread.yield(); } } } @Override public void processKeyEvent(KeyEvent keyEvent) { final int VK_LEFT = 0x25; final int VK_RIGHT = 0x27; final int VK_UP = 0x26; final int VK_DOWN = 0x28; final int VK_JUMP = 0x42; final int VK_W = 0x57; final int VK_S = 0x53; final int VK_A = 0x41; final int VK_D = 0x44; final int VK_PAUSE = 0x50; // press p for pause final int VK_HINTS = 0x38; // press 8 for hint map int k = keyEvent.getKeyCode(); if (k > 0) { k = k == VK_W ? VK_UP : k == VK_D ? VK_RIGHT : k == VK_A ? VK_LEFT : k == VK_S ? VK_DOWN : k; a[(k >= VK_LEFT && k <= vk_down)="" ||="" k="=" vk_hints="" ||="" k="=" vk_pause="" k="" :="" vk_jump]="keyEvent.getID()" !="402;" }="" }="" to="" run="" in="" window,="" uncomment="" below="" public="" static="" void="" main(string[]="" args)="" throws="" throwable="" {="" javax.swing.jframe="" frame="new" javax.swing.jframe("pitfall="" 4k");="" frame.setdefaultcloseoperation(javax.swing.jframe.exit_on_close);="" a="" applet="new" a();="" applet.setpreferredsize(new="" java.awt.dimension(608,="" 384));="" frame.add(applet,="" java.awt.borderlayout.center);="" frame.setresizable(false);="" frame.pack();="" frame.setlocationrelativeto(null);="" frame.setvisible(true);="" thread.sleep(250);="" applet.start();="" }*/="" }=""></=></=></=></=></=></=></=></=></=></=></=></=></=></=></=>