-
Notifications
You must be signed in to change notification settings - Fork 27
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
Collision data shape ordering (second attempt) #45
Open
MondayHopscotch
wants to merge
5
commits into
AustinEast:master
Choose a base branch
from
MondayHopscotch:listener-shape-issue
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
99beaab
simplified example of shape order issue
MondayHopscotch bdf99d8
more tinkering. physics oddities isolated to circles
MondayHopscotch 04fec0d
sort out circle collision flip logic
MondayHopscotch 1927b63
cleanup formatting and test states
MondayHopscotch 3d4789a
Merge branch 'master' of github.com:AustinEast/echo into listener-sha…
MondayHopscotch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't articulate exactly what this test is doing, so a short descriptor might help future folks if they need to come in here for any reason.