Skip to content

Commit

Permalink
Hit-testing for z-index now uses map position
Browse files Browse the repository at this point in the history
  • Loading branch information
basicallydan committed Feb 17, 2013
1 parent 8dfe1d5 commit 158f797
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion js/monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Sprite = require('./Sprite');
var super_draw = that.superior('draw');
var spriteVersion = 1;
var eatingStage = 0;
var standardSpeed = 4;
var standardSpeed = 6;

that.isEating = false;
that.isFull = false;
Expand Down
8 changes: 3 additions & 5 deletions js/skier.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var Sprite = require('./Sprite');
return false;
}

if (!obs.occupiesZIndex(that.canvasZ)) {
if (!obs.occupiesZIndex(that.mapPosition[2])) {
return false;
}

Expand Down Expand Up @@ -175,15 +175,13 @@ var Sprite = require('./Sprite');
that.isMoving = true;
that.hasBeenHit = false;
that.isJumping = true;
that.canvasZ = 1;
// that.incrementSpeedBy(1);
that.setMapPosition(undefined, undefined, 1);
if (cancelableStateTimeout) {
clearTimeout(cancelableStateTimeout);
}
cancelableStateTimeout = setTimeout(function() {
that.canvasZ = 0;
that.setMapPosition(undefined, undefined, 0);
that.isJumping = false;
// that.incrementSpeedBy(-1);
}, 1000);
};

Expand Down
14 changes: 10 additions & 4 deletions js/sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
};

this.setMapPosition = function (x, y, z) {
if (typeof x === 'undefined') {
x = that.mapPosition[0];
}
if (typeof y === 'undefined') {
y = that.mapPosition[1];
}
if (typeof z === 'undefined') {
z = that.mapPosition[2];
}
Expand Down Expand Up @@ -291,22 +297,22 @@
var horizontalIntersect = false;

// Test that THIS has a bottom edge inside of the other object
if (other.getTopHitBoxEdge(that.canvasZ) <= that.getBottomHitBoxEdge(that.canvasZ) && other.getBottomHitBoxEdge(that.canvasZ) >= that.getBottomHitBoxEdge(that.canvasZ)) {
if (other.getTopHitBoxEdge(that.mapPosition[2]) <= that.getBottomHitBoxEdge(that.mapPosition[2]) && other.getBottomHitBoxEdge(that.mapPosition[2]) >= that.getBottomHitBoxEdge(that.mapPosition[2])) {
verticalIntersect = true;
}

// Test that THIS has a top edge inside of the other object
if (other.getTopHitBoxEdge(that.canvasZ) <= that.getTopHitBoxEdge(that.canvasZ) && other.getBottomHitBoxEdge(that.canvasZ) >= that.getTopHitBoxEdge(that.canvasZ)) {
if (other.getTopHitBoxEdge(that.mapPosition[2]) <= that.getTopHitBoxEdge(that.mapPosition[2]) && other.getBottomHitBoxEdge(that.mapPosition[2]) >= that.getTopHitBoxEdge(that.mapPosition[2])) {
verticalIntersect = true;
}

// Test that THIS has a right edge inside of the other object
if (other.getLeftHitBoxEdge(that.canvasZ) <= that.getRightHitBoxEdge(that.canvasZ) && other.getRightHitBoxEdge(that.canvasZ) >= that.getRightHitBoxEdge(that.canvasZ)) {
if (other.getLeftHitBoxEdge(that.mapPosition[2]) <= that.getRightHitBoxEdge(that.mapPosition[2]) && other.getRightHitBoxEdge(that.mapPosition[2]) >= that.getRightHitBoxEdge(that.mapPosition[2])) {
horizontalIntersect = true;
}

// Test that THIS has a left edge inside of the other object
if (other.getLeftHitBoxEdge(that.canvasZ) <= that.getLeftHitBoxEdge(that.canvasZ) && other.getRightHitBoxEdge(that.canvasZ) >= that.getLeftHitBoxEdge(that.canvasZ)) {
if (other.getLeftHitBoxEdge(that.mapPosition[2]) <= that.getLeftHitBoxEdge(that.mapPosition[2]) && other.getRightHitBoxEdge(that.mapPosition[2]) >= that.getLeftHitBoxEdge(that.mapPosition[2])) {
horizontalIntersect = true;
}

Expand Down

0 comments on commit 158f797

Please sign in to comment.