-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollectible.js
More file actions
71 lines (59 loc) · 2.06 KB
/
collectible.js
File metadata and controls
71 lines (59 loc) · 2.06 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
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
pc.script.attribute('points', 'number', 10);
pc.script.attribute('fuel', 'number', 0);
pc.script.attribute('radius', 'number', 2.5);
pc.script.attribute('correctPosition', 'boolean', false);
pc.script.attribute('regenerate', 'boolean', true);
pc.script.attribute('triggerBonusMode', 'boolean', false);
pc.script.attribute('isMegaGem', 'boolean', false);
pc.script.attribute('isHeal', 'boolean', false);
pc.script.attribute('isStreak', 'boolean', false);
pc.script.attribute('effectName', 'string');
pc.script.create('collectible', function (context) {
var temp = new pc.Vec3();
var game = null;
var Collectible = function (entity) {
this.entity = entity;
};
Collectible.prototype = {
initialize: function () {
if (!game) {
game = context.root.findByName('Game').script.game;
}
if (this.regenerate) {
game.on('reset', this.reset, this);
}
if (this.correctPosition) {
var pos = this.entity.getPosition();
game.clampToRadius(pos);
this.entity.setPosition(pos);
}
},
reset: function () {
this.entity.enabled = true;
},
onEnable: function () {
if (this.regenerate) {
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = null;
}
}
game.physics.addCollider(this);
},
containsPlayer: function (player) {
var obb = player.obb;
return game.physics.testSphereObb(this.entity.getPosition(), this.radius, obb);
},
onContact: function () {
this.entity.enabled = false;
game.fire('pickup', this);
if (this.regenerate) {
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(this.reset.bind(this), 30000);
}
}
};
return Collectible;
});