Files
djupet/src/main.ts

42 lines
940 B
TypeScript
Raw Normal View History

import './style.css';
import { createState, tick, buyUpgrade } from './engine.ts';
import { initUI, renderState } from './ui.ts';
import { initMap, updateMap } from './map.ts';
let state = createState();
let lastTime = 0;
const TARGET_FPS = 30;
const FRAME_MS = 1000 / TARGET_FPS;
function start(): void {
const app = document.getElementById('app')!;
initUI(app,
(id) => { state = buyUpgrade(state, id); renderState(state); },
() => {
state = createState();
document.getElementById('overlay')!.classList.remove('visible');
renderState(state);
}
);
initMap('map');
renderState(state);
requestAnimationFrame(loop);
}
function loop(now: number): void {
if (now - lastTime >= FRAME_MS) {
lastTime = now;
if (state.phase === 'playing') {
state = tick(state);
renderState(state);
updateMap(state.dread, state.areas);
}
}
requestAnimationFrame(loop);
}
start();