-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanimated_object.js
More file actions
39 lines (32 loc) · 1.22 KB
/
animated_object.js
File metadata and controls
39 lines (32 loc) · 1.22 KB
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
pc.script.attribute('collectibleName', 'string');
pc.script.attribute('numCollectibles', 'number');
pc.script.attribute('animationName', 'string');
pc.script.attribute('fuel', 'number', 20);
pc.script.create('animated_object', function (context) {
var Animated_object = function (entity) {
this.entity = entity;
};
Animated_object.prototype = {
initialize: function () {
this.game = context.root.findByName('Game').script.game;
this.game.on('reset', this.reset, this);
this.game.on('pickup', this.onPickup, this);
this.reset();
},
reset: function () {
this.collectiblesPicked = 0;
},
onPickup: function (collectible) {
if (collectible.entity.getName() === this.collectibleName) {
this.collectiblesPicked++;
if (this.collectiblesPicked >= this.numCollectibles) {
this.collectiblesPicked = 0;
this.entity.animation.play(this.animationName);
// reward the player with some fuel
this.game.setFuel(this.game.fuel + this.fuel);
}
}
}
};
return Animated_object;
});