-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScoreSFX.js
102 lines (90 loc) · 2.5 KB
/
ScoreSFX.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
var ScoreSFX = (function () {
var LIFE_TIME = 1;
var ONE_UP_LIFE_TIME = 2;
function ScoreSFX () {
this.vy = -50;
this.score = 0;
this.imperviousToShootingRay = false;
this.inUse = false;
this.lifeTime = 0;
this.spriteImg = resources.get('player');
this.animations = [];
this.initAnimations();
};
ScoreSFX.prototype = new BasicObject();
ScoreSFX.prototype.update = function (dt) {
this.y += this.vy * dt;
this.lifeTime += dt;
var lifetime = this.score == 1 ? ONE_UP_LIFE_TIME : LIFE_TIME;
if(this.lifeTime >= lifetime) {
this.inUse = false;
this.lifeTime = 0;
}
};
ScoreSFX.prototype.spawn = function (x, y) {
this.x = x;
this.y = y;
this.inUse = true;
this.lifeTime = 0;
};
ScoreSFX.prototype.render = function (viewportContext) {
if(Game.debugSettings.drawStats) {
viewportContext.fillText(this.score, this.x, this.y);
}
var animation = this.animations[this.score];
if(animation) {
animation.render(viewportContext, Math.floor(this.x), Math.floor(this.y));
}
};
ScoreSFX.prototype.initAnimations = function () {
this.animations[100] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2781
}
],
width: 48,
height: 32,
frames: 1,
animSpeed: 60
}));
this.animations[200] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2829
}
],
width: 48,
height: 32,
frames: 1,
animSpeed: 60
}));
this.animations[400] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2877
}
],
width: 48,
height: 32,
frames: 1,
animSpeed: 60
}));
this.animations[1] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 3021
}
],
width: 48,
height: 32,
frames: 1,
animSpeed: 60
}));
};
return ScoreSFX;
})();