Repository navigation
Expand file tree
/
Copy pathGrid.js
More file actions
63 lines (56 loc) · 1.98 KB
/
Copy pathGrid.js
File metadata and controls
63 lines (56 loc) · 1.98 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
class Grid {
constructor() {
}
loadZone(newZone) {
this.tiles = create2dArray(newZone.w, newZone.h);;
for (let i = 0; i < newZone.w; i++) {
for (let j = 0; j < newZone.h; j++) {
let tile = new Tile(i, j)
let layout = newZone.layout[i][j];
//Set Tile Type
if (layout[0] == "g") {
tile.setType(TileType.GRASS);
} else if (layout[0] == "w") {
tile.setType(TileType.WALL);
} else if (layout[0] == "t") {
tile.setType(TileType.TELEPORT);
}
//Set Tile Sprite
if (layout[1]) {
tile.setModel(layout[1]);
}
if (layout[2]) {
tile.setBlockerModel(layout[2])
}
this.tiles[i][j] = tile;
}
}
//Add all characters
newZone.characters.forEach(character => {
entities.push(new Character(character.x, character.y, character.direction, character.id, character.pathing, this.tiles))
});
//Add all items
newZone.items.forEach(item => {
if (worldData.pickedItems[`${item.id}`]) {
//This item has already been picked up.
} else {
entities.push(new Item(item.x, item.y, item.id, item.type, null, this.tiles));
}
});
//Add all entities
newZone.entities.forEach(entity => {
let newEntity = new Entity(entity.x, entity.y, entity.model, this.tiles);
newEntity.type = entity.type;
entities.push(newEntity);
});
}
draw() {
this.tiles.forEach(row => {
row.forEach(tile => {
if (Math.abs(player.x - tile.x) < 6 && Math.abs(player.y - tile.y) < 6) {
tile.draw(player.x, player.y);
}
});
});
}
}