-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_engine.js
More file actions
97 lines (87 loc) · 2.38 KB
/
new_engine.js
File metadata and controls
97 lines (87 loc) · 2.38 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//import { gC } from "./conf.js";
//import { Utils } from "./utils.js";
//import { enemy } from "./enemy.js";
var assets = [];
function startGame(){
//Utils.clearCanvas()
let a_l = assets.length;
for(let a = 0;a<a_l;a++)
assets[a].start()
.then(
(succ)=>{
assets[a].animation()
.then(
(succ)=>{
//console.log(succ);
}
)
.catch(
(err)=>{
console.log(err);
}
)
}
)
.catch(
(err)=>{
console.log(err);
}
)
}
function addDemoAssets(t){
if(t%5)
assets.push(new enemy());
}
function readDemonData(){
var me = this;
return new Promise(function(res,rej){
if(!gC.demonData){
var xmlhttp = new XMLHttpRequest();
var url = 'assets/games/demons/demons4js.json';
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
gC.demonData = JSON.parse(this.responseText);
return res();
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}else{
return res();
}
})
}
function addCanvas(){
var me = this;
return new Promise(function(res,rej){
var canvas = Utils.getEBTN('canvas')
if(typeof canvas === 'object' && canvas.length <= 0){
//non c'è canvas
var a = Utils.getEBTN('body')[0]
var b = Utils.createE('canvas')
//memorizzo canvas e contesto
Utils.setCanvas(b)
Utils.appendB2A(a,b)
Utils.setAttribute(b,'width',gC.width)
Utils.setAttribute(b,'height',gC.height)
}
res();
})
}
//every frame value, draw scene
function l(){
var demoTime = 0;
addCanvas().then(
(succ)=>{
readDemonData().then(
(succ) => {
gC.l_i = setInterval(function() {
demoTime++;
addDemoAssets(demoTime);
startGame();
}, gC.fr);
}
)
}
)
}