Rewrote death on falling into a river; added arrow keys

This commit is contained in:
Mottributo 2023-03-25 23:01:09 +03:00
parent 7102b8eefc
commit 34dfd67a50

View File

@ -3,6 +3,7 @@ var cameraPosX;
var camera_speed; var camera_speed;
var processStop_timer; var processStop_timer;
var fps_recent_values = []; var fps_recent_values = [];
var death_timer;
var showDebugData = false; var showDebugData = false;
var gameChar; var gameChar;
@ -476,6 +477,7 @@ function draw() {
} }
// Doing plummeting // Doing plummeting
if (gameChar.isPlummeting) { if (gameChar.isPlummeting) {
if (death_timer == undefined) death_timer = frameCount;
gameChar.y += 3; gameChar.y += 3;
} }
// Drawing a sprite // Drawing a sprite
@ -807,9 +809,10 @@ function checkFlagpole() {
} }
} }
function checkPlayerDie() { function checkPlayerDie() {
if (gameChar.y >= height) { if (frameCount - death_timer > 60) {
if (gameChar.curLives > 1) { if (gameChar.curLives > 1) {
gameChar.curLives--; gameChar.curLives--;
death_timer = undefined;
startGame(); startGame();
} else if (gameChar.curLives == 1) { } else if (gameChar.curLives == 1) {
gameChar.curLives--; gameChar.curLives--;
@ -842,13 +845,14 @@ function keyPressed() {
startGame((level_start = true)); startGame((level_start = true));
} }
} else if (!gameChar.isPlummeting) { } else if (!gameChar.isPlummeting) {
if (keyCode == 65 /*A*/) gameChar.isLeft = true; if (keyCode == 65 /*A*/ || keyCode == LEFT_ARROW) gameChar.isLeft = true;
if (keyCode == 68 /*D*/) gameChar.isRight = true; if (keyCode == 68 /*D*/ || keyCode == RIGHT_ARROW) gameChar.isRight = true;
if (keyCode == 83 /*S*/) gameChar.goDown(); if (keyCode == 83 /*S*/ || keyCode == DOWN_ARROW) gameChar.goDown();
if (keyCode == 87 /*W*/) gameChar.goUp(); 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 // Rewrote jumping routine to make it more natural and be able to support platforms and different player dimensions
if ( if (
keyCode == 32 /*Space*/ && (keyCode == 32 /*Space*/ ||
keyCode == 88 /*X*/) &&
!gameChar.isFalling && !gameChar.isFalling &&
!gameChar.isJumping !gameChar.isJumping
) { ) {
@ -860,6 +864,6 @@ function keyPressed() {
} }
function keyReleased() { function keyReleased() {
console.log(frameCount + " released " + key + " " + keyCode); console.log(frameCount + " released " + key + " " + keyCode);
if (keyCode == 65 /*A*/) gameChar.isLeft = false; if (keyCode == 65 /*A*/ || keyCode == LEFT_ARROW) gameChar.isLeft = false;
if (keyCode == 68 /*D*/) gameChar.isRight = false; if (keyCode == 68 /*D*/ || keyCode == RIGHT_ARROW) gameChar.isRight = false;
} }