-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapObject.js
107 lines (86 loc) · 1.74 KB
/
MapObject.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
class MapObject extends EventListener {
constructor(options = {}) {
super();
const {
char,
color,
position = new Vector()
} = options;
this.char = char;
this.color = color;
this.position = position;
}
clone() {
const object = new this.constructor({
char: this.char,
color: this.color,
position: this.position.copy()
});
Utils.deepClone(this, object);
return object;
}
}
class Pickable extends MapObject {
constructor(options = {}) {
super(options);
this.name = "Pickable";
}
}
class Exit extends MapObject {
constructor(options = {}) {
super(options);
this.color = "#00ff00";
this.char = "X";
}
}
class Solid extends MapObject {
constructor(options = {}) {
super(options);
}
}
class Wall extends Solid {
constructor(options = {}) {
super(options);
this.color = "#858585";
this.char = "#";
}
}
class Arrow extends Pickable {
constructor(options = {}) {
super(options);
this.name = "Arrow";
this.color = "#fff255";
this.char = "A";
}
}
class LivingEntity extends Solid {
constructor(options = {}) {
super(options);
const {
name,
health,
strength
} = options;
this.name = name;
this.health = health;
this.strength = strength;
}
damage(attacker, amount = attacker.strength) {
this.dispatchEvent("damage", {attacker, amount}, event => {
this.health -= event.amount;
if(this.health <= 0) {
this.dispatchEvent("death", {attacker});
}
});
}
}
class Monster extends LivingEntity {
constructor(options = {}) {
super(options);
this.color = "#ff0000";
this.char = "M";
this.name = "Monster";
this.health = 1;
this.strength = 1;
}
}