39 lines
872 B
JavaScript
39 lines
872 B
JavaScript
import { Env } from "./Env.js";
|
|
import { Plane } from "./Plane.js";
|
|
import { Player } from "./Player.js";
|
|
|
|
window.addEventListener("load", () => main());
|
|
|
|
const main = () => {
|
|
const env = new Env();
|
|
|
|
document.body.appendChild(env.getDomElement());
|
|
|
|
const plan = new Plane(
|
|
window.innerWidth / 50,
|
|
10,
|
|
THREE.Color.NAMES.white,
|
|
THREE.Color.NAMES.black
|
|
);
|
|
env.addToScene(plan);
|
|
|
|
const player = new Player(THREE.Color.NAMES.red);
|
|
env.addToScene(player);
|
|
|
|
addEventListener("keypress", player.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);
|
|
};
|
|
|
|
animate();
|
|
};
|