This repository has been archived on 2022-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
GeometryDash3D/js/main.js

40 lines
872 B
JavaScript
Raw Normal View History

import { Env } from "./Env.js";
2022-11-22 10:40:56 +01:00
import { Plane } from "./Plane.js";
import { Joueur } from "./player.js";
2022-11-07 09:10:20 +01:00
window.addEventListener("load", () => main());
const main = () => {
const env = new Env();
2022-11-07 09:59:36 +01:00
document.body.appendChild(env.getDomElement());
2022-11-08 09:43:37 +01:00
2022-11-22 10:40:56 +01:00
const plan = new Plane(
window.innerWidth / 50,
10,
THREE.Color.NAMES.white,
THREE.Color.NAMES.black
);
env.addToScene(plan);
2022-11-08 09:43:37 +01:00
const joueur = new Joueur(THREE.Color.NAMES.red);
env.addToScene(joueur);
addEventListener("keypress", joueur.controlUser);
2022-11-24 18:41:17 +01:00
/**
* Run the game
*/
2022-11-08 09:43:37 +01:00
const animate = () => {
2022-11-24 18:41:17 +01:00
const delta = env.clock.getDelta();
const ticks = Math.round(delta / (1 / 120));
for (let i = 0; i < ticks; i++) {
env.update();
}
2022-11-08 09:43:37 +01:00
requestAnimationFrame(animate);
};
2022-11-08 09:43:37 +01:00
animate();
2022-11-07 09:10:20 +01:00
};