Ejemplo n.º 1
0
        //Places a room in the given tilemap using given coordinates and given constraints
        //enumerated at the top of the class.
        //Returns a Room object, which contains x,y coordinates, width, and height.
        public Room placeRoom(int[,] map, bool[,] cMap, int xCoor, int yCoor)
        {
            Room placedRoom;

            int randomWidthMax = random.Next(minRoomWidth, maxRoomWidth);
            int randomHeightMax = random.Next(minRoomHeight, maxRoomHeight);

            //Console.WriteLine("Random Width Max" + randomWidthMax);
            //Console.WriteLine("Random Height Max" + randomHeightMax);

            int leftMapBound = 0;
            int rightMapBound = map.GetLength(1) - 1;
            int upperMapBound = 0;
            int lowerMapBound = map.GetLength(0) - 1;
            int leftBound = xCoor - minRoomWidth;
            int rightBound = xCoor + minRoomWidth;
            int upperBound = yCoor - minRoomHeight;
            int lowerBound = yCoor + minRoomHeight;
            bool leftSet = false;
            bool rightSet = false;
            bool upperSet = false;
            bool lowerSet = false;

            //Console.WriteLine("X:" + xCoor);
            //Console.WriteLine("Y:" + yCoor);
            //Console.WriteLine("LeftBound:" + leftBound);
            //Console.WriteLine("Right Bound:" + rightBound);
            //Console.WriteLine("UpperBound:" + upperBound);
            //Console.WriteLine("Lower Bound:" + lowerBound);

            //for (int i = minRoomWidth; i < randomWidthMax; i++)
            //{
            //    if (map[yCoor, xCoor - i] != 0 || map[yCoor, xCoor + i] != 0)
            //    {
            //        leftBound = xCoor - i + 1;
            //        rightBound = xCoor + i - 1;
            //        i = randomWidthMax;
            //    }
            //}

            //for (int i = minRoomHeight; i < randomHeightMax; i++)
            //{
            //    if (map[yCoor - i, xCoor] != 0 || map[yCoor + i, xCoor] != 0)
            //    {
            //        upperBound = yCoor - i + 1;
            //        lowerBound = yCoor + i - 1;
            //        i = randomHeightMax;
            //    }
            //}

            int sizeCounter = (int)MathHelper.Min(minRoomHeight, minRoomWidth);
            while (sizeCounter <= randomWidthMax || sizeCounter <= randomHeightMax )
            {

                //Console.WriteLine(sizeCounter);

                if ((!leftSet || !upperSet) && map[yCoor - sizeCounter, xCoor - sizeCounter] != 0)
                {
                    //Console.WriteLine("Upper Left collision detected");
                    if (!leftSet)
                    {
                        leftBound = xCoor - sizeCounter + 1;
                        leftSet = true;
                    }
                    else if (!upperSet)
                    {
                        upperBound = yCoor - sizeCounter + 1;
                        upperSet = true;
                    }
                }

                if ((!rightSet || !upperSet) && map[yCoor - sizeCounter, xCoor + sizeCounter] != 0)
                {
                    //Console.WriteLine("Upper right collision detected");
                    if (!rightSet)
                    {
                        rightBound = xCoor + sizeCounter - 1;
                        rightSet = true;
                    }
                    if (!upperSet)
                    {
                        upperBound = yCoor - sizeCounter + 1;
                        upperSet = true;
                    }
                }

                if ((!leftSet || !lowerSet) && map[yCoor + sizeCounter, xCoor - sizeCounter] != 0)
                {
                    //Console.WriteLine("Lower Left collision detected");

                    if (!leftSet)
                    {
                        leftBound = xCoor - sizeCounter + 1;
                        leftSet = true;
                    }
                    if (!lowerSet)
                    {
                        lowerBound = yCoor + sizeCounter - 1;
                        lowerSet = true;
                    }
                }

                if ((!rightSet && !lowerSet) && map[yCoor + sizeCounter, xCoor + sizeCounter] != 0)
                {

                    //Console.WriteLine("Lower right collision detected");

                    if (!lowerSet)
                    {
                        lowerBound = yCoor + sizeCounter - 1;
                        lowerSet = true;
                    }
                    if (!rightSet)
                    {
                        rightBound = xCoor + sizeCounter - 1;
                        rightSet = true;
                    }
                }

                if (sizeCounter <= randomWidthMax)
                {
                    if (!leftSet)
                    {
                        if (map[yCoor, xCoor - sizeCounter] != 0)
                        {
                            leftBound = xCoor - sizeCounter + 1;
                            leftSet = true;
                        }
                        if (map[yCoor, xCoor - sizeCounter] == 0)
                        {
                            leftBound = xCoor - sizeCounter;
                        }
                    }

                    if (!rightSet)
                    {
                        if (map[yCoor, xCoor + sizeCounter] != 0)
                        {
                            rightBound = xCoor + sizeCounter - 1;
                            rightSet = true;
                        }
                        if (map[yCoor, xCoor + sizeCounter] == 0)
                        {
                            rightBound = xCoor + sizeCounter;
                        }
                    }
                }

                if (sizeCounter <= randomHeightMax)
                {
                    if (!upperSet)
                    {
                        if (map[yCoor - sizeCounter, xCoor] != 0)
                        {
                            upperBound = yCoor - sizeCounter + 1;
                            upperSet = true;
                        }
                        else if (map[yCoor - sizeCounter, xCoor] == 0)
                        {
                            upperBound = yCoor - sizeCounter;
                        }
                    }

                    if (!lowerSet)
                    {
                        if (map[yCoor + sizeCounter, xCoor] != 0)
                        {
                            lowerBound = yCoor + sizeCounter - 1;
                            lowerSet = true;
                        }
                        else if (map[yCoor + sizeCounter, xCoor] == 0)
                        {
                            lowerBound = yCoor + sizeCounter;
                        }

                    }
                }

                if (leftSet && rightSet && upperSet && lowerSet)
                {
                    //Console.WriteLine("Terminating loop - all bounds set");
                    sizeCounter = (int)MathHelper.Max(maxRoomWidth, maxRoomHeight) + 1;
                }

                sizeCounter++;

                if (xCoor - sizeCounter < leftMapBound || xCoor + sizeCounter > rightMapBound || yCoor - sizeCounter < upperMapBound || yCoor + sizeCounter > lowerMapBound)
                {
                    //Console.WriteLine("Terminating loop - room bounds went are illegal");
                    sizeCounter = (int)MathHelper.Max(maxRoomWidth, maxRoomHeight);
                }
            }

            //Console.WriteLine("LeftBound:" + leftBound);
            //Console.WriteLine("Right Bound:" + rightBound);
            //Console.WriteLine("UpperBound:" + upperBound);
            //Console.WriteLine("Lower Bound:" + lowerBound);

            map[upperBound, leftBound] = 1;
            map[upperBound, rightBound] = 3;
            map[lowerBound, leftBound] = 7;
            map[lowerBound, rightBound] = 9;

            for (int i = upperBound +1; i < lowerBound; i++)
            {
                map[i, leftBound] = 4;
                map[i, rightBound] = 6;
            }
            for (int i = leftBound +1; i < rightBound; i++)
            {
                map[upperBound, i] = 2;
                map[lowerBound, i] = 8;
            }

            for (int i = upperBound + 1; i < lowerBound; i++)
            {
                for (int j = leftBound + 1; j < rightBound; j++)
                {
                    map[i,j] = 5;
                    cMap[i, j] = true;
                }
            }
            //tileMap[yCoor, xCoor] = 14;

            //Console.WriteLine("Actual Width:" + (rightBound - leftBound + 1));
            //Console.WriteLine("Actual Height:" + (lowerBound - upperBound + 1));
            Rectangle dimensions = new Rectangle(leftBound, upperBound, rightBound - leftBound + 1, lowerBound - upperBound + 1);
            placedRoom = new Room(dimensions);
            return placedRoom;

        }
