-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
36 lines (31 loc) · 916 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import GeneticMLCars from './lib/geneticMLCars';
import * as P from 'pixi.js';
import { ALGORITHM } from './lib/constants';
window.addEventListener('DOMContentLoaded', initGame);
function removeExistingGame(): void {
const els = document.body.children;
if (els.length > 0) document.body.removeChild(els.item(0) as Node);
}
function init(): P.Application {
removeExistingGame();
const app = new P.Application(window.outerWidth, window.outerHeight, {
backgroundColor: 0xffffff
});
document.body.appendChild(app.view);
window.onresize = () => {
app.renderer.resize(window.innerWidth, window.innerHeight);
};
return app;
}
function initGame(): void {
const app = init();
const game = new GeneticMLCars(app);
game.start(ALGORITHM.amtToBreed + ALGORITHM.numAlphaClones);
}
// @ts-ignore
if (module.hot) {
// @ts-ignore
module.hot.accept(function accept() {
initGame();
});
}