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

54 lines
1.3 KiB
JavaScript
Raw Normal View History

import { Env } from "./Env.js";
2022-11-22 10:40:56 +01:00
import { Plane } from "./Plane.js";
2022-11-24 18:58:45 +01:00
import { Player } from "./Player.js";
2022-11-24 19:45:20 +01:00
import { Quality } from "./utils.js";
2022-11-07 09:10:20 +01:00
window.addEventListener("load", () => main());
const main = () => {
2022-11-24 19:45:20 +01:00
// THREE.js
const env = new Env();
document.body.appendChild(env.getDomElement());
2022-11-08 09:43:37 +01:00
2022-11-24 19:45:20 +01:00
// World
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
2022-11-24 19:45:20 +01:00
// Player
2022-11-24 18:58:45 +01:00
const player = new Player(THREE.Color.NAMES.red);
env.addToScene(player);
addEventListener("keypress", player.controlUser);
2022-11-24 19:45:20 +01:00
// GUI
2022-11-24 19:46:18 +01:00
const gui = new dat.gui.GUI({ closeOnTop: true });
2022-11-24 19:45:20 +01:00
const menu = Quality.buildGUI(env.quality);
for (const quality in menu) {
gui.add(menu, quality)
.listen()
.onFinishChange(() => {
Quality.update(env.setQuality, menu, quality);
});
}
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
2022-11-24 19:45:20 +01:00
// Run it
2022-11-08 09:43:37 +01:00
animate();
2022-11-07 09:10:20 +01:00
};