diff --git a/CHANGELOG.md b/CHANGELOG.md index df83ff855..e1075fa3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ -# 3.9.5 +# 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) +- Fix tile rotation bug. [#531](https://github.com/RafaelBarbosatec/bonfire/issues/531) [#530](https://github.com/RafaelBarbosatec/bonfire/issues/530) +# 3.9.5 - Fix Joystick bug when viewport is fixed resolution. [#526](https://github.com/RafaelBarbosatec/bonfire/issues/526) +- Add guard in `FlyingAttackGameObject` to prevent calling `onDestroy` after component has been destroyed. # 3.9.4 - Fix bug in `FollowerWidget`. diff --git a/example/assets/images/tiled/tiled_example.tmj b/example/assets/images/tiled/tiled_example.tmj index 2cb82c17e..337418418 100644 --- a/example/assets/images/tiled/tiled_example.tmj +++ b/example/assets/images/tiled/tiled_example.tmj @@ -56,55 +56,55 @@ "name":"objects", "objects":[ { - "class":"", "height":16, "id":2, "name":"spikes", "rotation":0, + "type":"", "visible":true, "width":16, "x":32.5, "y":156.5 }, { - "class":"", "height":16, "id":6, "name":"spikes", "rotation":0, + "type":"", "visible":true, "width":16, "x":44.5, "y":64 }, { - "class":"", "height":16, "id":7, "name":"spikes", "rotation":0, + "type":"", "visible":true, "width":16, "x":114.5, "y":109.5 }, { - "class":"", "height":16, "id":8, "name":"torch", "rotation":0, + "type":"", "visible":true, "width":16, "x":48.1666666666667, "y":15.8333333333333 }, { - "class":"", "height":16, "id":9, "name":"torch", "rotation":0, + "type":"", "visible":true, "width":16, "x":95.3333333333333, @@ -120,7 +120,7 @@ "nextobjectid":10, "orientation":"orthogonal", "renderorder":"right-down", - "tiledversion":"1.9.0", + "tiledversion":"1.10.2", "tileheight":16, "tilesets":[ { @@ -129,6 +129,6 @@ }], "tilewidth":16, "type":"map", - "version":"1.9", + "version":"1.10", "width":10 } \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index 62a52b5ce..e14237cb9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -47,7 +47,7 @@ packages: path: ".." relative: true source: path - version: "3.9.0" + version: "3.9.5" boolean_selector: dependency: transitive description: @@ -560,5 +560,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.3.0-0 <4.0.0" + dart: ">=3.4.0 <4.0.0" flutter: ">=3.19.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1880e64f5..690121767 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: none version: 1.0.0+1 environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=3.4.0 <4.0.0" dependencies: flutter: diff --git a/lib/map/base/tile.dart b/lib/map/base/tile.dart index 5cc6bf7d9..66575cb95 100644 --- a/lib/map/base/tile.dart +++ b/lib/map/base/tile.dart @@ -204,6 +204,15 @@ 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(); } diff --git a/lib/map/base/tile_layer_component.dart b/lib/map/base/tile_layer_component.dart index 9aed54e01..d5cb977d7 100644 --- a/lib/map/base/tile_layer_component.dart +++ b/lib/map/base/tile_layer_component.dart @@ -59,6 +59,7 @@ class TileLayerComponent extends PositionComponent with HasPaint { } void initLayer(Vector2 gameSize, Vector2 screenSize) { + if (gameSize.isZero()) return; _createQuadTree(gameSize, screenSize); } diff --git a/lib/map/tiled/builder/tiled_world_builder.dart b/lib/map/tiled/builder/tiled_world_builder.dart index 73f67581f..c805563cf 100644 --- a/lib/map/tiled/builder/tiled_world_builder.dart +++ b/lib/map/tiled/builder/tiled_world_builder.dart @@ -91,7 +91,7 @@ class TiledWorldBuilder { return Future.value( WorldBuildData( map: WorldMap( - _layers, + _layers.where((e) => e.tiles.isNotEmpty).toList(), tileSizeToUpdate: sizeToUpdate, ), components: _components, @@ -341,7 +341,6 @@ class TiledWorldBuilder { tileSetContain, (index - tilesetFirsTgId), ); - return TiledItemTileSet( type: object.type, collisions: object.collisions, diff --git a/lib/mixins/jumper.dart b/lib/mixins/jumper.dart index 4610d0a30..c2c903b39 100644 --- a/lib/mixins/jumper.dart +++ b/lib/mixins/jumper.dart @@ -1,4 +1,5 @@ import 'package:bonfire/bonfire.dart'; +import 'package:bonfire/util/collision_game_component.dart'; enum JumpingStateEnum { up, @@ -20,6 +21,9 @@ mixin Jumper on Movement, BlockMovementCollision { int _maxJump = 1; int _currentJumps = 0; JumpingStateEnum? _lastDirectionJump = JumpingStateEnum.idle; + int _tileCollisionCount = 0; + + static const _tileCollisionCountKey = 'tileCollisionCount'; void onJump(JumpingStateEnum state) { jumpingState = state; @@ -42,22 +46,44 @@ mixin Jumper on Movement, BlockMovementCollision { PositionComponent other, CollisionData collisionData, ) { - super.onBlockedMovement(other, collisionData); if (isJumping && lastDirectionVertical.isDownSide && collisionData.direction.isDownSide) { _currentJumps = 0; isJumping = false; } + super.onBlockedMovement(other, collisionData); + } + + @override + void onCollisionStart( + Set intersectionPoints, PositionComponent other) { + if (other is CollisionMapComponent || other is TileWithCollision) { + ++_tileCollisionCount; + resetInterval(_tileCollisionCountKey); + } + super.onCollisionStart(intersectionPoints, other); + } + + @override + void onCollisionEnd(PositionComponent other) { + if (other is CollisionMapComponent || other is TileWithCollision) { + if (--_tileCollisionCount == 0) resetInterval(_tileCollisionCountKey); + } + super.onCollisionEnd(other); } @override void update(double dt) { - super.update(dt); - if (!isJumping && displacement.y.abs() > 0.2) { + if (checkInterval(_tileCollisionCountKey, 100, dt, + firstCheckIsTrue: false) && + !isJumping && + _tileCollisionCount == 0 && + displacement.y.abs() > 0.2) { isJumping = true; } _notifyJump(); + super.update(dt); } void _notifyJump() { diff --git a/lib/objects/flying_attack_game_object.dart b/lib/objects/flying_attack_game_object.dart index a276b5653..3f2ce6cee 100644 --- a/lib/objects/flying_attack_game_object.dart +++ b/lib/objects/flying_attack_game_object.dart @@ -132,13 +132,14 @@ class FlyingAttackGameObject extends AnimatedGameObject } void _destroyObject(GameComponent component) { - if (isRemoving) return; + if (isRemoving || isRemoved) return; removeFromParent(); if (animationDestroy != null) { - if (direction != null) { - _destroyByDirection(direction!, dtUpdate, component); + final currentDirection = direction; + if (currentDirection != null) { + _destroyByDirection(currentDirection); } else { - _destroyByAngle(component); + _destroyByAngle(); } } removeAll(children); @@ -149,11 +150,7 @@ class FlyingAttackGameObject extends AnimatedGameObject return gameRef.map.toRect().contains(center.toOffset()); } - void _destroyByDirection( - Direction direction, - double dt, - GameComponent component, - ) { + void _destroyByDirection(Direction direction) { Vector2 positionDestroy; double biggerSide = max(width, height); @@ -236,12 +233,11 @@ class FlyingAttackGameObject extends AnimatedGameObject innerSize.x, innerSize.y, ), - component, ); } } - void _destroyByAngle(GameComponent component) { + void _destroyByAngle() { double nextX = (width / 2) * _cosAngle; double nextY = (height / 2) * _senAngle; @@ -277,12 +273,11 @@ class FlyingAttackGameObject extends AnimatedGameObject innerSize.x, innerSize.y, ), - component, ); } } - void _applyDestroyDamage(Rect rectPosition, GameComponent component) { + void _applyDestroyDamage(Rect rectPosition) { gameRef.add( DamageHitbox( id: id, diff --git a/pubspec.yaml b/pubspec.yaml index 90224cb90..efd0804e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bonfire description: (RPG maker) Create RPG-style or similar games more simply with Flame. -version: 3.9.5 +version: 3.9.6 homepage: https://bonfire-engine.github.io repository: https://github.com/RafaelBarbosatec/bonfire issue_tracker: https://github.com/RafaelBarbosatec/bonfire/issues