began work on platforms; moved setting sprite code

This commit is contained in:
Mottributo 2023-03-25 23:38:52 +03:00
parent 34dfd67a50
commit d1c0001865

View File

@ -17,6 +17,8 @@ var clouds = [];
var mountains = []; var mountains = [];
var collectables = []; var collectables = [];
var rivers = []; var rivers = [];
var platforms = [];
var enemies = [];
var flagpole; var flagpole;
var text_size; var text_size;
@ -86,14 +88,34 @@ function startGame(level_start) {
speed: 5, speed: 5,
baseLives: 3, baseLives: 3,
curLives: 3, curLives: 3,
baseJumpingStrength: 15,
curJumpingStrength: 0,
isRight: false, isRight: false,
isLeft: false, isLeft: false,
isFalling: false, isFalling: false,
isJumping: false, isJumping: false,
isPlummeting: false, isPlummeting: false,
curGroundIndex: 0, curGroundIndex: 0,
_updateSprite: function()
{
if (gameChar.isPlummeting) {
gameChar.sprite = 2;
} else if (gameChar.isFalling) {
gameChar.sprite = 2;
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 5;
else if (gameChar.isRight && !gameChar.isLeft)
gameChar.sprite = 6;
} else {
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 4;
else if (gameChar.isRight && !gameChar.isLeft)
gameChar.sprite = 3;
else gameChar.sprite = 1;
}
},
draw: function () { draw: function () {
this._updateSprite();
push(); push();
strokeWeight(1); strokeWeight(1);
stroke(1); stroke(1);
@ -379,6 +401,16 @@ function startGame(level_start) {
} }
} }
} }
for (i = 0; i < 100; i++) {
if (i == 0) {
platforms[0] = {
curGroundIndex: 0,
x: 700,
width: 50,
y: pow(gameChar.baseJumpingStrength, 2) / 2,
}
}
}
} }
} else { } else {
gameChar.x = width / 2; gameChar.x = width / 2;
@ -442,15 +474,15 @@ function draw() {
} }
if (gameChar.isJumping) { if (gameChar.isJumping) {
gameChar.y -= gameChar.jumpingStrength; gameChar.y -= gameChar.curJumpingStrength;
gameChar.jumpingStrength -= gravity; gameChar.curJumpingStrength -= gravity;
if (gameChar.jumpingStrength <= 0) { if (gameChar.curJumpingStrength <= 0) {
gameChar.isFalling = true; gameChar.isFalling = true;
gameChar.isJumping = false; gameChar.isJumping = false;
} }
} else if (gameChar.isFalling) { } else if (gameChar.isFalling) {
gameChar.y -= gameChar.jumpingStrength; gameChar.y -= gameChar.curJumpingStrength;
gameChar.jumpingStrength -= gravity; gameChar.curJumpingStrength -= gravity;
if (gameChar.y >= gameChar.getCurGroundY()) { if (gameChar.y >= gameChar.getCurGroundY()) {
gameChar.y = gameChar.getCurGroundY(); gameChar.y = gameChar.getCurGroundY();
gameChar.isFalling = false; gameChar.isFalling = false;
@ -459,22 +491,6 @@ function draw() {
} }
} }
checkPlayerDie(); checkPlayerDie();
// Setting sprite
{
if (gameChar.isPlummeting) {
gameChar.sprite = 2;
} else if (gameChar.isFalling) {
gameChar.sprite = 2;
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 5;
else if (gameChar.isRight && !gameChar.isLeft)
gameChar.sprite = 6;
} else {
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 4;
else if (gameChar.isRight && !gameChar.isLeft)
gameChar.sprite = 3;
else gameChar.sprite = 1;
}
}
// Doing plummeting // Doing plummeting
if (gameChar.isPlummeting) { if (gameChar.isPlummeting) {
if (death_timer == undefined) death_timer = frameCount; if (death_timer == undefined) death_timer = frameCount;
@ -857,7 +873,7 @@ function keyPressed() {
!gameChar.isJumping !gameChar.isJumping
) { ) {
gameChar.isJumping = true; gameChar.isJumping = true;
gameChar.jumpingStrength = 15; gameChar.curJumpingStrength = gameChar.baseJumpingStrength;
} }
} }
if (keyCode == 77 /*M*/) showDebugData = !showDebugData; if (keyCode == 77 /*M*/) showDebugData = !showDebugData;