Exemplo n.º 1
0
    public bool CanRotate(Vector3 spin)
    {
        // List<Vector2> toCheck = Rotator.GetSquaresToCheck(this.xy, spin);
        // foreach (Vector2 p in toCheck) {
        //  // Debug.Log(p);
        // }
        // ------testing:
        // spin = new Vector3 (10, 10, 1);
        // Vector2 pos = new Vector3 (10, 20);
        // Debug.Log("GROUP:::::::");
        // foreach (Crate crate in this.group.crates) {
        //  Debug.Log(crate.xy);
        // }
        List <Vector2> toCheck = Rotator.GetSquaresToCheck(this.xy, spin);

        if (dot)
        {
            foreach (Vector2 v in toCheck)
            {
                GameObject dotGO = Instantiate(dotPrefab);
                dotGO.transform.position = v;
            }
        }
        // Debug.LogFormat("Crate: Can Rotate {0}", this.xy);
        foreach (Vector2 target in toCheck)
        {
            // Debug.LogFormat("Checking {0}",target);
            Machine targetMachine     = Machines.At(target);
            bool    blockedByObstacle = targetMachine && targetMachine.isObstacle;
            if (blockedByObstacle)
            {
                Debug.Log("blockedByObstacle");
                return(false);
            }

            bool blockedByPusherArm = CheckPusherArms(target);
            if (blockedByPusherArm)
            {
                Debug.Log("blockedByPusherArm");
                return(false);
            }

            Crate targetCrate = Crates.At(target);
            if (targetCrate)
            {
                if (targetCrate && !group.crates.Contains(targetCrate))
                {
                    Debug.Log("blockedByOtherCrateGroup");
                    return(false);
                }
            }
        }
        return(true);
    }