-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlevelDrawer.js
98 lines (67 loc) · 1.82 KB
/
levelDrawer.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
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
97
98
function LevelDrawer(gameObject)
{
this.game = gameObject;
var self = this;
this.load = function(doneCallback)
{
self.game.levelImageProvider = new LevelImageProvider(self.game);
self.game.levelImageProvider.load(self.game.levelHandler.GraphicSet1, doneCallback);
}
//- create new self.game.gameTerrain
this.createTerrain = function()
{
var lH = self.game.levelHandler;
var img = self.game.gameContext.createImageData(lH.levelWidth, lH.levelHeight);
//self.ClearImage(img);
var iP = self.game.levelImageProvider;
var lHT = lH.terrains;
var tickNumber = self.game.tick;
for (var i = 0; i < lHT.length; i++)
{
var tInfo = lHT[i];
iP.copyImageTo(img, tInfo.id, tInfo, tickNumber);
}
this.game.gameTerrain = img;
return true;
}
//- create new Object Trigger
this.createObjectTrigger = function()
{
var tH = self.game.triggerHandler;
var iP = self.game.levelImageProvider;
var lH = self.game.levelHandler;
var lHO = lH.objects;
for (var i = 0; i < lHO.length; i++)
{
var oInfo = lHO[i];
iP.addTrigger(tH, oInfo);
}
return true;
}
this.getObjects = function(img)
{
var iR = self.game.levelImageProvider;
var lH = self.game.levelHandler;
var lHO = lH.objects;
var tickNumber = self.game.tick;
for (var i = 0; i < lHO.length; i++)
{
var oInfo = lHO[i];
iR.copyImageTo(img, oInfo.id, oInfo, tickNumber);
}
return img;
}
this.ClearImage = function(destImg)
{
var pixCount = destImg.height * destImg.width * 4;
var i = 0;
var imgData = destImg.data;
while(i < pixCount)
{
imgData[i++] = 0; //- R
imgData[i++] = 0; //- G
imgData[i++] = 0; //- B
imgData[i++] = 0; //- Alpha
}
}
}