fix map generation
This commit is contained in:
parent
b068df38d7
commit
37c51d7db8
4 changed files with 8 additions and 21 deletions
|
@ -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);
|
||||||
|
|
15
js/Player.js
15
js/Player.js
|
@ -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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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 });
|
||||||
|
|
10
js/utils.js
10
js/utils.js
|
@ -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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in a new issue