コード例 #1
0
ファイル: Room.cs プロジェクト: TommasoBianchi/LudumDare37
    public void Generate()
    {
        bool[,] map = new bool[width, height];

        FillMap(map);

        for (int i = 0; i < 5; i++)
        {
            map = CellularAutomataPass(map);
        }

        RemoveUnconnectedParts(map);

        nearestTiles = new Vector2[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (map[x, y])
                {
                    InstantiateFloorTile(map, x, y);
                    if (IsFloor(map, x, y + 1) && IsFloor(map, x, y - 1) && IsFloor(map, x + 1, y) && IsFloor(map, x - 1, y))
                    {
                        nearestTiles[x, y] = new Vector2(x, y);
                    }
                    else
                    {
                        nearestTiles[x, y] = -Vector2.one;
                    }
                }
                else
                {
                    nearestTiles[x, y] = -Vector2.one;
                }
            }
        }

        PrefillNearestTiles(map);

        if (topDoor == null)
        {
            GameObject door = Instantiate(doorPrefab, fallbackTopDoorPosition, Quaternion.identity, transform) as GameObject;
            topDoor = door.GetComponent <Door>();
            Debug.LogWarning("Top door in fallback position");
        }
        topDoor.room = this;

        if (bottomDoor == null)
        {
            GameObject door = Instantiate(doorPrefab, fallbackBottomDoorPosition, Quaternion.identity, transform) as GameObject;
            bottomDoor = door.GetComponent <Door>();
            Debug.LogWarning("Bottom door in fallback position");
        }
        bottomDoor.room      = this;
        bottomDoor.doorToHub = true;

        RoomPlan = RoomPlanFactory.getInstance().getRoomPlan(this.ID, this);
    }
コード例 #2
0
 void Start()
 {
     instance = this;
 }