Ejemplo n.º 1
0
    /// <summary>
    /// Do the calculation for the next player movement
    ///
    /// Calculate the swipe direction
    /// Calculate the next position if we move
    /// Check if the move is not out of bound
    /// Apply the movement
    /// </summary>
    /// <param name="touch"></param>
    /// <param name="direction"></param>
    void Movement(TouchStruct touch, Vector2 direction)
    {
        Vector3 swipeDirection = ToolBox.instance.ClosestDirection(direction);

        float angle = ToolBox.instance.ClosestAngle2D(-swipeDirection, lastDirection);

        body.Rotate(new Vector3(0, 0, angle), Space.Self);

        float nextPosX = currentGridIndex.x + swipeDirection.x;
        float nextPosY = currentGridIndex.y + swipeDirection.y;

        lastDirection = -swipeDirection;

        targetGridIndex = movementGrid.ClampIndexOnGrid((int)nextPosX, (int)nextPosY);
        StartCoroutine(MoveAnimation(movementGrid.GetPosition((int)targetGridIndex.x, (int)targetGridIndex.y)));
    }
Ejemplo n.º 2
0
    /// <summary>
    /// If it s the first move play triangle animation.
    /// Else search possible position on the grid
    ///  and get killed if no more movement are available
    /// </summary>
    void NextMove()
    {
        if (!hasEntered)
        {
            triangleCreator.TransformTriangle(MovementSpeed);
            hasEntered = true;
            return;
        }

        float nextPosX = currentGridIndex.x - direction.x;
        float nextPosY = currentGridIndex.y - direction.y;

        if (movementGrid.IndexExist((int)nextPosX, (int)nextPosY))
        {
            targetGridIndex = movementGrid.ClampIndexOnGrid((int)nextPosX, (int)nextPosY);
        }
        else
        {
            eManager.Killed(this);
            GameObject.Destroy(gameObject);
        }

        StartCoroutine(MoveAnimation(movementGrid.GetPosition(targetGridIndex.x, targetGridIndex.y)));
    }