moveFromDirection method

void moveFromDirection(
  1. Direction direction, {
  2. bool enabledDiagonal = true,
})

Implementation

void moveFromDirection(
  Direction direction, {
  bool enabledDiagonal = true,
}) {
  if (direction != lastDirection) {
    setZeroVelocity();
  }
  switch (direction) {
    case Direction.left:
      moveLeft();
      break;
    case Direction.right:
      moveRight();
      break;
    case Direction.up:
      moveUp();
      break;
    case Direction.down:
      moveDown();
      break;
    case Direction.upLeft:
      if (enabledDiagonal) {
        moveUpLeft();
      } else {
        moveRight();
      }
      break;
    case Direction.upRight:
      if (enabledDiagonal) {
        moveUpRight();
      } else {
        moveRight();
      }
      break;
    case Direction.downLeft:
      if (enabledDiagonal) {
        moveDownLeft();
      } else {
        moveLeft();
      }
      break;
    case Direction.downRight:
      if (enabledDiagonal) {
        moveDownRight();
      } else {
        moveRight();
      }
      break;
  }
}