canMove method

bool canMove(
  1. Direction direction, {
  2. double? displacement,
  3. Iterable<ShapeHitbox>? ignoreHitboxes,
})

Implementation

bool canMove(
  Direction direction, {
  double? displacement,
  Iterable<ShapeHitbox>? ignoreHitboxes,
}) {
  double maxDistance = displacement ?? (speed * (dtUpdate * 2));

  switch (direction) {
    case Direction.right:
    case Direction.left:
    case Direction.up:
    case Direction.down:
      if (_checkRaycastDirection(
        direction,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      }
      break;
    case Direction.upLeft:
      if (_checkRaycastDirection(
        Direction.left,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      } else if (_checkRaycastDirection(
        Direction.up,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      }
      break;
    case Direction.upRight:
      if (_checkRaycastDirection(
        Direction.right,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      } else if (_checkRaycastDirection(
        Direction.up,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      }
      break;
    case Direction.downLeft:
      if (_checkRaycastDirection(
        Direction.left,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      } else if (_checkRaycastDirection(
        Direction.down,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      }
      break;
    case Direction.downRight:
      if (_checkRaycastDirection(
        Direction.right,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      } else if (_checkRaycastDirection(
        Direction.down,
        maxDistance,
        ignoreHitboxes: ignoreHitboxes,
      )) {
        return false;
      }
      break;
  }

  return true;
}