-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathterrain.js
executable file
·98 lines (96 loc) · 2.85 KB
/
terrain.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
var terrain = {
list:{
"oilfield":{
name:"oilfield",
pixelWidth:40,
pixelHeight:60,
baseWidth:40,
baseHeight:20,
pixelOffsetX:0,
pixelOffsetY:40,
buildableGrid:[
[1,1]
],
passableGrid:[
[1,1]
],
spriteImages:[
{name:"hint",count:1},
{name:"default",count:1},
],
},
"bigrocks":{
name:"bigrocks",
pixelWidth:40,
pixelHeight:70,
baseWidth:40,
baseHeight:40,
pixelOffsetX:0,
pixelOffsetY:30,
buildableGrid:[
[1,1],
[0,1]
],
passableGrid:[
[1,1],
[0,1]
],
spriteImages:[
{name:"default",count:1},
],
},
"smallrocks":{
name:"smallrocks",
pixelWidth:20,
pixelHeight:35,
baseWidth:20,
baseHeight:20,
pixelOffsetX:0,
pixelOffsetY:15,
buildableGrid:[
[1]
],
passableGrid:[
[1]
],
spriteImages:[
{name:"default",count:1},
],
},
},
defaults:{
type:"terrain",
animationIndex:0,
action:"default",
selected:false,
selectable:false,
animate:function(){
switch (this.action){
case "default":
this.imageList = this.spriteArray["default"];
this.imageOffset = this.imageList.offset + this.animationIndex;
this.animationIndex++;
if (this.animationIndex>=this.imageList.count){
this.animationIndex = 0;
}
break;
case "hint":
this.imageList = this.spriteArray["hint"];
this.imageOffset = this.imageList.offset + this.animationIndex;
this.animationIndex++;
if (this.animationIndex>=this.imageList.count){
this.animationIndex = 0;
}
break;
}
},
draw:function(){
var x = (this.x*game.gridSize)-game.offsetX-this.pixelOffsetX;
var y = (this.y*game.gridSize)-game.offsetY-this.pixelOffsetY;
var colorOffset = 0; // No team based colors
game.foregroundContext.drawImage(this.spriteSheet, this.imageOffset*this.pixelWidth, colorOffset, this.pixelWidth, this.pixelHeight, x, y, this.pixelWidth, this.pixelHeight);
}
},
load:loadItem,
add:addItem
};