Example #1
0
    ///<summary>Moves the nodes of the snake for one turn, with animation if necessary.
    /// Returns the game coordinates of the space just vacated (where the tail was before the move).</summary>
    public int[] move(float timeToMove, bool shouldMoveSmoothly)
    {
        int[]     old     = this.tail.getCoordinates();
        SnakeNode newTail = this.tail.getNodeBefore();
        SnakeNode newHead = this.tail; // the tail moves up to become the head

        this.ghostNode.goToCoordinates(this.tail.getCoordinates());
        newHead.goToCoordinates(this.head.getCoordinates());

        // slide ghostNode into the tail and newHead out of the current head to animate the snake's movement
        this.ghostNode.StartCoroutine(this.ghostNode.moveToCoordinates(newTail.getCoordinates(), timeToMove, shouldMoveSmoothly));
        newHead.StartCoroutine(newHead.moveToCoordinates(this.head.coordinatesOfNextNode(), timeToMove, shouldMoveSmoothly));
        newHead.setDirection(this.head.getDirection());

        // point to the new head and tail
        this.head.setNodeBefore(newHead);
        newHead.setNodeBefore(null);
        this.tail = newTail;
        this.head = newHead;
        return(old);
    }