Skip to content
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
8 changes: 8 additions & 0 deletions flixel/FlxObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,16 @@ class FlxObject extends FlxBasic
*/
public static function separate(object1:FlxObject, object2:FlxObject):Bool
{
var tmp1 = object1.last.copyTo();
var tmp2 = object2.last.copyTo();
final separatedX = separateX(object1, object2);
object1.last.x = object1.x;
object2.last.x = object2.x;
final separatedY = separateY(object1, object2);
object1.last.copyFrom(tmp1);
object2.last.copyFrom(tmp2);
tmp1.put();
tmp2.put();
return separatedX || separatedY;

/*
Expand Down
26 changes: 21 additions & 5 deletions tests/unit/src/flixel/FlxObjectTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class FlxObjectTest extends FlxTest
}

@Test
function testSeprateX():Void
function testSeparateX():Void
{
final object1 = new FlxObject(5, 0, 10, 10);
object1.last.x = 10;
Expand All @@ -100,7 +100,7 @@ class FlxObjectTest extends FlxTest
}

@Test
function testSeprateY():Void
function testSeparateY():Void
{
final object1 = new FlxObject(0, 5, 10, 10);
object1.last.y = 10;
Expand All @@ -119,7 +119,23 @@ class FlxObjectTest extends FlxTest
}

@Test
function testSeprateXFromOpposite():Void
function testSeparateOnBothAxisNewlyOverlapping():Void
{
final object1 = new FlxObject(11, -1, 10, 10);
final object2 = new FlxObject(0, 10, 10, 10);
object2.immovable = true;

object1.setPosition(9, 2);

Assert.isTrue(FlxObject.separate(object1, object2));
// X-axis resolves first and no collision
Assert.areEqual(9, object1.x);
// Y-axis resolves second and is stopped by collision
Assert.areEqual(0, object1.y);
}

@Test
function testSeparateXFromOpposite():Void
{
/*
* NOTE: An odd y value on either may result in a rounding error where the second
Expand All @@ -142,7 +158,7 @@ class FlxObjectTest extends FlxTest
}

@Test
function testSeprateYFromOpposite():Void
function testSeparateYFromOpposite():Void
{
/*
* NOTE: An odd y value on either may result in a rounding error where the second
Expand Down Expand Up @@ -371,7 +387,7 @@ class FlxObjectTest extends FlxTest
}

@Test
function testgetRotatedBounds()
function testGetRotatedBounds()
{
var expected = FlxRect.get();
var rect = FlxRect.get();
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/src/flixel/math/FlxRectTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FlxRectTest extends FlxTest
}

@Test
function testgetRotatedBounds()
function testGetRotatedBounds()
{
var pivot = FlxPoint.get();
var expected = FlxRect.get();
Expand Down Expand Up @@ -64,7 +64,7 @@ class FlxRectTest extends FlxTest
}

@Test
function testgetRotatedBoundsSelf()
function testGetRotatedBoundsSelf()
{
var pivot = FlxPoint.get();
var expected = FlxRect.get();
Expand Down