-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWardrobe.js
77 lines (65 loc) · 1.97 KB
/
Wardrobe.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
var Wardrobe = (function () {
var SCORE_PLACEMENT_OFFSETX = 2;
var SCORE_PLACEMENT_OFFSETY = 32;
var states = {
closed: 0,
opened: 1
};
function Wardrobe (data) {
this.score = undefined;
this.x = data.x || 0;
this.y = data.y || 0;
this.width = 64;
this.height = 96;
this.state = states.closed;
this.imperviousToShootingRay = false;
this.spriteImg = resources.get('player');
this.animations = [];
this.initAnimations();
};
Wardrobe.prototype = new BasicObject();
Wardrobe.prototype.update = function (dt) {
if(this.animations[this.state]){
this.animations[this.state].update(dt);
}
};
Wardrobe.prototype.open = function () {
this.state = states.opened;
if(this.score) {
this.score.activate({
x: this.getRightX() - SCORE_PLACEMENT_OFFSETX - this.score.width,
y: this.y + SCORE_PLACEMENT_OFFSETY - this.score.height
});
}
};
Wardrobe.prototype.render = function (viewportContext) {
if(this.animations[this.state]){
this.animations[this.state].render(viewportContext, this.x, this.y);
}
};
Wardrobe.prototype.getCollisionReaction = function (collided) {
reaction = {
x: this.x + this.width - collided.width * .9
};
return reaction;
};
Wardrobe.prototype.initAnimations = function () {
this.animations[states.opened] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 0,
y: 648
}
],
width: 63,
height: 96,
frames: 1,
animSpeed: 1,
}));
};
Wardrobe.prototype.isOpened = function () {
return this.state == states.opened ? true : false;
};
return Wardrobe;
})();