From d1c000186557f9fb2876fe84e92049f31fe72627 Mon Sep 17 00:00:00 2001 From: Mottributo <87079566+Mottributo@users.noreply.github.com> Date: Sat, 25 Mar 2023 23:38:52 +0300 Subject: [PATCH] began work on platforms; moved setting sprite code --- sketch.js | 62 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/sketch.js b/sketch.js index 361c8c4..5351380 100644 --- a/sketch.js +++ b/sketch.js @@ -17,6 +17,8 @@ var clouds = []; var mountains = []; var collectables = []; var rivers = []; +var platforms = []; +var enemies = []; var flagpole; var text_size; @@ -86,14 +88,34 @@ function startGame(level_start) { speed: 5, baseLives: 3, curLives: 3, + baseJumpingStrength: 15, + curJumpingStrength: 0, isRight: false, isLeft: false, isFalling: false, isJumping: false, isPlummeting: false, 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 () { + this._updateSprite(); push(); strokeWeight(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 { gameChar.x = width / 2; @@ -442,15 +474,15 @@ function draw() { } if (gameChar.isJumping) { - gameChar.y -= gameChar.jumpingStrength; - gameChar.jumpingStrength -= gravity; - if (gameChar.jumpingStrength <= 0) { + gameChar.y -= gameChar.curJumpingStrength; + gameChar.curJumpingStrength -= gravity; + if (gameChar.curJumpingStrength <= 0) { gameChar.isFalling = true; gameChar.isJumping = false; } } else if (gameChar.isFalling) { - gameChar.y -= gameChar.jumpingStrength; - gameChar.jumpingStrength -= gravity; + gameChar.y -= gameChar.curJumpingStrength; + gameChar.curJumpingStrength -= gravity; if (gameChar.y >= gameChar.getCurGroundY()) { gameChar.y = gameChar.getCurGroundY(); gameChar.isFalling = false; @@ -459,22 +491,6 @@ function draw() { } } 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 if (gameChar.isPlummeting) { if (death_timer == undefined) death_timer = frameCount; @@ -857,7 +873,7 @@ function keyPressed() { !gameChar.isJumping ) { gameChar.isJumping = true; - gameChar.jumpingStrength = 15; + gameChar.curJumpingStrength = gameChar.baseJumpingStrength; } } if (keyCode == 77 /*M*/) showDebugData = !showDebugData;