-
Notifications
You must be signed in to change notification settings - Fork 3
/
JumpableBody.js
41 lines (34 loc) · 1.06 KB
/
JumpableBody.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
var JumpableBody = (function () {
function JumpableBody (data) {
this.x = data.x || 0;
this.y = data.y || 0;
this.width = data.width || 0;
this.height = data.height || 0;
this.surface = null;
this.staircase = null;
this.imperviousToShootingRay = false;
};
JumpableBody.prototype = new BasicObject();
JumpableBody.prototype.getCollisionReaction = function (collided) {
var reaction = {
x: undefined,
y: undefined,
vx: undefined,
vy: undefined
};
var prevBottom = undefined;
var elastic = false;
if(collided instanceof Box) {
elastic = true;
}
if(collided.prevy != undefined) {
prevBottom = collided.getPrevBottomY();
}
if(collided.y < this.y && collided.vy > 0 && prevBottom <= this.y){
reaction.y = this.y - collided.height
reaction.vy = elastic ? collided.vy * -1 : 0;
}
return reaction;
};
return JumpableBody;
})();