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

Compatibility with flixel 5.9.0 #431

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions flixel/addons/editors/ogmo/FlxOgmo3Loader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ class FlxOgmo3Loader
for (i in 0...tileFlags.length)
{
var flag = tileFlags[i];
#if (flixel < "5.9.0")
var specialTile = new FlxTileSpecial(tilemap.getTileByIndex(i), false, false, 0);
#else
var specialTile = new FlxTileSpecial(tilemap.getTileIndex(i), false, false, 0);
#end

if (flag & 4 > 0)
specialTile.flipX = true;
Expand Down
6 changes: 1 addition & 5 deletions flixel/addons/tile/FlxRayCastTilemap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import flixel.math.FlxPoint;
/**
* @author greglieberman
*/
@:deprecated("FlxRayCastTilemap is deprecated, use FlxTilemap.ray or rayStep, instead")// for flixel 5.9.0
class FlxRayCastTilemap extends FlxTilemap
{
/**
Expand Down Expand Up @@ -222,11 +223,6 @@ class FlxRayCastTilemap extends FlxTilemap
return Y * widthInTiles + X;
}

public function getTileIndex(X:Int, Y:Int):Int
{
return Y * widthInTiles + X;
}

public function coordsToTileX(CoordX:Float):Float
{
return Std.int((CoordX - x) / scaledTileWidth);
Expand Down
93 changes: 89 additions & 4 deletions flixel/addons/tile/FlxTilemapExt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class FlxTilemapExt extends FlxTilemap
}
}

#if (flixel < "5.9.0")
/**
* THIS IS A COPY FROM FlxTilemap BUT IT SOLVES SLOPE COLLISION TOO
* Checks if the Object overlaps any tiles with any collision flags set,
Expand All @@ -334,7 +335,7 @@ class FlxTilemapExt extends FlxTilemap
* @param position Optional, specify a custom position for the tilemap (useful for overlapsAt()-type functionality).
* @return Whether there were overlaps, or if a callback was specified, whatever the return value of the callback was.
*/
override public function overlapsWithCallback(object:FlxObject, ?callback:FlxObject->FlxObject->Bool, flipCallbackParams:Bool = false,
override function overlapsWithCallback(object:FlxObject, ?callback:FlxObject->FlxObject->Bool, flipCallbackParams:Bool = false,
?position:FlxPoint):Bool
{
var results:Bool = false;
Expand Down Expand Up @@ -375,8 +376,7 @@ class FlxTilemapExt extends FlxTilemap
continue;

final tile = _tileObjects[dataIndex];

if (tile.allowCollisions != NONE)
if (tile.solid)
{
var overlapFound = false;

Expand All @@ -400,7 +400,10 @@ class FlxTilemapExt extends FlxTilemap
}
else
{
overlapFound = (object.x + object.width > tile.x) && (object.x < tile.x + tile.width) && (object.y + object.height > tile.y)
overlapFound
= (object.x + object.width > tile.x)
&& (object.x < tile.x + tile.width)
&& (object.y + object.height > tile.y)
&& (object.y < tile.y + tile.height);
}

Expand All @@ -425,6 +428,88 @@ class FlxTilemapExt extends FlxTilemap

return results;
}
#else
/**
* Hacky fix for `FlxTilemapExt`, with all the new changes to 5.9.0 it's better to perfectly
* 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
{
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)
{
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)
{
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 (processCallback != null)
{
overlapFound = processCallback(tile, object);
}
else
{
overlapFound = tile.overlapsObject(object);
}

// New generalized slope collisions
if (overlapFound || checkArrays(tile.index))
{
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);
}
}
}

return results;
}
#end

/**
* Set glue to force contact with slopes and a slow down factor while climbing
Expand Down
12 changes: 8 additions & 4 deletions flixel/addons/weapon/FlxWeapon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,20 @@ class FlxTypedWeapon<TBullet:FlxBullet>
}
}

function shouldBulletHit(Object:FlxObject, Bullet:FlxObject):Bool
function shouldBulletHit(object:FlxObject, bullet:FlxObject):Bool
{
if (parent == Object && skipParentCollision)
if (parent == object && skipParentCollision)
{
return false;
}

if ((Object is FlxTilemap))
if ((object is FlxTilemap))
{
return cast(Object, FlxTilemap).overlapsWithCallback(Bullet);
#if (flixel < "5.9.0")
return cast(object, FlxTilemap).overlapsWithCallback(bullet);
#else
return cast(object, FlxTilemap).processOverlaps(bullet);
#end
}
else
{
Expand Down
Loading