Skip to content
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

Fix for #520 #521

Merged
merged 4 commits into from
Jun 2, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- push improvements.
- `Movement` mixin improvements.
- Other otimizations
- Fix intermittent crash after `simpleAttackRanged` is called

# 3.9.2
- MiniMap improviments. Fix issue [#517](https://github.com/RafaelBarbosatec/bonfire/issues/517)
Expand Down
21 changes: 16 additions & 5 deletions lib/collision/block_movement_collision.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ mixin BlockMovementCollision on Movement {

@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
super.onCollision(intersectionPoints, other);
if (other is Sensor || !_blockMovementCollisionEnabled) return;
if (other is Sensor || !_blockMovementCollisionEnabled) {
super.onCollision(intersectionPoints, other);
return;
}
bool stopOtherMovement = true;
bool stopMovement = other is GameComponent
? onBlockMovement(intersectionPoints, other)
Expand All @@ -89,6 +91,7 @@ mixin BlockMovementCollision on Movement {
}

if (!stopMovement || !stopOtherMovement) {
super.onCollision(intersectionPoints, other);
return;
}

Expand All @@ -98,18 +101,24 @@ mixin BlockMovementCollision on Movement {
_collisionsResolution[other]!,
);
_collisionsResolution.remove(other);
super.onCollision(intersectionPoints, other);
return;
}

ShapeHitbox shape1 = _getCollisionShapeHitbox(
ShapeHitbox? shape1 = _getCollisionShapeHitbox(
shapeHitboxes,
intersectionPoints,
);
ShapeHitbox shape2 = _getCollisionShapeHitbox(
ShapeHitbox? shape2 = _getCollisionShapeHitbox(
other.children.query<ShapeHitbox>(),
intersectionPoints,
);

if (shape1 == null || shape2 == null) {
super.onCollision(intersectionPoints, other);
return;
}

({Vector2 normal, double depth})? colisionResult;

if (_isPolygon(shape1)) {
Expand Down Expand Up @@ -143,6 +152,7 @@ mixin BlockMovementCollision on Movement {
other.setCollisionResolution(this, data.inverted());
}
}
super.onCollision(intersectionPoints, other);
}

bool _isPolygon(ShapeHitbox shape) {
Expand Down Expand Up @@ -273,10 +283,11 @@ mixin BlockMovementCollision on Movement {
return (normal: normal, depth: depth);
}

ShapeHitbox _getCollisionShapeHitbox(
ShapeHitbox? _getCollisionShapeHitbox(
List<ShapeHitbox> shapeHitboxes,
Set<Vector2> intersectionPoints,
) {
if (shapeHitboxes.isEmpty || intersectionPoints.isEmpty) return null;
if (shapeHitboxes.length == 1) {
return shapeHitboxes.first;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/mixins/direction_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ mixin DirectionAnimation on Movement {
await animation?.onLoad(gameRef);
return super.onLoad();
}

@override
void onMount(){
void onMount() {
super.onMount();
idle();
}
Expand Down
Loading