*move rotation to utils
*change velocity
This commit is contained in:
parent
03903834a8
commit
d3aca8888d
2 changed files with 51 additions and 49 deletions
51
js/player.js
51
js/player.js
|
@ -1,53 +1,5 @@
|
|||
import { Cube } from "./Cube.js";
|
||||
|
||||
class Rotation {
|
||||
constructor(position) {
|
||||
this.default = position.clone();
|
||||
this.state = false;
|
||||
this.rotation = 0;
|
||||
this.jump = 0;
|
||||
|
||||
this.rotationVelocity = 0.05;
|
||||
this.jumpVelocity = 0.1;
|
||||
|
||||
this.lastJump = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the state of the animation and update the latest jump time
|
||||
* @param {number} time
|
||||
*/
|
||||
changeState = (time) => {
|
||||
this.state = !this.state;
|
||||
if (time) {
|
||||
this.lastJump = time;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the final rotation
|
||||
* @param {number} rotation
|
||||
*/
|
||||
changeRotation = (rotation) => {
|
||||
this.rotation = rotation;
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the final position
|
||||
* @param {number} jump
|
||||
*/
|
||||
changeJump = (jump) => {
|
||||
this.jump = jump;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the state of the jump
|
||||
* @returns boolean representing if the object is going up or down
|
||||
*/
|
||||
falling = () => {
|
||||
return this.jump == this.default.y;
|
||||
};
|
||||
}
|
||||
import { Rotation } from "./utils.js";
|
||||
|
||||
export class Joueur extends Cube {
|
||||
constructor(color) {
|
||||
|
@ -55,6 +7,7 @@ export class Joueur extends Cube {
|
|||
|
||||
this.data.position.y = 0.5;
|
||||
this.data.rotation.x = this.gameRotation;
|
||||
|
||||
this.movementData = new Rotation(this.data.position);
|
||||
}
|
||||
|
||||
|
|
49
js/utils.js
49
js/utils.js
|
@ -16,3 +16,52 @@ export const textureGradient = (width, height, color1, color2) => {
|
|||
|
||||
return texture;
|
||||
};
|
||||
|
||||
export class Rotation {
|
||||
constructor(position) {
|
||||
this.default = position.clone();
|
||||
this.state = false;
|
||||
this.rotation = 0;
|
||||
this.jump = 0;
|
||||
|
||||
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
|
||||
*/
|
||||
changeState = (time) => {
|
||||
this.state = !this.state;
|
||||
if (time) {
|
||||
this.lastJump = time;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the final rotation
|
||||
* @param {number} rotation
|
||||
*/
|
||||
changeRotation = (rotation) => {
|
||||
this.rotation = rotation;
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the final position
|
||||
* @param {number} jump
|
||||
*/
|
||||
changeJump = (jump) => {
|
||||
this.jump = jump;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the state of the jump
|
||||
* @returns boolean representing if the object is going up or down
|
||||
*/
|
||||
falling = () => {
|
||||
return this.jump == this.default.y;
|
||||
};
|
||||
}
|
||||
|
|
Reference in a new issue