-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeliveryzonetrigger.js
32 lines (27 loc) · 1.1 KB
/
deliveryzonetrigger.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
pc.script.create('deliveryzonetrigger', function (context) {
// Creates a new Deliveryzonetrigger instance
var Deliveryzonetrigger = function (entity) {
this.entity = entity;
};
Deliveryzonetrigger.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
this.entity.collision.on('triggerleave', this.onTriggerLeave, this);
},
onTriggerEnter: function (entity) {
if (entity.getName().indexOf('Pipe') !== -1) {
context.root.findByName('Pipe Wars').script.game.updatePipesDelivered(1);
}
},
onTriggerLeave: function (entity) {
if (entity.getName().indexOf('Pipe') !== -1) {
context.root.findByName('Pipe Wars').script.game.updatePipesDelivered(-1);
}
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
}
};
return Deliveryzonetrigger;
});