示例#1
0
    private void SpawnExit(List <int> _avaliableIndex)
    {
        if (_avaliableIndex.Count >= 4)
        {
            float x = w - 1.5f;
            float y = Random.Range(1, h) - 0.5f;

            Vector2[] vec2 = new[] { new Vector2(+0.5f, -0.5f), new Vector2(+0.5f, +0.5f)
                                     , new Vector2(-0.5f, -0.5f), new Vector2(-0.5f, +0.5f) };

            BaseElement exit = SetElement <ExitElement>((int)(x + vec2[0].x), (int)(y + vec2[0].y));
            exit.transform.position = new Vector3(x, y, 0);
            exit.GetComponent <BoxCollider2D>().size = new Vector2(2, 2);
            //Destroy(exit.GetComponent<BoxCollider2D>());
            //exit.gameObject.AddComponent<BoxCollider2D>();

            for (int i = 0; i < vec2.Length; i++)
            {
                _avaliableIndex.Remove(GetIndexByPos((int)(x + vec2[i].x), (int)(y + vec2[i].y)));
                if (i != 0)
                {
                    Destroy(MapArray[(int)(x + vec2[i].x), (int)(y + vec2[i].y)].gameObject);
                    MapArray[(int)(x + vec2[i].x), (int)(y + vec2[i].y)] = exit;
                }
            }
        }
    }
示例#2
0
    /// <summary>
    /// 生成出口
    /// </summary>
    /// <param name="availableIndex">尚未初始化的地图元素的索引值列表</param>
    private void GenerateExit(List <int> availableIndex)
    {
        float       x    = w - 1.5f;
        float       y    = Random.Range(1, h) - 0.5f;
        BaseElement exit = SetElement(GetIndex((int)(x + 0.5), (int)(y - 0.5)), ElementContent.Exit);

        exit.transform.position = new Vector3(x, y, 0);
        Destroy(exit.GetComponent <BoxCollider2D>());
        exit.gameObject.AddComponent <BoxCollider2D>();
        availableIndex.Remove(GetIndex((int)(x + 0.5), (int)(y - 0.5)));
        availableIndex.Remove(GetIndex((int)(x + 0.5), (int)(y + 0.5)));
        availableIndex.Remove(GetIndex((int)(x - 0.5), (int)(y - 0.5)));
        availableIndex.Remove(GetIndex((int)(x - 0.5), (int)(y + 0.5)));
        Destroy(mapArray[(int)(x + 0.5), (int)(y + 0.5)].gameObject);
        Destroy(mapArray[(int)(x - 0.5), (int)(y - 0.5)].gameObject);
        Destroy(mapArray[(int)(x - 0.5), (int)(y + 0.5)].gameObject);
        mapArray[(int)(x + 0.5), (int)(y + 0.5)] = exit; //空的位置都指向exit位置
        mapArray[(int)(x - 0.5), (int)(y - 0.5)] = exit;
        mapArray[(int)(x - 0.5), (int)(y + 0.5)] = exit;
    }