diff --git a/js/Env.js b/js/Env.js index dd90e76..6943119 100644 --- a/js/Env.js +++ b/js/Env.js @@ -42,6 +42,9 @@ export class Env { light.position.set(2, 1, 4); light.castShadow = true; this.scene.add(light); + + // Clock + this.clock = new THREE.Clock(); } /** @@ -100,4 +103,13 @@ export class Env { * @returns */ render = () => this.renderer.render(this.scene, this.camera); + + /** + * Update the game logic + */ + update = () => { + console.log(s); + this.animate(); + this.render(); + }; } diff --git a/js/main.js b/js/main.js index 75d0f26..eb646bc 100644 --- a/js/main.js +++ b/js/main.js @@ -22,10 +22,17 @@ const main = () => { addEventListener("keypress", joueur.controlUser); + /** + * Run the game + */ const animate = () => { + const delta = env.clock.getDelta(); + const ticks = Math.round(delta / (1 / 120)); + for (let i = 0; i < ticks; i++) { + env.update(); + } + requestAnimationFrame(animate); - env.animate(); - env.render(); }; animate();