Skip to content

Commit

Permalink
Merge pull request #538 from RafaelBarbosatec/develop
Browse files Browse the repository at this point in the history
Version 3.9.7
  • Loading branch information
RafaelBarbosatec authored Jul 1, 2024
2 parents 73871d8 + 0287fa3 commit 36e8ad6
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.9.7
- Update `tiledjsonreader`
- Bugfix/tile rotation collision. [#535](https://github.com/RafaelBarbosatec/bonfire/pull/535)
- Adds 'currentIndex' and 'fastAnimationcurrentIndex' in `SimpleDirectionAnimation`.

# 3.9.6
- Fix jump animation showing instead of run/idle animation on slanting floors
- Fix above layer bug [#532](https://github.com/RafaelBarbosatec/bonfire/issues/532)
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.9.5"
version: "3.9.6"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -435,10 +435,10 @@ packages:
dependency: transitive
description:
name: tiledjsonreader
sha256: "9390145be049ec4d73ef43672b337ce40fa6e4a72a0672ad680e4971edba2899"
sha256: faadb2eb207cd73d12dd4b24e7784203a975bc2ba6d115291bad1513333f8ec3
url: "https://pub.dev"
source: hosted
version: "1.3.4"
version: "1.3.5"
typed_data:
dependency: transitive
description:
Expand Down
9 changes: 6 additions & 3 deletions lib/collision/block_movement_collision.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ mixin BlockMovementCollision on Movement {
CollisionData collisionData,
) {
_lastCollisionData = collisionData;

if (_bodyType.isDynamic) {
Vector2 correction;
double depth = 0;
if (collisionData.depth > 0) {
depth = collisionData.depth + 0.08;
double depth = collisionData.depth;
if (depth != 0) {
depth = collisionData.depth.abs() + 0.08;
}

correction = (-collisionData.normal * depth);
if ((other is BlockMovementCollision) && other._bodyType.isDynamic) {
correction = (-collisionData.normal * depth / 2);
}

correctPositionFromCollision(position + correction);
}

velocity -= getVelocityReflection(other, collisionData);
}

Expand Down
40 changes: 37 additions & 3 deletions lib/collision/collision_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,45 @@ class CollisionUtil {
}
}

final _cachedGlobalVertices = ValueCache<List<Vector2>>();

extension PolygonComponentExt on PolygonComponent {
List<Vector2> get absoluteVertices {
Vector2 p = absolutePosition;
return vertices.map((element) {
final Vector2 p = absolutePosition;
final adjustedVerticies =
absoluteAngle == 0 ? vertices : rotatedVerticesBonfire(absoluteAngle);

final result = adjustedVerticies.map((element) {
return element.translated(p.x, p.y);
}).toList();
}).toList(growable: false);
return result;
}

/// gives back the shape vectors multiplied by the size and scale
List<Vector2> rotatedVerticesBonfire(double parentAngle) {
final angle = parentAngle;
if (!_cachedGlobalVertices.isCacheValid<dynamic>(<dynamic>[
size,
angle,
])) {
final globalVertices = List.generate(
vertices.length,
(_) => Vector2.zero(),
growable: false,
);

for (var i = 0; i < vertices.length; i++) {
final vertex = vertices[i];
globalVertices[i]
..setFrom(vertex)
..rotate(angle);
}

_cachedGlobalVertices.updateCache<dynamic>(
globalVertices,
<dynamic>[size.clone(), angle],
);
}
return _cachedGlobalVertices.value!;
}
}
44 changes: 35 additions & 9 deletions lib/map/base/tile.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math' as math;

import 'package:bonfire/map/base/tile_component.dart';
import 'package:bonfire/map/base/tile_with_collision.dart';
import 'package:bonfire/map/util/map_assets_manager.dart';
Expand Down Expand Up @@ -204,20 +206,44 @@ class Tile {
tile.id = id;
tile.angle = angle;
tile.opacity = opacity;

if (angle != 0) {
tile.anchor = Anchor.center;
tile.position = tile.position +
Vector2(
width / 2,
height / 2,
);
}
if (isFlipHorizontal) {
tile.flipHorizontallyAroundCenter();
}
if (isFlipVertical) {
tile.flipVerticallyAroundCenter();
}

// Needs to be debugged with different anchors. Works for default.
// tile.anchor = Anchor.topCenter;
_translateTileAngle(tile); // Force tile to be in it's box after rotation
}

void _translateTileAngle(TileComponent tile) {
// Depending or where the rotated object is - move it to positive coordinates:

final angle = tile.angle;
final sin = math.sin(angle);
final cos = math.cos(angle);
if (tile.anchor.x != 0.5) {
final delta =
(1 - 2 * tile.anchor.x) * tile.width * tile.transform.scale.x;
if (cos < 0.9) {
tile.transform.x -= delta * cos;
}
if (sin < 0.9) {
tile.transform.y -= delta * sin;
}
}

if (tile.anchor.y != 0.5) {
final delta =
(1 - 2 * tile.anchor.y) * tile.height * tile.transform.scale.y;
if (sin > 0.9) {
tile.transform.x += delta * sin;
}
if (cos < 0.9) {
tile.transform.y -= delta * cos;
}
}
}
}
4 changes: 4 additions & 0 deletions lib/map/tiled/builder/tiled_world_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class TiledWorldBuilder {
for (var tile in tileLayer.data ?? const <int>[]) {
if (tile != 0) {
var data = _getDataTile(tile);

if (data != null) {
bool tileIsAbove = ((data.type?.contains(ABOVE_TYPE) ?? false) ||
(data.tileClass?.contains(ABOVE_TYPE) ?? false) ||
Expand Down Expand Up @@ -341,6 +342,7 @@ class TiledWorldBuilder {
tileSetContain,
(index - tilesetFirsTgId),
);

return TiledItemTileSet(
type: object.type,
collisions: object.collisions,
Expand Down Expand Up @@ -563,6 +565,8 @@ class TiledWorldBuilder {
size: Vector2(width, height),
position: isObjectCollision ? null : Vector2(x, y),
isSolid: true,
// Angle here is not used because
// collision object is already rotated
);

if (ellipse == true) {
Expand Down
3 changes: 3 additions & 0 deletions lib/util/direction_animations/simple_direction_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class SimpleDirectionAnimation {
late RenderTransformWrapper _renderWrapper;
late RenderTransformWrapper _fastAnimationRenderWrapper;

int get currentIndex => _current.currentIndex;
int get fastAnimationcurrentIndex => _fastAnimation?.currentIndex ?? 0;

SimpleDirectionAnimation({
required FutureOr<SpriteAnimation> idleRight,
required FutureOr<SpriteAnimation> runRight,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ packages:
dependency: "direct main"
description:
name: tiledjsonreader
sha256: "9390145be049ec4d73ef43672b337ce40fa6e4a72a0672ad680e4971edba2899"
sha256: faadb2eb207cd73d12dd4b24e7784203a975bc2ba6d115291bad1513333f8ec3
url: "https://pub.dev"
source: hosted
version: "1.3.4"
version: "1.3.5"
typed_data:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions 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.9.6
version: 3.9.7
homepage: https://bonfire-engine.github.io
repository: https://github.com/RafaelBarbosatec/bonfire
issue_tracker: https://github.com/RafaelBarbosatec/bonfire/issues
Expand All @@ -15,7 +15,7 @@ dependencies:
sdk: flutter

flame: 1.17.0
tiledjsonreader: ^1.3.4
tiledjsonreader: ^1.3.5
http: ^1.1.0
a_star_algorithm: ^0.3.1

Expand Down

0 comments on commit 36e8ad6

Please sign in to comment.