예제 #1
0
    public void SignalReady(MapGenerator.Room r)
    {
        float centerX = (r.innerRect.xMin + r.innerRect.xMax) / 2;
        float centerY = (r.innerRect.yMin + r.innerRect.yMax) / 2;

        player.transform.position = new Vector3(centerX, centerY);
        player.GetComponent <SpriteRenderer>().enabled = true;
    }
예제 #2
0
    private void PrepareMainRoom(ICollection <MapGenerator.Room> rooms)
    {
        foreach (MapGenerator.Room room in rooms)
        {
            if (room.isMainRoom)
            {
                mainRoom = room;
                break;
            }
        }

        if (mainRoom == null)
        {
            Debug.Log("Can´t find main room");
        }
    }
예제 #3
0
    public void Generate(MapGenerator.Room r)
    {
        int x = (int)r.outerRect.x;
        int y = (int)r.outerRect.y;
        int w = (int)r.outerRect.width - 1;
        int h = (int)r.outerRect.height - 1;

        for (int i = x; i < x + w; i++)
        {
            for (int j = y; j < y + h; j++)
            {
                groundMap.SetTile(new Vector3Int(i, j, 0), baseGroundTile);
            }
        }

        /*
         * for (int j = y; j < y + h; j++)
         * {
         *
         *  wallsMap.SetTile(new Vector3Int(x, j, 0), wallTiles[0]);
         *  wallsMap.SetTile(new Vector3Int(x + w, j, 0), wallTiles[1]);
         * }
         * for (int i = x; i < x + w; i++)
         * {
         *  wallsMap.SetTile(new Vector3Int(i, y, 0), wallTiles[2]);
         *  wallsMap.SetTile(new Vector3Int(i, y + h, 0), wallTiles[3]);
         * }
         *
         * wallsMap.SetTile(new Vector3Int(x, y, 0), cornerTiles[2]);
         * wallsMap.SetTile(new Vector3Int(x + w, y, 0), cornerTiles[3]);
         * wallsMap.SetTile(new Vector3Int(x, y + h, 0), cornerTiles[0]);
         * wallsMap.SetTile(new Vector3Int(x + w, y + h, 0), cornerTiles[1]);
         *
         */
        for (int j = y; j < y + h; j++)
        {
            wallsMap.SetTile(new Vector3Int(x, j, 0), wallRuleTile);
            wallsMap.SetTile(new Vector3Int(x + w, j, 0), wallRuleTile);
        }
        for (int i = x; i < x + w; i++)
        {
            wallsMap.SetTile(new Vector3Int(i, y, 0), wallRuleTile);
            wallsMap.SetTile(new Vector3Int(i, y + h, 0), wallRuleTile);
        }

        wallsMap.SetTile(new Vector3Int(x, y, 0), wallRuleTile);
        wallsMap.SetTile(new Vector3Int(x + w, y, 0), wallRuleTile);
        wallsMap.SetTile(new Vector3Int(x, y + h, 0), wallRuleTile);
        wallsMap.SetTile(new Vector3Int(x + w, y + h, 0), wallRuleTile);
        foreach (MapGenerator.Connection connect in r.confirmedConnections)
        {
            wallsMap.SetTile(connect.connectTile, null);
            GameObject d = Instantiate(doorPrefab, new Vector3(connect.connectTile.x + 0.5f, connect.connectTile.y + 0.5f), Quaternion.identity);
            if (connect.endTile.x != connect.startTile.x) // horizontal connection, measn door is in a vertical wall
            {
                //wallsMap.SetTile(new Vector3Int(connect.connectTile.x, connect.connectTile.y + 1, 0), doorCapTiles[0]);
                // wallsMap.SetTile(new Vector3Int(connect.connectTile.x, connect.connectTile.y - 1, 0), doorCapTiles[1]);
            }
            else //door is in horizontal wall
            {
            }
        }
    }
예제 #4
0
    public void CreateCheckPoints_Roombased(List <MapGenerator.Room> survivingRooms)
    {
        startRoom = new MapGenerator.Room();
        goalRoom  = new MapGenerator.Room();
        checkRoom = new MapGenerator.Room();
        bool startC = false;
        bool goalC  = false;
        int  connRoomsCount;

        foreach (MapGenerator.Room room in survivingRooms)
        {
            connRoomsCount = room.connectedRooms.Count;
            //Create start point
            if (connRoomsCount == 1 && !startC)
            {
                startRoom = room;
                foreach (MapGenerator.Coord tile in startRoom.ReturnTiles())
                {
                    if (mapGen.map [tile.tileX, tile.tileY - 1] == 1 && mapGen.IsInMapRange(tile.tileX, tile.tileY))
                    {
                        startX = tile.tileX;
                        startY = tile.tileY;
                        mapGen.map [tile.tileX, tile.tileY] = 2;
                        CreateArea(tile.tileX, tile.tileY);
                        startC = true;
                        break;
                    }
                }
            }
            //Create goal
            if (connRoomsCount == 1 && room != startRoom && !goalC)
            {
                goalRoom = room;
                foreach (MapGenerator.Coord tile in goalRoom.ReturnTiles())
                {
                    if (mapGen.map [tile.tileX, tile.tileY - 1] == 1 && mapGen.IsInMapRange(tile.tileX, tile.tileY))
                    {
                        goalX = tile.tileX;
                        goalY = tile.tileY;
                        mapGen.map [tile.tileX, tile.tileY] = 3;
                        CreateArea(tile.tileX, tile.tileY);
                        goalC = true;
                        break;
                    }
                }
            }
        }

        //Create checkpoints
        foreach (MapGenerator.Coord tile in mapGen.survivingPassageCoords)
        {
            if (previousCheckX == 0 && previousCheckY == 0)
            {
                previousCheckX = tile.tileX;
                previousCheckY = tile.tileY;
            }
            if (Mathf.Abs(tile.tileX - previousCheckX) > 20 && Mathf.Abs(tile.tileY - previousCheckY) > 20)
            {
                if (mapGen.map [tile.tileX, tile.tileY - 1] == 1 && mapGen.map [tile.tileX, tile.tileY] == 0 &&
                    mapGen.IsInMapRange(tile.tileX, tile.tileY))
                {
                    checkpointsPos.Add(tile);
                    previousCheckX = tile.tileX;
                    previousCheckY = tile.tileY;
                    mapGen.map [tile.tileX, tile.tileY] = 9;
                    CreateArea(tile.tileX, tile.tileY);
                }
            }
        }
    }