Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
fix: bug where small movements moved the player incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliePugh committed Mar 12, 2024
1 parent 7c8c641 commit bb1032f
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import 'package:trashy_road/src/game/game.dart';
/// This behavior is meant to be used in conjunction with
/// [PlayerMovingBehavior].
class PlayerDragMovingBehavior extends Behavior<Player> {
static const _swipeThreshold = 50;

late final PlayerMovingBehavior _playerMovingBehavior;

Offset _startPosition = Offset.zero;
Expand Down Expand Up @@ -46,15 +44,15 @@ class PlayerDragMovingBehavior extends Behavior<Player> {
final isVertical = verticalDelta.abs() > horizontalDelta.abs();

if (isVertical) {
final isUpwardsSwipe = verticalDelta < -_swipeThreshold;
final isUpwardsSwipe = verticalDelta < 0;

if (isUpwardsSwipe) {
_playerMovingBehavior.move(Direction.up);
} else {
_playerMovingBehavior.move(Direction.down);
}
} else {
final isRightSwipe = horizontalDelta > _swipeThreshold;
final isRightSwipe = horizontalDelta > 0;

if (isRightSwipe) {
_playerMovingBehavior.move(Direction.right);
Expand Down

0 comments on commit bb1032f

Please sign in to comment.