Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hexus committed Jun 26, 2016
1 parent 6207f71 commit 1741518
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Arcade Slopes Change Log

## v0.1.1 - 26th June 2016
- Implemented corner collision pulling (#3).
- Fixed incompatibility with Phaser 2.4.9 and 2.5.0 (#5).
- Updated the readme regarding changes to physics body sizes before enabling
slopes (#6).

## v0.1.0 - 22nd May 2016
- Collision pulling; an alternative approach to sticky slopes.

Expand Down
84 changes: 68 additions & 16 deletions dist/phaser-arcade-slopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Phaser.Plugin.ArcadeSlopes.prototype.constructor = Phaser.Plugin.ArcadeSlopes;
* @constant
* @type {string}
*/
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.0-beta';
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.1';

/**
* The Separating Axis Theorem collision solver type.
Expand Down Expand Up @@ -286,13 +286,14 @@ Phaser.Plugin.ArcadeSlopes.Overrides = {};
* @param {integer} i - The tile index.
* @param {Phaser.Sprite} sprite - The sprite to check.
* @param {Phaser.Tile} tile - The tile to check.
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemap layer the tile belongs to.
* @param {function} collideCallback - An optional collision callback.
* @param {function} processCallback - An optional overlap processing callback.
* @param {object} callbackContext - The context in which to run the callbacks.
* @param {boolean} overlapOnly - Whether to only check for an overlap.
* @return {boolean} - Whether a collision occurred.
*/
Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite, tile, collideCallback, processCallback, callbackContext, overlapOnly) {
Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite, tile, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) {
if (!sprite.body) {
return false;
}
Expand All @@ -307,7 +308,7 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite,

return true;
}
} else if (this.separateTile(i, sprite.body, tile, overlapOnly)) {
} else if (this.separateTile(i, sprite.body, tile, tilemapLayer, overlapOnly)) {
this._total++;

if (collideCallback) {
Expand All @@ -326,13 +327,14 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite,
* @method Phaser.Plugin.ArcadeSlopes.Overrides#collideSpriteVsTiles
* @param {Phaser.Sprite} sprite - The sprite to check.
* @param {Phaser.Tile[]} tiles - The tiles to check.
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemap layer the tiles belong to.
* @param {function} collideCallback - An optional collision callback.
* @param {function} processCallback - An optional overlap processing callback.
* @param {object} callbackContext - The context in which to run the callbacks.
* @param {boolean} overlapOnly - Whether to only check for an overlap.
* @return {boolean} - Whether a collision occurred.
*/
Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTiles = function (sprite, tiles, collideCallback, processCallback, callbackContext, overlapOnly) {
Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTiles = function (sprite, tiles, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) {
var collided = false;

if (!sprite.body) {
Expand All @@ -342,10 +344,10 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTiles = function (sprite, ti
for (var i = 0; i < tiles.length; i++) {
if (processCallback) {
if (processCallback.call(callbackContext, sprite, tiles[i])) {
collided = this.collideSpriteVsTile(i, sprite, tiles[i], collideCallback, processCallback, callbackContext, overlapOnly) || collided;
collided = this.collideSpriteVsTile(i, sprite, tiles[i], tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) || collided;
}
} else {
collided = this.collideSpriteVsTile(i, sprite, tiles[i], collideCallback, processCallback, callbackContext, overlapOnly) || collided;
collided = this.collideSpriteVsTile(i, sprite, tiles[i], tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) || collided;
}
}

Expand Down Expand Up @@ -385,7 +387,7 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTilemapLayer = function (spr
return false;
}

var collided = this.collideSpriteVsTiles(sprite, tiles, collideCallback, processCallback, callbackContext, overlapOnly);
var collided = this.collideSpriteVsTiles(sprite, tiles, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly);

if (!collided && !overlapOnly) {
// TODO: This call is too hacky and solver-specific
Expand Down Expand Up @@ -1691,13 +1693,17 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snap = function (body, tiles) {
/**
* Pull the body into a collision response based on its slopes options.
*
* TODO: Refactor; don't return after any condition is met, accumulate values
* into a single SAT.Vector and apply at the end.
*
* @method Phaser.Plugin.ArcadeSlopes.SatSolver#pull
* @param {Phaser.Physics.Arcade.Body} body - The physics body.
* @param {SAT.Response} response - The SAT response.
* @return {boolean} - Whether the body was pulled.
*/
Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.pull = function (body, response) {
if (!body.slopes.pullUp && !body.slopes.pullDown && !body.slopes.pullLeft && !body.slopes.pullRight) {
if (!body.slopes.pullUp && !body.slopes.pullDown && !body.slopes.pullLeft && !body.slopes.pullRight &&
!body.slopes.pullTopLeft && !body.slopes.pullTopRight && !body.slopes.pullBottomLeft && !body.slopes.pullBottomRight) {
return false;
}

Expand All @@ -1716,32 +1722,62 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.pull = function (body, response)
}

if (body.slopes.pullDown && overlapN.y > 0) {
// Scale it by the configured amount
pullDown = overlapN.clone().scale(body.slopes.pullDown);

// Apply it to the body velocity
body.velocity.x += pullDown.x;
body.velocity.y += pullDown.y;

return true;
}

if (body.slopes.pullLeft && overlapN.x < 0) {
// Scale it by the configured amount
pullLeft = overlapN.clone().scale(body.slopes.pullLeft);

// Apply it to the body velocity
body.velocity.x += pullLeft.x;
body.velocity.y += pullLeft.y;

return true;
}

if (body.slopes.pullRight && overlapN.x > 0) {
// Scale it by the configured amount
pullRight = overlapN.clone().scale(body.slopes.pullRight);

// Apply it to the body velocity
body.velocity.x += pullRight.x;
body.velocity.y += pullRight.y;

return true;
}

if (body.slopes.pullTopLeft && overlapN.x < 0 && overlapN.y < 0) {
pullUp = overlapN.clone().scale(body.slopes.pullTopLeft);

body.velocity.x += pullUp.x;
body.velocity.y += pullUp.y;

return true;
}

if (body.slopes.pullTopRight && overlapN.x > 0 && overlapN.y < 0) {
pullDown = overlapN.clone().scale(body.slopes.pullTopRight);

body.velocity.x += pullDown.x;
body.velocity.y += pullDown.y;

return true;
}

if (body.slopes.pullBottomLeft && overlapN.x < 0 && overlapN.y > 0) {
pullLeft = overlapN.clone().scale(body.slopes.pullBottomLeft);

body.velocity.x += pullLeft.x;
body.velocity.y += pullLeft.y;

return true;
}

if (body.slopes.pullBottomRight && overlapN.x > 0 && overlapN.y > 0) {
pullRight = overlapN.clone().scale(body.slopes.pullBottomRight);

body.velocity.x += pullRight.x;
body.velocity.y += pullRight.y;

Expand Down Expand Up @@ -1773,6 +1809,22 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snapCollide = function (body, til
return false;
};

/**
* Determine whether everything required to process a collision is available.
*
* @method Phaser.Plugin.ArcadeSlopes.SatSolver#shouldCollide
* @param {Phaser.Physics.Arcade.Body} body - The physics body.
* @param {Phaser.Tile} tile - The tile.
* @return {boolean}
*/
Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.shouldCollide = function (body, tile) {
if (body.enable && body.polygon && body.slopes && tile.collides && tile.slope && tile.slope.polygon) {
return true;
}

return false;
};

/**
* Separate the given body and tile from each other and apply any relevant
* changes to the body's velocity.
Expand All @@ -1789,7 +1841,7 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snapCollide = function (body, til
*/
Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.collide = function (i, body, tile, overlapOnly) {
// Bail out if we don't have everything we need
if (!(body.enable && body.polygon && body.slopes && tile.slope && tile.slope.polygon)) {
if (!this.shouldCollide(body, tile)) {
return false;
}

Expand Down Expand Up @@ -1849,7 +1901,7 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.collide = function (i, body, tile
*/
Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.collideOnAxis = function (body, tile, axis, response) {
// Bail out if we don't have everything we need
if (!(body.enable && body.polygon && body.slopes && tile.slope && tile.slope.polygon)) {
if (!this.shouldCollide(body, tile)) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/phaser-arcade-slopes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phaser-arcade-slopes",
"version": "0.1.1-dev",
"version": "0.1.1",
"description": "A Phaser plugin that provides sloped tiles for the Arcade Physics engine.",
"main": "dist/phaser-arcade-slopes.js",
"scripts": {},
Expand Down
2 changes: 1 addition & 1 deletion src/ArcadeSlopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Phaser.Plugin.ArcadeSlopes.prototype.constructor = Phaser.Plugin.ArcadeSlopes;
* @constant
* @type {string}
*/
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.1-dev';
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.1';

/**
* The Separating Axis Theorem collision solver type.
Expand Down
3 changes: 3 additions & 0 deletions src/ArcadeSlopes/SatSolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snap = function (body, tiles) {
/**
* Pull the body into a collision response based on its slopes options.
*
* TODO: Refactor; don't return after any condition is met, accumulate values
* into a single SAT.Vector and apply at the end.
*
* @method Phaser.Plugin.ArcadeSlopes.SatSolver#pull
* @param {Phaser.Physics.Arcade.Body} body - The physics body.
* @param {SAT.Response} response - The SAT response.
Expand Down

0 comments on commit 1741518

Please sign in to comment.