コード例 #1
0
    void CheckSelectorTouchesPlayer(GridLocation center)
    {
        GridSpace nextitemspace = currentlevelqueue.GetNextItemCost();

        // -- if we can place the object make sure the player is near it
        if (canplaceobject)
        {
            bool touchesplayer = false;
            switch (rotationpreview)
            {
            case 0:
                for (int i = 0; i < nextitemspace.shape.Length; ++i)
                {
                    if (nextitemspace.shape[i])
                    {
                        if (AnyGridNearPlayer0Rot(center, i))
                        {
                            // -- we are good, we can break
                            touchesplayer = true;
                            break;
                        }
                    }
                }
                break;

            case 90:
                for (int i = 0; i < nextitemspace.shape.Length; ++i)
                {
                    if (nextitemspace.shape[i])
                    {
                        if (AnyGridNearPlayer90Rot(center, i))
                        {
                            // -- we are good, we can break
                            touchesplayer = true;
                            break;
                        }
                    }
                }
                break;

            case 180:
                for (int i = 0; i < nextitemspace.shape.Length; ++i)
                {
                    if (nextitemspace.shape[i])
                    {
                        if (AnyGridNearPlayer180Rot(center, i))
                        {
                            // -- we are good, we can break
                            touchesplayer = true;
                            break;
                        }
                    }
                }
                break;

            case 270:
                for (int i = 0; i < nextitemspace.shape.Length; ++i)
                {
                    if (nextitemspace.shape[i])
                    {
                        if (AnyGridNearPlayer270Rot(center, i))
                        {
                            // -- we are good, we can break
                            touchesplayer = true;
                            break;
                        }
                    }
                }
                break;
            }

            if (!touchesplayer)
            {
                // - bummer. turn selector yellow so they know
                canplaceobject = false;

                for (int i = 0; i < nextitemspace.shape.Length; ++i)
                {
                    if (nextitemspace.shape[i])
                    {
                        selector.selectorpreview[i].color = Color.yellow;
                    }
                }
            }
        }
    }