diff --git a/packages/trashy_road/lib/src/game/entities/map_border/map_border.dart b/packages/trashy_road/lib/src/game/entities/map_border/map_border.dart index bc69062a..0a3dec91 100644 --- a/packages/trashy_road/lib/src/game/entities/map_border/map_border.dart +++ b/packages/trashy_road/lib/src/game/entities/map_border/map_border.dart @@ -1,23 +1,29 @@ import 'dart:ui'; +import 'package:flame/collisions.dart'; import 'package:flame/components.dart'; +import 'package:flame_behaviors/flame_behaviors.dart'; import 'package:tiled/tiled.dart'; import 'package:trashy_road/game_settings.dart'; -import 'package:trashy_road/src/game/game.dart'; - -class MapBorder extends Obstacle { +class MapBorder extends PositionedEntity { MapBorder._({required super.position, required super.size}) : super( - blockOnlyBottomTile: false, anchor: Anchor.topLeft, - children: [ - RectangleComponent(size: Vector2.copy(size)..toGameSize()) - ..setColor( - const Color.fromARGB(64, 0, 0, 0), - ), - ], - ); + ) { + final gameSize = Vector2.copy(size)..toGameSize(); + addAll([ + PropagatingCollisionBehavior( + RectangleHitbox( + size: gameSize, + ), + ), + RectangleComponent(size: gameSize) + ..setColor( + const Color.fromARGB(64, 0, 0, 0), + ), + ]); + } /// Derives a [MapBorder] from a [TiledObject]. factory MapBorder.fromTiledObject(TiledObject tiledObject) { diff --git a/packages/trashy_road/lib/src/game/entities/obstacle/obstacle.dart b/packages/trashy_road/lib/src/game/entities/obstacle/obstacle.dart index bdb02bed..cf9e0dca 100644 --- a/packages/trashy_road/lib/src/game/entities/obstacle/obstacle.dart +++ b/packages/trashy_road/lib/src/game/entities/obstacle/obstacle.dart @@ -7,26 +7,19 @@ class Obstacle extends PositionedEntity { Obstacle({ required Vector2 super.size, required Vector2 super.position, - Anchor anchor = Anchor.bottomLeft, super.children, Iterable? behaviors, - bool blockOnlyBottomTile = true, }) : super( - anchor: anchor, + anchor: Anchor.bottomLeft, priority: position.y.floor(), behaviors: [ if (behaviors != null) ...behaviors, PropagatingCollisionBehavior( RectangleHitbox( anchor: Anchor.topCenter, - size: (blockOnlyBottomTile ? Vector2.all(0.8) : size) - ..toGameSize(), - position: Vector2( - size.x / 2, - blockOnlyBottomTile - ? size.y - GameSettings.gridDimensions.y - : 0, - ), + size: Vector2.all(0.8)..toGameSize(), + position: + Vector2(size.x / 2, size.y - GameSettings.gridDimensions.y), ), ), ], diff --git a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart index 7d9749af..ce60d5b2 100644 --- a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart +++ b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart @@ -1,6 +1,5 @@ // FIXME(alestiago): Avoid ignoring deprecated_member_use as soon as: // https://github.com/flame-engine/flame/pull/3002 is released. -// ignore_for_file: deprecated_member_use import 'dart:async'; diff --git a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_obstacle_behavior.dart b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_obstacle_behavior.dart index ccba16ee..036e8a87 100644 --- a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_obstacle_behavior.dart +++ b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_obstacle_behavior.dart @@ -4,9 +4,10 @@ import 'package:trashy_road/src/game/game.dart'; /// Communicates to the [PlayerKeyboardMovingBehavior] that the player /// has collided with an [Obstacle]. -class PlayerObstacleBehavior extends CollisionBehavior { +class PlayerObstacleBehavior + extends CollisionBehavior { @override - void onCollisionStart(Set intersectionPoints, Obstacle other) { + void onCollisionStart(Set intersectionPoints, T other) { super.onCollisionStart(intersectionPoints, other); parent.findBehavior().bounceBack(); } diff --git a/packages/trashy_road/lib/src/game/entities/player/player.dart b/packages/trashy_road/lib/src/game/entities/player/player.dart index 578701b7..edca3b75 100644 --- a/packages/trashy_road/lib/src/game/entities/player/player.dart +++ b/packages/trashy_road/lib/src/game/entities/player/player.dart @@ -23,7 +23,8 @@ class Player extends PositionedEntity with ZIndex { ), PlayerCollectingTrashBehavior(), PlayerDepositingTrashBehavior(), - PlayerObstacleBehavior(), + PlayerObstacleBehavior(), + PlayerObstacleBehavior(), PausingBehavior( selector: (player) => player.findBehaviors(),