-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
PropagatingCollisionBehavior
should also work for non entity c…
…omponents (#20) * bug: `PropagatingCollisionBehavior` should also work for non entity components * bug: `PropagatingCollisionBehavior` should also work for non entity components
- Loading branch information
1 parent
64276fe
commit ca5fc6c
Showing
8 changed files
with
76 additions
and
108 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'movement_behavior.dart'; | ||
export 'rotation_behavior.dart'; | ||
export 'screen_collision_behavior.dart'; |
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,21 @@ | ||
import 'package:flame/collisions.dart'; | ||
import 'package:flame_behaviors/flame_behaviors.dart'; | ||
|
||
/// Simplified "screen wrapping" behavior, while not perfect it does showcase | ||
/// the possibility of acting on collision with non-entities. | ||
class ScreenCollisionBehavior extends CollisionBehavior<ScreenHitbox, Entity> { | ||
@override | ||
void onCollisionEnd(ScreenHitbox other) { | ||
if (parent.position.x < other.position.x) { | ||
parent.position.x = other.position.x + other.scaledSize.x; | ||
} else if (parent.position.x > other.position.x + other.scaledSize.x) { | ||
parent.position.x = other.position.x; | ||
} | ||
|
||
if (parent.position.y < other.position.y) { | ||
parent.position.y = other.position.y + other.scaledSize.y; | ||
} else if (parent.position.y > other.position.y + other.scaledSize.y) { | ||
parent.position.y = other.position.y; | ||
} | ||
} | ||
} |
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