@@ -58,7 +58,7 @@ Phaser.Plugin.ArcadeSlopes.prototype.constructor = Phaser.Plugin.ArcadeSlopes;
58
58
* @constant
59
59
* @type {string }
60
60
*/
61
- Phaser . Plugin . ArcadeSlopes . VERSION = '0.1.0-beta ' ;
61
+ Phaser . Plugin . ArcadeSlopes . VERSION = '0.1.1 ' ;
62
62
63
63
/**
64
64
* The Separating Axis Theorem collision solver type.
@@ -286,13 +286,14 @@ Phaser.Plugin.ArcadeSlopes.Overrides = {};
286
286
* @param {integer } i - The tile index.
287
287
* @param {Phaser.Sprite } sprite - The sprite to check.
288
288
* @param {Phaser.Tile } tile - The tile to check.
289
+ * @param {Phaser.TilemapLayer } tilemapLayer - The tilemap layer the tile belongs to.
289
290
* @param {function } collideCallback - An optional collision callback.
290
291
* @param {function } processCallback - An optional overlap processing callback.
291
292
* @param {object } callbackContext - The context in which to run the callbacks.
292
293
* @param {boolean } overlapOnly - Whether to only check for an overlap.
293
294
* @return {boolean } - Whether a collision occurred.
294
295
*/
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 ) {
296
297
if ( ! sprite . body ) {
297
298
return false ;
298
299
}
@@ -307,7 +308,7 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite,
307
308
308
309
return true ;
309
310
}
310
- } else if ( this . separateTile ( i , sprite . body , tile , overlapOnly ) ) {
311
+ } else if ( this . separateTile ( i , sprite . body , tile , tilemapLayer , overlapOnly ) ) {
311
312
this . _total ++ ;
312
313
313
314
if ( collideCallback ) {
@@ -326,13 +327,14 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTile = function (i, sprite,
326
327
* @method Phaser.Plugin.ArcadeSlopes.Overrides#collideSpriteVsTiles
327
328
* @param {Phaser.Sprite } sprite - The sprite to check.
328
329
* @param {Phaser.Tile[] } tiles - The tiles to check.
330
+ * @param {Phaser.TilemapLayer } tilemapLayer - The tilemap layer the tiles belong to.
329
331
* @param {function } collideCallback - An optional collision callback.
330
332
* @param {function } processCallback - An optional overlap processing callback.
331
333
* @param {object } callbackContext - The context in which to run the callbacks.
332
334
* @param {boolean } overlapOnly - Whether to only check for an overlap.
333
335
* @return {boolean } - Whether a collision occurred.
334
336
*/
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 ) {
336
338
var collided = false ;
337
339
338
340
if ( ! sprite . body ) {
@@ -342,10 +344,10 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTiles = function (sprite, ti
342
344
for ( var i = 0 ; i < tiles . length ; i ++ ) {
343
345
if ( processCallback ) {
344
346
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 ;
346
348
}
347
349
} 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 ;
349
351
}
350
352
}
351
353
@@ -385,7 +387,7 @@ Phaser.Plugin.ArcadeSlopes.Overrides.collideSpriteVsTilemapLayer = function (spr
385
387
return false ;
386
388
}
387
389
388
- var collided = this . collideSpriteVsTiles ( sprite , tiles , collideCallback , processCallback , callbackContext , overlapOnly ) ;
390
+ var collided = this . collideSpriteVsTiles ( sprite , tiles , tilemapLayer , collideCallback , processCallback , callbackContext , overlapOnly ) ;
389
391
390
392
if ( ! collided && ! overlapOnly ) {
391
393
// TODO: This call is too hacky and solver-specific
@@ -1691,13 +1693,17 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snap = function (body, tiles) {
1691
1693
/**
1692
1694
* Pull the body into a collision response based on its slopes options.
1693
1695
*
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
+ *
1694
1699
* @method Phaser.Plugin.ArcadeSlopes.SatSolver#pull
1695
1700
* @param {Phaser.Physics.Arcade.Body } body - The physics body.
1696
1701
* @param {SAT.Response } response - The SAT response.
1697
1702
* @return {boolean } - Whether the body was pulled.
1698
1703
*/
1699
1704
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 ) {
1701
1707
return false ;
1702
1708
}
1703
1709
@@ -1716,32 +1722,62 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.pull = function (body, response)
1716
1722
}
1717
1723
1718
1724
if ( body . slopes . pullDown && overlapN . y > 0 ) {
1719
- // Scale it by the configured amount
1720
1725
pullDown = overlapN . clone ( ) . scale ( body . slopes . pullDown ) ;
1721
1726
1722
- // Apply it to the body velocity
1723
1727
body . velocity . x += pullDown . x ;
1724
1728
body . velocity . y += pullDown . y ;
1725
1729
1726
1730
return true ;
1727
1731
}
1728
1732
1729
1733
if ( body . slopes . pullLeft && overlapN . x < 0 ) {
1730
- // Scale it by the configured amount
1731
1734
pullLeft = overlapN . clone ( ) . scale ( body . slopes . pullLeft ) ;
1732
1735
1733
- // Apply it to the body velocity
1734
1736
body . velocity . x += pullLeft . x ;
1735
1737
body . velocity . y += pullLeft . y ;
1736
1738
1737
1739
return true ;
1738
1740
}
1739
1741
1740
1742
if ( body . slopes . pullRight && overlapN . x > 0 ) {
1741
- // Scale it by the configured amount
1742
1743
pullRight = overlapN . clone ( ) . scale ( body . slopes . pullRight ) ;
1743
1744
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
+
1745
1781
body . velocity . x += pullRight . x ;
1746
1782
body . velocity . y += pullRight . y ;
1747
1783
@@ -1773,6 +1809,22 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snapCollide = function (body, til
1773
1809
return false ;
1774
1810
} ;
1775
1811
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
+
1776
1828
/**
1777
1829
* Separate the given body and tile from each other and apply any relevant
1778
1830
* changes to the body's velocity.
@@ -1789,7 +1841,7 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.snapCollide = function (body, til
1789
1841
*/
1790
1842
Phaser . Plugin . ArcadeSlopes . SatSolver . prototype . collide = function ( i , body , tile , overlapOnly ) {
1791
1843
// 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 ) ) {
1793
1845
return false ;
1794
1846
}
1795
1847
@@ -1849,7 +1901,7 @@ Phaser.Plugin.ArcadeSlopes.SatSolver.prototype.collide = function (i, body, tile
1849
1901
*/
1850
1902
Phaser . Plugin . ArcadeSlopes . SatSolver . prototype . collideOnAxis = function ( body , tile , axis , response ) {
1851
1903
// 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 ) ) {
1853
1905
return false ;
1854
1906
}
1855
1907
0 commit comments