*move rotation to utils

*change velocity
This commit is contained in:
Mylloon 2022-11-24 17:34:00 +01:00
parent 03903834a8
commit d3aca8888d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 51 additions and 49 deletions

View file

@ -1,53 +1,5 @@
import { Cube } from "./Cube.js"; import { Cube } from "./Cube.js";
import { Rotation } from "./utils.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;
};
}
export class Joueur extends Cube { export class Joueur extends Cube {
constructor(color) { constructor(color) {
@ -55,6 +7,7 @@ export class Joueur extends Cube {
this.data.position.y = 0.5; this.data.position.y = 0.5;
this.data.rotation.x = this.gameRotation; this.data.rotation.x = this.gameRotation;
this.movementData = new Rotation(this.data.position); this.movementData = new Rotation(this.data.position);
} }

View file

@ -16,3 +16,52 @@ export const textureGradient = (width, height, color1, color2) => {
return texture; 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;
};
}