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(
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);

View file

@ -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();
}
};

View file

@ -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 });

View file

@ -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;
}
};
/**