-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadHandler.js
42 lines (34 loc) · 1.2 KB
/
loadHandler.js
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
37
38
39
40
41
42
import { mapArray, mapWidth, mapHeight, elementsToBeLoaded, HUDSprite, hexSpritesheet, buildingsSprite, tileInteract } from './constants/index.js';
import { Hex } from './libraries/hex.js';
import { Point2D } from './libraries/point2d.js';
import getBiome from './libraries/biomes.js';
let loadedElements = 0;
function loading()
{
loadedElements += 1;
console.log(`${loadedElements}/${elementsToBeLoaded} loaded ` + Math.round(loadedElements/elementsToBeLoaded*100) + "%");
}
export function isLoaded(){
if (loadedElements == elementsToBeLoaded)
{
console.log(`${loadedElements}/${elementsToBeLoaded} elements loaded. Game initializing`);
return true;
}
}
export function load() {
hexSpritesheet.onload = loading();
HUDSprite.onload = loading();
buildingsSprite.onload = loading();
tileInteract.onload = loading();
if(loadMap()) loading();
}
function loadMap() {
for (let x = mapWidth; x > 0; x--) {
mapArray[x] = new Array(mapHeight);
for (let y = mapHeight; y > 0; y--) {
mapArray[x][y] = new Hex(new Point2D(x,y));
mapArray[x][y].tile = getBiome(new Point2D(x,y));
}
}
return true;
}