-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgas.js
78 lines (72 loc) · 2.28 KB
/
gas.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
Game.Gas = function(properties) {
properties = properties || {};
// Call the glyph's construtor with our set of properties
Game.Glyph.call(this, properties);
// Set up the properties
this._name = properties['name'];
this._blocksLight = (properties['blocksLight'] !== undefined) ? properties['blocksLight'] : true;
this._description = properties['description'] || '';
this._flammable = properties['flammable'] || false;
this._lifespan = properties['lifespan'] || 5;
this._speed = properties['speed'] || 1000;
this._defaultForeground = this._foreground;
this._defaultBackground = this._background;
this._isHazard = properties['isHazard'] || false;
};
Game.Gas.extend(Game.Glyph);
// Standard getters
Game.Gas.prototype.isBlockingLight = function() {
return this._blocksLight;
}
Game.Gas.prototype.isFlammable = function() {
return this._flammable;
}
Game.Gas.prototype.getDescription = function() {
return this._description;
};
Game.Gas.prototype.getSpeed = function() {
return this._speed;
};
Game.Gas.prototype.getNeighborPositions = function() {
let tiles = [];
// Generate all possible offsets
for (let dX = -1; dX < 2; dX ++) {
for (let dY = -1; dY < 2; dY++) {
// Make sure it isn't the same tile
if (dX === 0 && dY === 0 || (dX === dY)) {
continue;
}
tiles.push({x: this._x + dX, y: this._y + dY});
}
}
return Game.randomize(tiles);
};
Game.Gas.prototype.setX = function(x) {
this._x = x;
}
Game.Gas.prototype.setY = function(y) {
this._y = y;
}
Game.Gas.prototype.setMap = function(map) {
this._map = map;
}
Game.Gas.prototype.getX = function() {
return this._x;
}
Game.Gas.prototype.getY = function() {
return this._y;
}
Game.Gas.prototype.getMap = function() {
return this._map;
}
Game.Gas.prototype.act = function() {
if (this._lifespan > 0) {
this._lifespan--;
} else {
this.getMap().removeGas(this);
}
this._foreground = ROT.Color.toHex(ROT.Color.randomize(ROT.Color.fromString(this._defaultForeground), [10, 10, 10]));
this._background = ROT.Color.toHex(ROT.Color.randomize(ROT.Color.fromString(this._defaultBackground), [10, 10, 10]));
// Re-render the screen
Game.refresh();
}