-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelbuilder.js
132 lines (123 loc) · 6.01 KB
/
levelbuilder.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
function LevelBuilder(str, game, levelID = "") {
this.level = [];
// left side wall
for (var i = -4; i <= 4; i++) {
var tile = new Tile(game, "./img/placeholder_tile.png", 0, 0,
-128, i * 128, -128, i * 128,
128, 128, 128, 128, {allDir:true, bottom:true})
this.level.push({type:"Platform", ent:tile});
}
var row = 0;
var count = 0;
var countBuffer = 0;
for(var i = 0; i < str.length; i++) {
//Tile(game, img, framex, framey, x, y, posX, posY, width, height, frameW, frameH, allSides)
//types of entities: Platform, Enemy, Other
switch(str.charAt(i)) {
case 'C':
var tile = new Tile(game, "./img/cage.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:false, bottom:false});
this.level.push({type:"Platform", ent:tile});
break;
case 'K':
var tile = new Tile(game, "./img/cage_dog.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:true});
this.level.push({type:"Platform", ent:tile});
break;
case 'X':
var tile = new Tile(game, "./img/cage_cat.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:true});
this.level.push({type:"Platform", ent:tile});
break;
case 'T': // placeholder tile
var tile = new Tile(game, "./img/placeholder_tile.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:true});
this.level.push({type:"Platform", ent:tile});
break;
case 'G': // ground
var tile = new Tile(game, "./img/" + levelID + "ground.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:true});
this.level.push({type:"Platform", ent:tile});
break;
case 'B': // box
var tile = new Tile(game, "./img/" + levelID + "box.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:true});
this.level.push({type:"Platform", ent:tile});
break;
case 'F': // fence
var tile = new Tile(game, "./img/" + levelID + "fence.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:false});
this.level.push({type:"Platform", ent:tile});
break;
case 'D': // dumpster
var tile = new Tile(game, "./img/" + levelID + "dumpster.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:false});
this.level.push({type:"Platform", ent:tile});
break;
case 'S': // building
var tile = new Tile(game, "./img/" + levelID + "building.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:false, bottom:false});
this.level.push({type:"Platform", ent:tile});
break;
case 'I': // crane piece vertical
var tile = new Tile(game, "./img/" + levelID + "crane_piece_v.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:false, bottom:false});
this.level.push({type:"Platform", ent:tile});
break;
case '+': // crane piece horizontal
var tile = new Tile(game, "./img/" + levelID + "crane_piece_h.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:true});
this.level.push({type:"Platform", ent:tile});
break;
case '=': // bridge
var tile = new Tile(game, "./img/" + levelID + "bridge.png", 0, 0, 128 * (i - count - 1), 128 * (row - 1),
128 * (i - count - 1), 128 * (row - 1), 128, 128, 128, 128, {allDir:true, bottom:false});
this.level.push({type:"Platform", ent:tile});
break;
case 'W':
var water0 = new Platform(game, 128 * (i - count - 1), 128 * (row - 1), 64, 64, "Red");
var water1 = new Platform(game, 128 * (i - count - 1) + 64, 128 * (row - 1), 64, 64, "Red");
var water2 = new Platform(game, 128 * (i - count - 1), 128 * (row - 1) + 64, 64, 64, "Red");
var water3 = new Platform(game, 128 * (i - count - 1) + 64, 128 * (row - 1) + 64, 64, 64, "Red");
this.level.push({type:"Platform", ent:water0});
this.level.push({type:"Platform", ent:water1});
this.level.push({type:"Platform", ent:water2});
this.level.push({type:"Platform", ent:water3});
break;
case 'l': // lamp
var lamp = new Lamp(game, 128 * (i - count - 1), 128 * (row - 1) - 256);
this.level.push({type:"Other", ent:lamp});
break;
case 'c': // checkpoint
var checkpoint = new Checkpoint(game, 128 * (i - count - 1) + 32, 128 * (row - 1));
this.level.push({type:"Other", ent:checkpoint});
break;
case 's': // sitter dog
this.level.push({type:"Enemy", ent:new EnemyIdle(game, 128 * (i-count) - 64, 128 * (row - 1) + 24)})
break;
case 'p': // pacer dog
this.level.push({type:"Enemy", ent:new EnemyPace(game, 128 * (i-count), 128 * (row - 1) + 24)})
break
case 'r': // rat
this.level.push({type:"Enemy", ent:new Rat(game, 128 * (i - count - 1), 128 * (row - 1) + 64)})
break;
case 'b': // bird
this.level.push({type:"Enemy", ent:new Bird(game, 128 * (i-count), 128 * (row - 1))})
break;
case 'g': // range
this.level.push({type:"Enemy", ent:new Range(game, 128 * (i-count), 128 * (row - 1))})
break;
case ';': // newline
row++;
count += countBuffer;
countBuffer = 0;
default: break;
}
countBuffer++;
}
this.level.push({type:"Other", ent: new Health(game)});
this.level.push({type:"Other", ent:game.cat});
}
LevelBuilder.prototype.getLevel = function() {
return this.level;
}