-
Notifications
You must be signed in to change notification settings - Fork 3
/
Score.js
111 lines (96 loc) · 2.85 KB
/
Score.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
108
109
110
111
var Score = (function () {
var ANIMATION_SPEED = 8;
function playCollectionSound () {
var soundBuffer = this.sounds[this.score];
if(soundBuffer) {
audioAPI.playSound(soundBuffer);
}
};
function initAnimations () {
this.animations[100] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2538
}
],
width: 30,
height: 30,
frames: 2,
animSpeed: ANIMATION_SPEED
}));
this.animations[200] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2598
}
],
width: 30,
height: 30,
frames: 2,
animSpeed: ANIMATION_SPEED
}));
this.animations[400] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2658
}
],
width: 30,
height: 30,
frames: 2,
animSpeed: ANIMATION_SPEED
}));
//one up
this.animations[1] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2719
}
],
width: 30,
height: 30,
frames: 2,
animSpeed: ANIMATION_SPEED
}));
};
function Score (data) {
this.x = data.x || 0;
this.y = data.y || 0;
this.score = data.score || 0;
this.width = 30;
this.height = 30;
this.active = data.x > 0 ? true : false;
this.imperviousToShootingRay = false;
this.sounds = [];
this.sounds[100] = resources.get('score_100'),
this.sounds[200] = resources.get('score_200'),
this.sounds[400] = resources.get('score_400'),
this.animations = [];
this.spriteImg = resources.get('player');
initAnimations.call(this);
};
Score.prototype = new BasicObject();
Score.prototype.update = function (dt) {
this.animations[this.score].update(dt);
};
Score.prototype.activate = function (data) {
this.active = true;
this.x = data.x || 0;
this.y = data.y || 0;
}
Score.prototype.resolveCollision = function (collided) {
if(collided instanceof Player) {
this.active = false;
playCollectionSound.call(this);
}
};
Score.prototype.render = function (viewportContext) {
// viewportContext.fillRect(Math.floor(this.x), Math.floor(this.y), this.width, this.height);
this.animations[this.score].render(viewportContext, this.x, this.y);
};
return Score;
})();