Rewrote death on falling into a river; added arrow keys
This commit is contained in:
parent
7102b8eefc
commit
34dfd67a50
20
sketch.js
20
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user