Skip to content

Commit 1741518

Browse files
committed
v0.1.1
1 parent 6207f71 commit 1741518

File tree

6 files changed

+81
-20
lines changed

6 files changed

+81
-20
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Arcade Slopes Change Log
22

3+
## v0.1.1 - 26th June 2016
4+
- Implemented corner collision pulling (#3).
5+
- Fixed incompatibility with Phaser 2.4.9 and 2.5.0 (#5).
6+
- Updated the readme regarding changes to physics body sizes before enabling
7+
slopes (#6).
8+
39
## v0.1.0 - 22nd May 2016
410
- Collision pulling; an alternative approach to sticky slopes.
511

dist/phaser-arcade-slopes.js

+68-16
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Phaser.Plugin.ArcadeSlopes.prototype.constructor = Phaser.Plugin.ArcadeSlopes;
5858
* @constant
5959
* @type {string}
6060
*/
61-
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.0-beta';
61+
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.1';
6262

6363
/**
6464
* The Separating Axis Theorem collision solver type.
@@ -286,13 +286,14 @@ Phaser.Plugin.ArcadeSlopes.Overrides = {};
286286
* @param {integer} i - The tile index.
287287
* @param {Phaser.Sprite} sprite - The sprite to check.
288288
* @param {Phaser.Tile} tile - The tile to check.
289+
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemap layer the tile belongs to.
289290
* @param {function} collideCallback - An optional collision callback.
290291
* @param {function} processCallback - An optional overlap processing callback.
291292
* @param {object} callbackContext - The context in which to run the callbacks.
292293
* @param {boolean} overlapOnly - Whether to only check for an overlap.
293294
* @return {boolean} - Whether a collision occurred.
294295
*/
295-
Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite, tile, collideCallback, processCallback, callbackContext, overlapOnly) {
296+
Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite, tile, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) {
296297
if (!sprite.body) {
297298
return false;
298299
}
@@ -307,7 +308,7 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite,
307308

308309
return true;
309310
}
310-
} else if (this.separateTile(i, sprite.body, tile, overlapOnly)) {
311+
} else if (this.separateTile(i, sprite.body, tile, tilemapLayer, overlapOnly)) {
311312
this._total++;
312313

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

338340
if (!sprite.body) {
@@ -342,10 +344,10 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTiles = function (sprite, ti
342344
for (var i = 0; i < tiles.length; i++) {
343345
if (processCallback) {
344346
if (processCallback.call(callbackContext, sprite, tiles[i])) {
345-
collided = this.collideSpriteVsTile(i, sprite, tiles[i], collideCallback, processCallback, callbackContext, overlapOnly) || collided;
347+
collided = this.collideSpriteVsTile(i, sprite, tiles[i], tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) || collided;
346348
}
347349
} else {
348-
collided = this.collideSpriteVsTile(i, sprite, tiles[i], collideCallback, processCallback, callbackContext, overlapOnly) || collided;
350+
collided = this.collideSpriteVsTile(i, sprite, tiles[i], tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) || collided;
349351
}
350352
}
351353

@@ -385,7 +387,7 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTilemapLayer = function (spr
385387
return false;
386388
}
387389

388-
var collided = this.collideSpriteVsTiles(sprite, tiles, collideCallback, processCallback, callbackContext, overlapOnly);
390+
var collided = this.collideSpriteVsTiles(sprite, tiles, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly);
389391

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

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

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

1722-
// Apply it to the body velocity
17231727
body.velocity.x += pullDown.x;
17241728
body.velocity.y += pullDown.y;
17251729

17261730
return true;
17271731
}
17281732

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

1733-
// Apply it to the body velocity
17341736
body.velocity.x += pullLeft.x;
17351737
body.velocity.y += pullLeft.y;
17361738

17371739
return true;
17381740
}
17391741

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

1744-
// Apply it to the body velocity
1745+
body.velocity.x += pullRight.x;
1746+
body.velocity.y += pullRight.y;
1747+
1748+
return true;
1749+
}
1750+
1751+
if (body.slopes.pullTopLeft && overlapN.x < 0 && overlapN.y < 0) {
1752+
pullUp = overlapN.clone().scale(body.slopes.pullTopLeft);
1753+
1754+
body.velocity.x += pullUp.x;
1755+
body.velocity.y += pullUp.y;
1756+
1757+
return true;
1758+
}
1759+
1760+
if (body.slopes.pullTopRight && overlapN.x > 0 && overlapN.y < 0) {
1761+
pullDown = overlapN.clone().scale(body.slopes.pullTopRight);
1762+
1763+
body.velocity.x += pullDown.x;
1764+
body.velocity.y += pullDown.y;
1765+
1766+
return true;
1767+
}
1768+
1769+
if (body.slopes.pullBottomLeft && overlapN.x < 0 && overlapN.y > 0) {
1770+
pullLeft = overlapN.clone().scale(body.slopes.pullBottomLeft);
1771+
1772+
body.velocity.x += pullLeft.x;
1773+
body.velocity.y += pullLeft.y;
1774+
1775+
return true;
1776+
}
1777+
1778+
if (body.slopes.pullBottomRight && overlapN.x > 0 && overlapN.y > 0) {
1779+
pullRight = overlapN.clone().scale(body.slopes.pullBottomRight);
1780+
17451781
body.velocity.x += pullRight.x;
17461782
body.velocity.y += pullRight.y;
17471783

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

1812+
/**
1813+
* Determine whether everything required to process a collision is available.
1814+
*
1815+
* @method Phaser.Plugin.ArcadeSlopes.SatSolver#shouldCollide
1816+
* @param {Phaser.Physics.Arcade.Body} body - The physics body.
1817+
* @param {Phaser.Tile} tile - The tile.
1818+
* @return {boolean}
1819+
*/
1820+
Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.shouldCollide = function (body, tile) {
1821+
if (body.enable && body.polygon && body.slopes && tile.collides && tile.slope && tile.slope.polygon) {
1822+
return true;
1823+
}
1824+
1825+
return false;
1826+
};
1827+
17761828
/**
17771829
* Separate the given body and tile from each other and apply any relevant
17781830
* changes to the body's velocity.
@@ -1789,7 +1841,7 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snapCollide = function (body, til
17891841
*/
17901842
Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.collide = function (i, body, tile, overlapOnly) {
17911843
// Bail out if we don't have everything we need
1792-
if (!(body.enable && body.polygon && body.slopes && tile.slope && tile.slope.polygon)) {
1844+
if (!this.shouldCollide(body, tile)) {
17931845
return false;
17941846
}
17951847

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

dist/phaser-arcade-slopes.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "phaser-arcade-slopes",
3-
"version": "0.1.1-dev",
3+
"version": "0.1.1",
44
"description": "A Phaser plugin that provides sloped tiles for the Arcade Physics engine.",
55
"main": "dist/phaser-arcade-slopes.js",
66
"scripts": {},

src/ArcadeSlopes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Phaser.Plugin.ArcadeSlopes.prototype.constructor = Phaser.Plugin.ArcadeSlopes;
5858
* @constant
5959
* @type {string}
6060
*/
61-
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.1-dev';
61+
Phaser.Plugin.ArcadeSlopes.VERSION = '0.1.1';
6262

6363
/**
6464
* The Separating Axis Theorem collision solver type.

src/ArcadeSlopes/SatSolver.js

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snap = function (body, tiles) {
348348
/**
349349
* Pull the body into a collision response based on its slopes options.
350350
*
351+
* TODO: Refactor; don't return after any condition is met, accumulate values
352+
* into a single SAT.Vector and apply at the end.
353+
*
351354
* @method Phaser.Plugin.ArcadeSlopes.SatSolver#pull
352355
* @param {Phaser.Physics.Arcade.Body} body - The physics body.
353356
* @param {SAT.Response} response - The SAT response.

0 commit comments

Comments
 (0)