diff --git a/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx b/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx index 95dd88f5..b5702fa0 100644 --- a/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx +++ b/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx @@ -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; diff --git a/flixel/addons/tile/FlxRayCastTilemap.hx b/flixel/addons/tile/FlxRayCastTilemap.hx index 3d5e5b13..b708ba1b 100644 --- a/flixel/addons/tile/FlxRayCastTilemap.hx +++ b/flixel/addons/tile/FlxRayCastTilemap.hx @@ -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 { /** @@ -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); diff --git a/flixel/addons/tile/FlxTilemapExt.hx b/flixel/addons/tile/FlxTilemapExt.hx index 7973569b..538241f3 100644 --- a/flixel/addons/tile/FlxTilemapExt.hx +++ b/flixel/addons/tile/FlxTilemapExt.hx @@ -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, @@ -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; @@ -375,8 +376,7 @@ class FlxTilemapExt extends FlxTilemap continue; final tile = _tileObjects[dataIndex]; - - if (tile.allowCollisions != NONE) + if (tile.solid) { var overlapFound = false; @@ -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); } @@ -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(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 diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 0c43dd37..d8c04de5 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -430,16 +430,20 @@ class FlxTypedWeapon } } - 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 {