Ejemplo n.º 2
0
        public void placeKey(bool[,] cMap, Room room)
        {
            Rectangle dimensions = room.dimensions;
            Point coors;

            coors.X = (int)random.Next(dimensions.X + 1, dimensions.X + dimensions.Width - 2);
            coors.Y = (int)random.Next(dimensions.Y + 1, dimensions.Y + dimensions.Height - 2);

            SpawnFlag curSpawn;
            for (int i = 0; i < spawns.Count; i++)
            {
                curSpawn = spawns[0];
                if (curSpawn.tilePosition.X == coors.X && curSpawn.tilePosition.Y == coors.Y)
                {
                    coors.X = (int)random.Next(dimensions.X + 1, dimensions.X + dimensions.Width - 2);
                    coors.Y = (int)random.Next(dimensions.Y + 1, dimensions.Y + dimensions.Height - 2);
                }
            }

            SpawnFlag spawnFlag = new SpawnFlag("key", coors, (int)SPAWNTYPES.KEY);
            spawns.Add(spawnFlag);
            room.spawns.Add(spawnFlag);
        }
Ejemplo n.º 3
0
        public void placeEnemy(bool[,] cMap, Room room, List<SpawnFlag> spawns, String enemyType)
        {
            Rectangle dimensions = room.dimensions;
            Point coors;

            coors.X = (int)random.Next(dimensions.X + 1, dimensions.X + dimensions.Width - 2);
            coors.Y = (int)random.Next(dimensions.Y + 1, dimensions.Y + dimensions.Height - 2);

            SpawnFlag curSpawn;
            for (int i = 0; i < spawns.Count; i++ )
            {
                curSpawn = spawns[0];
                if (curSpawn.tilePosition.X == coors.X && curSpawn.tilePosition.Y == coors.Y)
                {
                    coors.X = (int)random.Next(dimensions.X + 1, dimensions.X + dimensions.Width - 2);
                    coors.Y = (int)random.Next(dimensions.Y + 1, dimensions.Y + dimensions.Height - 2);
                }
            }

            SpawnFlag spawnFlag = new SpawnFlag(enemyType, coors, 2);
            spawns.Add(spawnFlag);
        }
Ejemplo n.º 4
0
        public List<Room> partitionPastRoom(List<Room> rooms, Room lockedBranch)
        {
            rooms.Remove(lockedBranch);
            if (lockedBranch.children.Count > 0)
            {
                foreach (Room child in lockedBranch.children)
                {
                    rooms = partitionPastRoom(rooms, child);
                }
                return rooms;
            }else
            { 
                return rooms;
            }

        }