Skip to content

Commit

Permalink
feat: adding IgnoresCollisionTags status (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtome authored Sep 1, 2024
1 parent 4a53cea commit de882d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CollisionDetectionBehavior extends PhysicalBehavior
/// Used to test intersections.
final _hitboxProxy = _HitboxProxyComponent();

final _tmpIgnoreTags = <String>{};

@override
void onMount() {
super.onMount();
Expand Down Expand Up @@ -331,8 +333,20 @@ class CollisionDetectionBehavior extends PhysicalBehavior
.where((s) => s is IgnoredByWorld || s is IgnoredByCollisions)
.isEmpty,
);

_tmpIgnoreTags.clear();
parent.statuses.whereType<IgnoresCollisionTags>().forEach((status) {
_tmpIgnoreTags.addAll(status.ignoreTags);
});
for (final other in physicals) {
if (!other.isRemoving && intersectsOther(_hitboxProxy, other)) {
var skip = false;
for (final tag in other.tags) {
if (_tmpIgnoreTags.contains(tag)) {
skip = true;
}
}
skip |= other.isRemoving;
if (!skip && intersectsOther(_hitboxProxy, other)) {
_potentialHits.add(other);
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/leap/lib/src/entities/status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ mixin IgnoresSolidCollisions on EntityStatus {}
/// A status mixin which indicates the parent entity should not
/// collide with non-solids.
mixin IgnoresNonSolidCollisions on EntityStatus {}

/// A status mixin which indicates the parent entity should not
/// collide with any other entities which have a tag in [ignoreTags]
mixin IgnoresCollisionTags on EntityStatus {
final ignoreTags = <String>{};
}

0 comments on commit de882d6

Please sign in to comment.