From 1927b631816208745144567df72d943fb69e30e3 Mon Sep 17 00:00:00 2001 From: Logan Date: Sat, 2 Mar 2024 13:27:28 -0700 Subject: [PATCH] cleanup formatting and test states --- echo/util/SAT.hx | 16 ++---- sample/Main.hx | 5 +- sample/state/ListenerState.hx | 82 --------------------------- sample/state/OverlappingSpawnState.hx | 72 ----------------------- sample/state/PolygonState.hx | 2 +- sample/state/StaticState.hx | 2 - 6 files changed, 10 insertions(+), 169 deletions(-) delete mode 100644 sample/state/ListenerState.hx delete mode 100644 sample/state/OverlappingSpawnState.hx diff --git a/echo/util/SAT.hx b/echo/util/SAT.hx index 0cf586a..473e88c 100644 --- a/echo/util/SAT.hx +++ b/echo/util/SAT.hx @@ -334,11 +334,8 @@ class SAT { // collisions used the transformed rect, set the collision data's shape back // to the original rect - if (!flip) { - col.sa = r; - } else { - col.sb = r; - } + if (!flip) col.sa = r; + else col.sb = r; return col; } @@ -415,11 +412,8 @@ class SAT { // collisions were done with a polygon derrived from the provided rect // so we need to set our collision data shape back to the original rectangle - if (flip) { - col.sb = r; - } else { - col.sa = r; - } + if (flip) col.sb = r; + else col.sa = r; return col; } @@ -506,7 +500,7 @@ class SAT { test1 = min1 - max2; test2 = min2 - max1; - // Preform another test // TODO: What is this test doing, exactly? + // Perform another test if (test1 > 0 || test2 > 0) { col.put(); return null; diff --git a/sample/Main.hx b/sample/Main.hx index 55fd7e6..85c55e8 100644 --- a/sample/Main.hx +++ b/sample/Main.hx @@ -1,5 +1,7 @@ package; +import state.test.ListenerState; +import state.test.OverlappingSpawnState; import hxd.Key; import echo.Echo; import echo.World; @@ -46,9 +48,10 @@ class Main extends BaseApp { // Set up our Sample States sample_states = [ - OverlappingSpawnState, ListenerState, PolygonState, StackingState, MultiShapeState, ShapesState, GroupsState, StaticState, LinecastState, Linecast2State, TileMapState, TileMapState2, + PolygonState, StackingState, MultiShapeState, ShapesState, GroupsState, StaticState, LinecastState, Linecast2State, TileMapState, TileMapState2, BezierState, VerletState ]; + index = 0; // Create a State Manager and pass it the World and the first Sample fsm = new FSM(world, Type.createInstance(sample_states[index], [])); diff --git a/sample/state/ListenerState.hx b/sample/state/ListenerState.hx deleted file mode 100644 index 55b62e7..0000000 --- a/sample/state/ListenerState.hx +++ /dev/null @@ -1,82 +0,0 @@ -package state; - -import echo.data.Options.ListenerOptions; -import echo.Material; -import echo.Body; -import echo.World; -import util.Random; - -class ListenerState extends BaseState { - - override public function enter(world:World) { - Main.instance.state_text.text = "Sample: Collision Listener"; - - // Create a material for all the shapes to share - var material:Material = {elasticity: 0.7}; - - var bodyA = new Body({ - x: Random.range(60, world.width - 60), - y: Random.range(0, world.height / 2), - // rotation: Random.range(0, 360), - material: material, - shapes: [ - { - type: POLYGON, - radius: Random.range(16, 32), - width: Random.range(16, 48), - height: Random.range(16, 48), - sides: Random.range_int(3, 8), - offset_y: -10, - }, - { - type: POLYGON, - radius: Random.range(16, 32), - width: Random.range(16, 48), - height: Random.range(16, 48), - sides: Random.range_int(3, 8), - offset_y: 10, - } - ] - }); - world.add(bodyA); - - // Add a Physics body at the bottom of the screen for the other Physics Bodies to stack on top of - // This body has a mass of 0, so it acts as an immovable object - var bodyB = new Body({ - mass: STATIC, - x: world.width / 5, - y: world.height - 40, - material: material, - rotation: 5, - shape: { - type: RECT, - width: world.width, - height: 20 - } - }); - world.add(bodyB); - - var dbgOpts:ListenerOptions = { - enter: (a, b, data) -> { - trace('bodyA == listener `a`: ${bodyA == a}'); - // the second shape is our 'bottom' shape that is making the collision - trace('bodyA owns data `shape a`: ${bodyA.shapes.contains(data[0].sa)}'); - trace('bodyB == listener `b`: ${bodyB == b}'); - trace('bodyB owns `shape b`: ${bodyB.shapes.contains(data[0].sb)}'); - }, - }; - - // Create a listener for collisions between the Physics Bodies - world.listen(bodyA, bodyB, dbgOpts); - } - - override function step(world:World, dt:Float) { - // Reset any off-screen Bodies - world.for_each((member) -> { - if (offscreen(member, world)) { - member.velocity.set(0, 0); - member.set_position(Random.range(0, world.width), 0); - } - }); - } -} \ No newline at end of file diff --git a/sample/state/OverlappingSpawnState.hx b/sample/state/OverlappingSpawnState.hx deleted file mode 100644 index 7ca3ebf..0000000 --- a/sample/state/OverlappingSpawnState.hx +++ /dev/null @@ -1,72 +0,0 @@ -package state; - -import echo.data.Options.ListenerOptions; -import echo.Material; -import echo.Body; -import echo.World; -import util.Random; - -class OverlappingSpawnState extends BaseState { - - override public function enter(world:World) { - Main.instance.state_text.text = "Sample: Collision Listener"; - - // Create a material for all the shapes to share - var material:Material = {elasticity: 0.7}; - - var body = new Body({ - x: 200, - y: 50, - rotation: 0, - material: material, - shape: { - type: CIRCLE, - radius: 16, - offset_y: 0, - } - }); - world.add(body); - - // body = new Body({ - // x: 200, - // y: 53, - // rotation: 0, - // material: material, - // shape: { - // type: CIRCLE, - // radius: 12, - // offset_y: 0, - // } - // }); - // world.add(body); - - // Add a Physics body at the bottom of the screen for the other Physics Bodies to stack on top of - // This body has a mass of 0, so it acts as an immovable object - var floor = new Body({ - mass: STATIC, - x: world.width / 5, - y: world.height - 40, - material: material, - // rotation: 5, - shape: { - type: RECT, - width: world.width, - height: 20 - } - }); - world.add(floor); - - // Create a listener for collisions between the Physics Bodies - world.listen(); - } - - override function step(world:World, dt:Float) { - // Reset any off-screen Bodies - world.for_each((member) -> { - if (offscreen(member, world)) { - member.velocity.set(0, 0); - member.set_position(Random.range(0, world.width), 0); - } - }); - } -} \ No newline at end of file diff --git a/sample/state/PolygonState.hx b/sample/state/PolygonState.hx index 297ac86..96827bb 100644 --- a/sample/state/PolygonState.hx +++ b/sample/state/PolygonState.hx @@ -21,7 +21,7 @@ class PolygonState extends BaseState { var b = new Body({ x: Random.range(60, world.width - 60), y: Random.range(0, world.height / 2), - rotation: 0, + rotation: Random.range(0, 360), material: material, shape: { type: POLYGON, diff --git a/sample/state/StaticState.hx b/sample/state/StaticState.hx index 5301c68..226697f 100644 --- a/sample/state/StaticState.hx +++ b/sample/state/StaticState.hx @@ -33,8 +33,6 @@ class StaticState extends BaseState { shape: { type: CIRCLE, radius: Random.range(2, 4), - width: Random.range(2, 4), - height: Random.range(2, 4) } }); world.add(b);