From 37c51d7db8d3d75bfbc85970615dc158157308cd Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 2 Dec 2022 14:29:12 +0100 Subject: [PATCH] fix map generation --- js/Env.js | 2 +- js/Player.js | 15 ++++----------- js/main.js | 2 +- js/utils.js | 10 ++-------- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/js/Env.js b/js/Env.js index 80750ea..d9bd461 100644 --- a/js/Env.js +++ b/js/Env.js @@ -167,7 +167,7 @@ export class Env { const spade = new Spade( Math.random() * 0xffffff, Math.round(Math.random()) ? Size.little : Size.big, - startDelta + index + Math.random() * 20 + startDelta + (index - 1) * 10 ); this.addToScene(spade, TypeEntity.ennemy); diff --git a/js/Player.js b/js/Player.js index d4e14eb..b0ac700 100644 --- a/js/Player.js +++ b/js/Player.js @@ -57,17 +57,10 @@ export class Player extends Cube { * @param {string} key key pressed */ controlUser = (key) => { - const now = Date.now(); - if ( - key.code == "Space" && - !this.movementData.state && - now - this.movementData.lastJump > 300 - ) { - this.movementData.changeRotation( - this.data.rotation.y - Math.PI / 2 - ); - this.movementData.changeJump(this.data.position.y + Math.PI / 2); - this.movementData.changeState(now); + if (key.code == "Space" && !this.movementData.state) { + this.movementData.changeRotation(this.data.rotation.y - Math.PI); + this.movementData.changeJump(this.data.position.y + Math.PI); + this.movementData.changeState(); } }; diff --git a/js/main.js b/js/main.js index 09f909e..457fb52 100644 --- a/js/main.js +++ b/js/main.js @@ -25,7 +25,7 @@ const main = () => { addEventListener("keypress", player.controlUser); // Generate random map - env.generateRandomMap(20); + env.generateRandomMap(10); // GUI const gui = new dat.gui.GUI({ closeOnTop: true }); diff --git a/js/utils.js b/js/utils.js index a15d5a4..7d17ccb 100644 --- a/js/utils.js +++ b/js/utils.js @@ -26,19 +26,13 @@ export class Rotation { this.rotationVelocity = 0.03; this.jumpVelocity = 0.06; - - this.lastJump = 0; } /** - * Change the state of the animation and update the latest jump time - * @param {number} time + * Change the state of the animation */ - changeState = (time) => { + changeState = () => { this.state = !this.state; - if (time) { - this.lastJump = time; - } }; /**