-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
51 lines (38 loc) · 1.13 KB
/
main.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
43
44
45
46
47
48
49
50
51
import Game from './src/game';
import config from './src/config';
import mapData from './src/mapData';
const canvas = document.querySelector('#can');
const loadImage = (srcMap) => {
return new Promise((resolve) => {
const imgsRequest = [];
Object.keys(srcMap).map((type) => {
imgsRequest.push(
new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
resolve({
type,
img,
path: img.src
});
}
img.src = srcMap[type];
})
)
})
Promise.all(imgsRequest).then((images) => {
resolve(images)
})
})
}
const __init = (allImages) => {
const game = new Game('Mario', canvas, allImages, mapData, config)
}
//加载完图片后,游戏初始化;
loadImage(config.asset).then((allImages) => {
const obj = {}
allImages.map((item) => {
obj[item.type] = item;
})
__init(obj)
})