/* method that will move a ball in a certain direction, or hop in a certain direction */

    public bool moveBall(Direction d)
    {
        Dimple moveToDimple = CurrentDimple.getNeighborAtDirection(d);

        //Debug.Log (d);
        //Debug.Log (moveToDimple);
        if (moveToDimple == null)
        {
            return(false);
        }
        else
        {
            if (moveToDimple.isOccupied())
            {
                Debug.Log("occupied");

                // if moveToDimple alreayd has a ball, check if we can jump
                moveToDimple = moveToDimple.getNeighborAtDirection(d);
                // valid jump?
                if (moveToDimple == null || moveToDimple.isOccupied())
                {
                    return(false);
                }
            }
        }
        CurrentDimple.toggleOccupied();
        // This is where we update position?

        CurrentDimple = moveToDimple;
        CurrentDimple.toggleOccupied();

        Vector3 newPos = this.transform.position;

        newPos.x = CurrentDimple.transform.position.x;
        newPos.z = CurrentDimple.transform.position.z;
        this.transform.position = newPos;

        return(true);
    }
Ejemplo n.º 2
0
    public void AddNeighboringDimple(Neighbor n)
    {
        // add the neighbor if there isn't already one in that direction
        if (getNeighborAtDirection(n.direction) == null)
        {
            neighbors.Add(n);
        }
        else
        {
            return;
        }

        Dimple neighborDimple = n.dimple;

        // get direction to THIS dimple from new neighbor
        Direction acrossDirection = acrossFromDirection(n.direction);

        // ad THIS dimple as neighbor to the neighbor at the new direction
        if (neighborDimple.getNeighborAtDirection(acrossDirection) == null)
        {
            neighborDimple.AddNeighboringDimple(new Neighbor(this, acrossDirection));
        }
    }