-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectible.js
More file actions
38 lines (29 loc) · 880 Bytes
/
Collectible.js
File metadata and controls
38 lines (29 loc) · 880 Bytes
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
function Collectible(descr) {
this.setup(descr);
this.sprite = g_sprites.collectible;
this._scale = 1;
this._width = this.sprite.width;
this. height = this.sprite.height;
this.radius = this._width/2;
this._isCollected = false;
}
//Collectibles are entities
Collectible.prototype = new Entity();
Collectible.prototype.update = function(du) {
spatialManager.unregister(this);
if (this._isCollected) return entityManager.KILL_ME_NOW;
if (this.isColliding().isCharacter) {
eat.volume = 1;
eat.play();
this._isCollected = true;
g_currentLevel.collectibles--;
} else {
spatialManager.register(this);
}
}
Collectible.prototype.render = function (ctx) {
var origScale = this.sprite.scale;
this.sprite.scale = this._scale;
this.sprite.drawWrappedCentredAt(ctx, this.cx, this.cy, this.rotation);
this.sprite.scale = origScale;
}