-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriggerArea.js
72 lines (68 loc) · 2.46 KB
/
TriggerArea.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
Adventurous.TriggerArea = function(obj)
{
this.name = obj.name;
this.rect = new Phaser.Rectangle(parseInt(obj.x),parseInt(obj.y),parseInt(obj.w),parseInt(obj.h));
this.overlapsPlayer = false;
this.conditions = obj.conditions;
this.interactions = Adventurous.interactions[this.name];
};
Adventurous.TriggerArea.prototype =
{
update: function () //some parts sorta copied from Interactions.js
{
if(currentState.activeEffects == null && Adventurous.Util.areConditionsMet(this.conditions))
{
for(var i = 0; i < this.interactions.withItem[""].interactions.length; i++)
{
var interactionSet = this.interactions.withItem[""].interactions[i];
switch(interactionSet.when)
{
case Adventurous.Constants.ON_ENTER:
if(this.playerJustEntered())
{
if(Adventurous.Util.areConditionsMet(interactionSet.conditions))
{
currentState.activeEffects = new Adventurous.Effects(currentState.player,interactionSet.effects,this.name);
currentState.cursor.hide();
}
}
break;
case Adventurous.Constants.ON_EXIT:
if(this.playerJustExited())
{
if(Adventurous.Util.areConditionsMet(interactionSet.conditions))
{
currentState.activeEffects = new Adventurous.Effects(currentState.player,interactionSet.effects,this.name);
currentState.cursor.hide();
}
}
break;
}
}
}
},
playerJustEntered: function()
{
if(!this.overlapsPlayer)
{
this.overlapsPlayer = currentState.player.isStandingIn(this.rect);
return this.overlapsPlayer;
}
else
{
return false;
}
},
playerJustExited: function()
{
if(this.overlapsPlayer)
{
this.overlapsPlayer = currentState.player.isStandingIn(this.rect);
return !this.overlapsPlayer;
}
else
{
return false;
}
}
};