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(
|
||||
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);
|
||||
|
|
15
js/Player.js
15
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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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 });
|
||||
|
|
10
js/utils.js
10
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;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue