fix map generation

This commit is contained in:
Mylloon 2022-12-02 14:29:12 +01:00
parent b068df38d7
commit 37c51d7db8
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 8 additions and 21 deletions

View file

@ -167,7 +167,7 @@ export class Env {
const spade = new Spade( const spade = new Spade(
Math.random() * 0xffffff, Math.random() * 0xffffff,
Math.round(Math.random()) ? Size.little : Size.big, Math.round(Math.random()) ? Size.little : Size.big,
startDelta + index + Math.random() * 20 startDelta + (index - 1) * 10
); );
this.addToScene(spade, TypeEntity.ennemy); this.addToScene(spade, TypeEntity.ennemy);

View file

@ -57,17 +57,10 @@ export class Player extends Cube {
* @param {string} key key pressed * @param {string} key key pressed
*/ */
controlUser = (key) => { controlUser = (key) => {
const now = Date.now(); if (key.code == "Space" && !this.movementData.state) {
if ( this.movementData.changeRotation(this.data.rotation.y - Math.PI);
key.code == "Space" && this.movementData.changeJump(this.data.position.y + Math.PI);
!this.movementData.state && this.movementData.changeState();
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);
} }
}; };

View file

@ -25,7 +25,7 @@ const main = () => {
addEventListener("keypress", player.controlUser); addEventListener("keypress", player.controlUser);
// Generate random map // Generate random map
env.generateRandomMap(20); env.generateRandomMap(10);
// GUI // GUI
const gui = new dat.gui.GUI({ closeOnTop: true }); const gui = new dat.gui.GUI({ closeOnTop: true });

View file

@ -26,19 +26,13 @@ export class Rotation {
this.rotationVelocity = 0.03; this.rotationVelocity = 0.03;
this.jumpVelocity = 0.06; this.jumpVelocity = 0.06;
this.lastJump = 0;
} }
/** /**
* Change the state of the animation and update the latest jump time * Change the state of the animation
* @param {number} time
*/ */
changeState = (time) => { changeState = () => {
this.state = !this.state; this.state = !this.state;
if (time) {
this.lastJump = time;
}
}; };
/** /**