-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathitem.js
34 lines (27 loc) · 762 Bytes
/
item.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
var inherits = require('inherits');
var Entity = require('crtrdg-entity');
module.exports = Item;
inherits(Item, Entity);
function Item(options){
this.name = options.name;
this.game = options.game;
this.inventory = options.inventory;
this.healthMeter = options.healthMeter || {};
this.weight = options.weight;
this.healing = options.healing;
this.id = this.name.replace(/ /g,'_').toLowerCase();
this.position = {
x: options.position.x,
y: options.position.y
};
this.size = {
x: options.size.x,
y: options.size.y
};
this.color = '#fff111';
}
Item.prototype.eat = function(){
this.healthMeter.level += this.healing;
if (this.healthMeter.level >= 100) this.healthMeter.level = 100;
this.inventory.remove(this);
}