Skip to content

Commit

Permalink
Tilemapext overlaps (#432)
Browse files Browse the repository at this point in the history
* use forEachOverlappingTile after all

* rename method
  • Loading branch information
Geokureli authored Jun 6, 2024
1 parent ed40318 commit 83a0984
Showing 1 changed file with 26 additions and 62 deletions.
88 changes: 26 additions & 62 deletions flixel/addons/tile/FlxTilemapExt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -434,79 +434,43 @@ class FlxTilemapExt extends FlxTilemap
* recreate the old behavior, here and then make a new tilemap with slopes that uses the new
* features to eventually replace it
*/
override function processOverlaps<TObj:FlxObject>(object:TObj, ?processCallback:(FlxTile, TObj)->Bool, ?position:FlxPoint, isCollision = true):Bool
override function objectOverlapsTiles<TObj:FlxObject>(object:TObj, ?callback:(FlxTile, TObj)->Bool, ?position:FlxPoint, isCollision = true):Bool
{
var results:Bool = false;

var xPos:Float = x;
var yPos:Float = y;

if (position != null)
{
xPos = position.x;
yPos = position.y;
position.putWeak();
}

inline function bindInt(value:Int, min:Int, max:Int)
var results = false;
function each(tile:FlxTile)
{
return Std.int(FlxMath.bound(value, min, max));
}

// Figure out what tiles we need to check against, and bind them by the map edges
final minTileX:Int = bindInt(Math.floor((object.x - xPos) / scaledTileWidth), 0, widthInTiles);
final minTileY:Int = bindInt(Math.floor((object.y - yPos) / scaledTileHeight), 0, heightInTiles);
final maxTileX:Int = bindInt(Math.ceil((object.x + object.width - xPos) / scaledTileWidth), 0, widthInTiles);
final maxTileY:Int = bindInt(Math.ceil((object.y + object.height - yPos) / scaledTileHeight), 0, heightInTiles);

// Cache tilemap movement
final deltaX:Float = xPos - last.x;
final deltaY:Float = yPos - last.y;

// Loop through the range of tiles and call the callback on them, accordingly
for (row in minTileY...maxTileY)
{
for (column in minTileX...maxTileX)
if (tile.solid)
{
final mapIndex:Int = (row * widthInTiles) + column;
final dataIndex:Int = _data[mapIndex];
if (dataIndex < 0)
continue;

final tile = _tileObjects[dataIndex];
tile.orientAt(xPos, yPos, column, row);

if (tile.solid)
var overlapFound = false;
if (callback != null)
{
var overlapFound = false;
if (processCallback != null)
{
overlapFound = processCallback(tile, object);
}
else
{
overlapFound = tile.overlapsObject(object);
}
overlapFound = callback(tile, object);
}
else
{
overlapFound = tile.overlapsObject(object);
}

// New generalized slope collisions
if (overlapFound || checkArrays(tile.index))
// New generalized slope collisions
if (overlapFound || checkArrays(tile.index))
{
if (tile.callbackFunction != null)
{
if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter)))
{
tile.callbackFunction(tile, object);
tile.onCollide.dispatch(tile, object);
}
results = true;
tile.callbackFunction(tile, object);
tile.onCollide.dispatch(tile, object);
}
}
else if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter)))
{
tile.callbackFunction(tile, object);
tile.onCollide.dispatch(tile, object);
results = true;
}
}
else if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter)))
{
tile.callbackFunction(tile, object);
tile.onCollide.dispatch(tile, object);
}
}

forEachOverlappingTile(object, each, position);

return results;
}
#end
Expand Down

0 comments on commit 83a0984

Please sign in to comment.