import GameConfig from "../config/GameConfiguration.js"; import Logger from "../utils/Logger.js"; import Time from "../utils/Time.js"; import GameRenderer from "./GameRenderer.js"; import Enemy from "./objects/Enemy.js"; import Planet from "./objects/Planet.js"; var gameLoop, playerID, stage, state, lastUpdate = 0, lastEnemySpawn; function onTick() { let now = Date.now(), delta = now - lastUpdate, adjustment = (Time.ONE_SECOND_IN_MS / GameConfig.getFPS()) / delta; if (state) { predictStateChanges(); GameRenderer.render(state, delta) } lastUpdate = now; } function predictStateChanges() { // TODO: Predict local changes to enemy positions } function onWorldDestroyed() { Logger.log(`World destroyed [Current health ${planet.health}]`, "Game"); } class GameManager { init(canvasStage) { stage = canvasStage; state = null; } start(newPlayerID) { playerID = newPlayerID; GameRenderer.init(stage); lastUpdate = Date.now(); gameLoop = setInterval(onTick, (Time.ONE_SECOND_IN_MS / GameConfig.getFPS())); } addGazePoint(point) { gazePoints.push(point); } syncState(serverState) { state = serverState; } } export default new GameManager();