Exemplo n.º 1
0
    private void SetPointerLocomotionTarget(Vector2 target, ObjectDirection moveDirection)
    {
        //Logger.Warning($"SetPointerLocomotionTarget to target {target.x}, {target.y} in the direction {moveDirection}");
        GridLocation targetGridLocation = GridLocation.FindClosestGridTile(target);

        if (!ValidateTarget(new TargetLocation(targetGridLocation, moveDirection)))
        {
            return;
        }

        Vector2 gridVectorTarget = GridLocation.GridToVector(targetGridLocation);

        if (CurrentGridLocation.X == targetGridLocation.X && CurrentGridLocation.Y == targetGridLocation.Y)
        {
            return;
        }

        if (!_animationHandler.InLocomotion)
        {
            _animationHandler.SetLocomotion(true);
        }

        IsCalculatingPath = true;

        PathToTarget = _pathfinding.FindNodePath(CurrentGridLocation, targetGridLocation);
        PathToTarget.RemoveAt(0);

        IsCalculatingPath = false;
        SetHasCalculatedTarget(true);
    }
Exemplo n.º 2
0
    public void TryStartCharacterMovement(ObjectDirection direction)
    {
        // check if character is in tile position, if so, start movement in direction.
        if (HasCalculatedTarget)
        {
            // if already in locomotion, it means that we are between tiles and we are moving. Return.
            return;
        }

        if (IsCalculatingPath)
        {
            return;
        }

        GridLocation currentGridLocation = GridLocation.VectorToGrid(transform.position);

        //Order character to go to another tile
        _animationHandler.SetDirection(direction);

        switch (direction)
        {
        case ObjectDirection.Down:
            TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X, currentGridLocation.Y - 1), direction);
            break;

        case ObjectDirection.Left:
            TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X - 1, currentGridLocation.Y), direction);
            break;

        case ObjectDirection.Right:
            TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X + 1, currentGridLocation.Y), direction);
            break;

        case ObjectDirection.Up:
            TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X, currentGridLocation.Y + 1), direction);
            break;

        default:
            Logger.Warning("Unhandled locomotion direction {0}", direction);
            return;
        }

        if (!ValidateTarget(TargetGridLocation))
        {
            // This prevents the character from displaying locomotion animation when walking into an unwalkable tile
            _animationHandler.SetLocomotion(false);
            return;
        }

        //Logger.Warning("Start path!");
        IsCalculatingPath = true;
        //Logger.Log($"TryStartCharacterMovement. {CurrentGridLocation.X},{CurrentGridLocation.Y} to {TargetGridLocation.TargetGridLocation.X}, {TargetGridLocation.TargetGridLocation.Y}");
        PathToTarget = _pathfinding.FindNodePath(CurrentGridLocation, TargetGridLocation.TargetGridLocation);
        PathToTarget.RemoveAt(0);

        IsCalculatingPath = false;
        SetHasCalculatedTarget(true);

        if (!_animationHandler.InLocomotion)
        {
            _animationHandler.SetLocomotion(true);
        }
    }