Skip to content

Commit

Permalink
Merge pull request RafaelBarbosatec#561 from RafaelBarbosatec/develop
Browse files Browse the repository at this point in the history
Version 3.10.5
  • Loading branch information
RafaelBarbosatec authored Oct 19, 2024
2 parents 34a8ad1 + d971178 commit f73dc47
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.10.5
- Adds param `withDiagonal` in `setupPathFinding` (PathFinding mixin)
- Fix PathFinding bug. Now not consider your own collision as a barrier.

# 3.10.4
- Update `tiledjsonreader` to support web platform
- `DirectionAnimation` improvements
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.12.0"
mime:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions lib/base/game_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,6 @@ abstract class GameComponent extends PositionComponent
void onGameMounted() {
_gameMounted = true;
}

List<ShapeHitbox> get getHitboxes => children.query<ShapeHitbox>();
}
27 changes: 17 additions & 10 deletions lib/mixins/path_finding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ mixin PathFinding on Movement {
bool _showBarriers = false;
bool _gridSizeIsCollisionSize = false;
bool _useOnlyVisibleBarriers = true;
bool _withDiagonal = true;
double _factorInflateFindArea = 2;
VoidCallback? _onFinish;

final List<Point<int>> _barriers = [];
final List _ignoreCollisions = [];
final List<ShapeHitbox> _ignoreCollisions = [];

LinePathComponent? _linePathComponent;
Color _pathLineColor = const Color(0xFF40C4FF).withOpacity(0.5);
Expand All @@ -47,8 +48,10 @@ mixin PathFinding on Movement {

/// If `false` the algorithm use map tile size with base of the grid. if true this use collision size of the component.
bool gridSizeIsCollisionSize = false,
bool withDiagonal = true,
double factorInflateFindArea = 2,
}) {
_withDiagonal = withDiagonal;
_linePathEnabled = linePathEnabled ?? _linePathEnabled;
_useOnlyVisibleBarriers = useOnlyVisibleBarriers;
_factorInflateFindArea = factorInflateFindArea;
Expand All @@ -64,7 +67,7 @@ mixin PathFinding on Movement {

Future<List<Vector2>> moveToPositionWithPathFinding(
Vector2 position, {
List? ignoreCollisions,
List<GameComponent>? ignoreCollisions,
VoidCallback? onFinish,
}) async {
if (!hasGameRef) {
Expand Down Expand Up @@ -104,13 +107,14 @@ mixin PathFinding on Movement {

List<Vector2> getPathToPosition(
Vector2 position, {
List? ignoreCollisions,
List<GameComponent>? ignoreCollisions,
}) {
_ignoreCollisions.clear();
_ignoreCollisions.add(this);
if (ignoreCollisions != null) {
_ignoreCollisions.addAll(ignoreCollisions);
}
_ignoreCollisions.addAll(getHitboxes);

ignoreCollisions?.forEach(
(comp) => _ignoreCollisions.addAll(comp.getHitboxes),
);
return _calculatePath(position);
}

Expand Down Expand Up @@ -197,9 +201,11 @@ mixin PathFinding on Movement {
area = Rect.fromLTRB(left, top, right, bottom).inflate(inflate);

for (final e in gameRef.collisions(onlyVisible: _useOnlyVisibleBarriers)) {
var rect = e.toAbsoluteRect();
if (!_ignoreCollisions.contains(e) && area.overlaps(rect)) {
_addCollisionOffsetsPositionByTile(rect);
if (!_ignoreCollisions.contains(e)) {
var rect = e.toAbsoluteRect();
if (area.overlaps(rect)) {
_addCollisionOffsetsPositionByTile(rect);
}
}
}

Expand All @@ -217,6 +223,7 @@ mixin PathFinding on Movement {
start: playerPosition,
end: targetPosition,
barriers: _barriers,
withDiagonal: _withDiagonal,
).findThePath();

if (result.isNotEmpty || _isNeighbor(playerPosition, targetPosition)) {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
web:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bonfire
description: (RPG maker) Create RPG-style or similar games more simply with Flame.
version: 3.10.4
version: 3.10.5
homepage: https://bonfire-engine.github.io
repository: https://github.com/RafaelBarbosatec/bonfire
issue_tracker: https://github.com/RafaelBarbosatec/bonfire/issues
Expand Down

0 comments on commit f73dc47

Please sign in to comment.