From d3aca8888d936136c07eaa38300d3949804553a8 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 24 Nov 2022 17:34:00 +0100 Subject: [PATCH] *move rotation to utils *change velocity --- js/player.js | 51 ++------------------------------------------------- js/utils.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/js/player.js b/js/player.js index 4f4fc38..30ef058 100644 --- a/js/player.js +++ b/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); } diff --git a/js/utils.js b/js/utils.js index a32c61b..1251b1e 100644 --- a/js/utils.js +++ b/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; + }; +}