-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.js
89 lines (81 loc) · 2.01 KB
/
level.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
/*global ROT, DN*/
DN.Level = function () {
'use strict';
var i;
this.map = {};
this.monsters = [];
DN.digger.create(this.initMap.bind(this));
this.rooms = DN.digger.getRooms();
this.stairs = this.rooms[this.rooms.length - 1].getCenter();
this.map[this.stairs[0] + ',' + this.stairs[1]] = {
x: this.stairs[0],
y: this.stairs[1],
char: '>'
};
for (i = 0; i < this.rooms.length; i += 1) {
this.rooms[i].getDoors(this.initDoor.bind(this));
}
this.fov = new ROT.FOV.PreciseShadowcasting(this.isTransparent.bind(this));
};
DN.Level.prototype.initMap = function (x, y, value) {
'use strict';
if (!value) {
this.map[x + ',' + y] = {
x: x,
y: y,
char: '.'
};
if (ROT.RNG.getPercentage() === 1) {
this.monsters.push(
new DN.Actor(String.fromCharCode(this.monsters.length + 65),
x, y, 0, 10, 6)
);
}
}
};
DN.Level.prototype.initDoor = function (x, y) {
'use strict';
this.map[x + ',' + y].char = '+';
};
DN.Level.prototype.isTransparent = function (x, y) {
'use strict';
if (this.map.hasOwnProperty(x + ',' + y)) {
return this.map[x + ',' + y].char !== '+';
}
return false;
};
DN.Level.prototype.isPassable = function (x, y) {
'use strict';
return this.map.hasOwnProperty(x + ',' + y);
};
DN.Level.prototype.getChar = function (x, y) {
'use strict';
var i;
if (DN.adventurer.x === x && DN.adventurer.y === y) {
return '@';
}
for (i = 0; i < this.monsters.length; i += 1) {
if (this.monsters[i].x === x && this.monsters[i].y === y) {
return this.monsters[i].char;
}
}
if (this.map.hasOwnProperty(x + ',' + y)) {
return this.map[x + ',' + y].char;
}
return '#';
};
DN.Level.prototype.getTerrain = function (x, y) {
'use strict';
if (this.map.hasOwnProperty(x + ',' + y)) {
return this.map[x + ',' + y].char;
}
return '#';
};
DN.Level.prototype.setChar = function (x, y, char) {
'use strict';
this.map[x + ',' + y] = {
x: x,
y: y,
char: char
};
};