From 34dfd67a500f701573fe413b070607659fe26738 Mon Sep 17 00:00:00 2001 From: Mottributo <87079566+Mottributo@users.noreply.github.com> Date: Sat, 25 Mar 2023 23:01:09 +0300 Subject: [PATCH] Rewrote death on falling into a river; added arrow keys --- sketch.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sketch.js b/sketch.js index 4171510..361c8c4 100644 --- a/sketch.js +++ b/sketch.js @@ -3,6 +3,7 @@ var cameraPosX; var camera_speed; var processStop_timer; var fps_recent_values = []; +var death_timer; var showDebugData = false; var gameChar; @@ -476,6 +477,7 @@ function draw() { } // Doing plummeting if (gameChar.isPlummeting) { + if (death_timer == undefined) death_timer = frameCount; gameChar.y += 3; } // Drawing a sprite @@ -807,9 +809,10 @@ function checkFlagpole() { } } function checkPlayerDie() { - if (gameChar.y >= height) { + if (frameCount - death_timer > 60) { if (gameChar.curLives > 1) { gameChar.curLives--; + death_timer = undefined; startGame(); } else if (gameChar.curLives == 1) { gameChar.curLives--; @@ -842,13 +845,14 @@ function keyPressed() { startGame((level_start = true)); } } else if (!gameChar.isPlummeting) { - if (keyCode == 65 /*A*/) gameChar.isLeft = true; - if (keyCode == 68 /*D*/) gameChar.isRight = true; - if (keyCode == 83 /*S*/) gameChar.goDown(); - if (keyCode == 87 /*W*/) gameChar.goUp(); + if (keyCode == 65 /*A*/ || keyCode == LEFT_ARROW) gameChar.isLeft = true; + if (keyCode == 68 /*D*/ || keyCode == RIGHT_ARROW) gameChar.isRight = true; + if (keyCode == 83 /*S*/ || keyCode == DOWN_ARROW) gameChar.goDown(); + if (keyCode == 87 /*W*/ || keyCode == UP_ARROW) gameChar.goUp(); // Rewrote jumping routine to make it more natural and be able to support platforms and different player dimensions if ( - keyCode == 32 /*Space*/ && + (keyCode == 32 /*Space*/ || + keyCode == 88 /*X*/) && !gameChar.isFalling && !gameChar.isJumping ) { @@ -860,6 +864,6 @@ function keyPressed() { } function keyReleased() { console.log(frameCount + " released " + key + " " + keyCode); - if (keyCode == 65 /*A*/) gameChar.isLeft = false; - if (keyCode == 68 /*D*/) gameChar.isRight = false; + if (keyCode == 65 /*A*/ || keyCode == LEFT_ARROW) gameChar.isLeft = false; + if (keyCode == 68 /*D*/ || keyCode == RIGHT_ARROW) gameChar.isRight = false; }