Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tilemapext overlaps #432

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading