Ejemplo n.º 1
0
        public World loadFromCustom(Texture2D tile, int tileSize, int[,] tileMap, bool[,] collisionMap, Point playerSpawnPos, List <String> enemyTypeList, List <Point> enemySpawnPosList)
        {
            World            tempWorld   = new World(tile, tileSize);
            List <SpawnFlag> spawns      = new List <SpawnFlag>();
            SpawnFlag        playerSpawn = new SpawnFlag("player", playerSpawnPos, 1);

            tempWorld.setTileMap(tileMap, collisionMap);
            spawns.Add(playerSpawn);
            tempWorld.setSpawnTile(playerSpawnPos);
            SpawnFlag enemySpawn;

            if (enemyTypeList.Count == enemySpawnPosList.Count)
            {
                for (int i = 0; i < enemyTypeList.Count; i++)
                {
                    enemySpawn        = new SpawnFlag(enemyTypeList.ElementAt(i), enemySpawnPosList.ElementAt(i), 2);
                    enemySpawn.hasKey = true;
                    spawns.Add(enemySpawn);
                }
            }
            tempWorld.setSpawns(spawns);
            tempWorld.themeMusic = "forestTheme";
            return(tempWorld);
        }
Ejemplo n.º 2
0
        public World generateWorld(Texture2D floorTex, int width, int height, int tileSize, int numEnemies)
        {
            rooms            = new List <Room>();
            spawns           = new List <SpawnFlag>();
            newWorld         = new World(floorTex, tileSize);
            tileMap          = new int[height, width];
            collisionMap     = new bool[height, width];
            remainingEnemies = numEnemies;

            for (int i = 0; i < tileMap.GetLength(0); i++)
            {
                tileMap[i, 0]         = -1;
                tileMap[i, width - 1] = -1;
            }

            for (int i = 0; i < tileMap.GetLength(1); i++)
            {
                tileMap[0, i]          = -1;
                tileMap[height - 1, i] = -1;
            }

            Rectangle validWorldSpace = new Rectangle(1, 1, width - 1, height - 1);
            Point     coors           = chooseRoomSite(tileMap, validWorldSpace);
            Room      firstRoom       = placeRoom(tileMap, collisionMap, coors.X, coors.Y);

            firstRoom.startRoom = true;

            Point     spawnPos    = new Point(coors.X, coors.Y);
            SpawnFlag playerSpawn = new SpawnFlag("player", spawnPos, 1);

            spawns.Add(playerSpawn);
            newWorld.setSpawnTile(spawnPos);
            tileMap[coors.Y, coors.X] = 14;

            rooms.Add(firstRoom);

            int  roomIndex = 0;
            int  numRooms  = 1;
            Room curRoom   = rooms.ElementAt(roomIndex);

            while (numRooms < maxRooms)
            {
                int[] hallCoors;

                //Console.WriteLine("Current room index" + roomIndex);

                //Console.WriteLine("Room#" + numRooms);
                //if(numRooms > 1)
                //    hallCoors = chooseHallSite(tileMap, curRoom.dimensions);
                //else
                hallCoors = chooseHallSite(tileMap, curRoom.dimensions);

                if (hallCoors[0] == -1)
                {
                    //Console.WriteLine("Couldn't find a good hall site");

                    if (roomIndex == 0)
                    {
                        roomIndex = random.Next(0, rooms.Count);
                    }
                    else
                    {
                        roomIndex--;
                    }

                    curRoom = rooms.ElementAt(roomIndex);
                }
                else
                {
                    if (random.Next(0, 4) == 0)
                    {
                        Room splitRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        rooms.Add(splitRoom);
                    }
                    else
                    {
                        curRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        rooms.Add(curRoom);
                    }

                    placeHall(tileMap, collisionMap, hallCoors[0], hallCoors[1], hallCoors[2], hallCoors[3]);
                    roomIndex++;
                    numRooms++;
                }
            }

            Room room;

            for (int i = 0; i < rooms.Count; i++)
            {
                room = rooms.ElementAt(i);
                if (i != 0)
                {
                    placeEnemy(collisionMap, room, spawns);
                }
                if (i == rooms.Count - 1)
                {
                    tileMap[room.dimensions.Y + room.dimensions.Height / 2, room.dimensions.X + room.dimensions.Width / 2] = 15;
                }
            }

            //Set room list here
            newWorld.setTileMap(tileMap, collisionMap);
            newWorld.setSpawns(spawns);
            return(newWorld);
        }
Ejemplo n.º 3
0
        public World generateWorld(Texture2D floorTex, List<String> enemyClasses, int width, int height, int tileSize, int numEnemies)
        {
            rooms = new List<Room>();
            spawns = new List<SpawnFlag>();
            newWorld = new World(floorTex, tileSize);
            tileMap = new int[height, width];
            collisionMap = new bool[height, width];
            remainingEnemies = numEnemies;

            for (int i = 0; i < tileMap.GetLength(0); i++)
            {
                tileMap[i, 0] = -1;
                tileMap[i, width - 1] = -1;
            }

            for (int i = 0; i < tileMap.GetLength(1); i++)
            {
                tileMap[0, i] = -1;
                tileMap[height - 1, i] = -1;
            }

            Rectangle validWorldSpace = new Rectangle(1, 1, width - 1, height - 1);
            Point coors = chooseRoomSite(tileMap, validWorldSpace);
            Room firstRoom = placeRoom(tileMap, collisionMap, coors.X, coors.Y);
            firstRoom.startRoom = true;

            Point spawnPos = new Point(coors.X, coors.Y);
            SpawnFlag playerSpawn = new SpawnFlag("player", spawnPos, 1);
            spawns.Add(playerSpawn);
            newWorld.setSpawnTile(spawnPos);
            tileMap[coors.Y, coors.X] = 14;

            rooms.Add(firstRoom);

            int roomIndex = 0;
            int numRooms = 1;
            Room curRoom = rooms.ElementAt(roomIndex);
            while(numRooms < maxRooms)
            {
                int[] hallCoors;

                //Console.WriteLine("Current room index" + roomIndex);

                //Console.WriteLine("Room#" + numRooms);
                //if(numRooms > 1)
                //    hallCoors = chooseHallSite(tileMap, curRoom.dimensions);
                //else
                hallCoors = chooseHallSite(tileMap, curRoom.dimensions);

                if (hallCoors[0] == -1)
                {
                    //Console.WriteLine("Couldn't find a good hall site");
                    
                    if (roomIndex == 0)
                        roomIndex = random.Next(0, rooms.Count);
                    else
                        roomIndex--;

                    curRoom = rooms.ElementAt(roomIndex);
                }
                else
                {
                    if (random.Next(0, 4) == 0)
                    {
                        Room splitRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        rooms.Add(splitRoom);
                    }
                    else
                    {
                        curRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        rooms.Add(curRoom);
                    }
                    
                    placeHall(tileMap, collisionMap, hallCoors[0], hallCoors[1], hallCoors[2], hallCoors[3]);
                    roomIndex++;
                    numRooms++;
                }
            }

            Room room;
            String enemyClass;
            for (int i = 0; i < rooms.Count; i++)
            {
                room = rooms.ElementAt(i);
                if (i != 0)
                {
                    enemyClass = enemyClasses[random.Next(0,enemyClasses.Count)];
                    placeEnemy(collisionMap, room, spawns, enemyClass);
                }
                if (i == rooms.Count - 1)
                {
                    tileMap[room.dimensions.Y + room.dimensions.Height / 2, room.dimensions.X + room.dimensions.Width / 2] = 15;
                }
            }

            //Set room list here
            newWorld.setTileMap(tileMap, collisionMap);
            newWorld.setSpawns(spawns);
            return newWorld;
        }
Ejemplo n.º 4
0
        public World loadFromCustom(Texture2D tile, int tileSize, int[,] tileMap, bool[,] collisionMap, Point playerSpawnPos, List<String> enemyTypeList, List<Point> enemySpawnPosList)
        {
            World tempWorld = new World(tile, tileSize);
            List<SpawnFlag> spawns = new List<SpawnFlag>();
            SpawnFlag playerSpawn = new SpawnFlag("player", playerSpawnPos, 1);
            tempWorld.setTileMap(tileMap, collisionMap);
            spawns.Add(playerSpawn);
            tempWorld.setSpawnTile(playerSpawnPos);
            SpawnFlag enemySpawn;
            if(enemyTypeList.Count == enemySpawnPosList.Count)
            {
                for(int i = 0; i < enemyTypeList.Count; i++)
                {
                    enemySpawn = new SpawnFlag(enemyTypeList.ElementAt(i), enemySpawnPosList.ElementAt(i), 2);
                    spawns.Add(enemySpawn);
                }
            }
            tempWorld.setSpawns(spawns);
            return tempWorld;

        }
Ejemplo n.º 5
0
        public World generateWorld(Texture2D floorTex, List<EnemyConfig> enemyConfigs, int tileSize, int difficulty)
        {
            rooms = new List<Room>();
            spawns = new List<SpawnFlag>();
            int enemyDifficultyCap = difficulty /5;
            int healthPotions = difficulty / 30;
            List<EnemyConfig> availableEnemies = enemyConfigs.FindAll(x => x.difficulty <= difficulty );
            List<EnemyConfig> chosenEnemies = new List<EnemyConfig>();
            while (enemyDifficultyCap > 0 && availableEnemies.Count > 0)
            {
                EnemyConfig choosenEnemy = availableEnemies[random.Next(0,availableEnemies.Count)];
                chosenEnemies.Add(choosenEnemy);
                enemyDifficultyCap -= choosenEnemy.difficulty;
                availableEnemies = enemyConfigs.FindAll(x => x.difficulty <= difficulty );
            }
            maxRooms = (int)(difficulty / 5) + 3;
            int width = (maxRooms * maxRoomWidth * 2) + (maxRooms * maxHallLength);
            int height = (maxRooms * maxRoomHeight * 2) + (maxRooms * maxHallLength);
            newWorld = new World(floorTex, tileSize);
            tileMap = new int[height, width];
            collisionMap = new bool[height, width];
            //remainingEnemies = numEnemies;

            for (int i = 0; i < tileMap.GetLength(0); i++)
            {
                tileMap[i, 0] = -1;
                tileMap[i, width - 1] = -1;
            }

            for (int i = 0; i < tileMap.GetLength(1); i++)
            {
                tileMap[0, i] = -1;
                tileMap[height - 1, i] = -1;
            }

            Rectangle validWorldSpace = new Rectangle(1, 1, width - 1, height - 1);
            Point coors = chooseRoomSite(tileMap, validWorldSpace);
            Room firstRoom = placeRoom(tileMap, collisionMap, coors.X, coors.Y);
            firstRoom.startRoom = true;
            firstRoom.isOptional = false;
            firstRoom.depth = 0;

            Point spawnPos = new Point(coors.X, coors.Y);
            SpawnFlag playerSpawn = new SpawnFlag("player", spawnPos, (int)SPAWNTYPES.ACTOR);
            spawns.Add(playerSpawn);
            newWorld.setSpawnTile(spawnPos);
            //tileMap[coors.Y, coors.X] = 14;

            rooms.Add(firstRoom);

            int roomIndex = 0;
            int numRooms = 1;
            Room curRoom = rooms.ElementAt(roomIndex);
            while(numRooms < maxRooms)
            {
                int[] hallCoors;

                //Console.WriteLine("Current room index" + roomIndex);

                //Console.WriteLine("Room#" + numRooms);
                //if(numRooms > 1)
                //    hallCoors = chooseHallSite(tileMap, curRoom.dimensions);
                //else
                hallCoors = chooseHallSite(tileMap, curRoom.dimensions);

                if (hallCoors[0] == -1)
                {
                    //Console.WriteLine("Couldn't find a good hall site");
                    
                    if (roomIndex == 0)
                        roomIndex = random.Next(0, rooms.Count);
                    else
                        roomIndex--;

                    curRoom = rooms.ElementAt(roomIndex);
                }
                else
                {
                    if (random.Next(0, 4) == 0)
                    {
                        Room splitRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        splitRoom.hallEntrance = new Point(hallCoors[0], hallCoors[1]);
                        splitRoom.parent = curRoom;
                        curRoom.children.Add(splitRoom);
                        splitRoom.depth = splitRoom.parent.depth + 1;
                        splitRoom.isOptional = true;
                        rooms.Add(splitRoom);
                    }
                    else
                    {
                        Room tempRoom = curRoom;
                        curRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        curRoom.hallEntrance = new Point(hallCoors[0], hallCoors[1]);
                        curRoom.roomCenter = new Point(hallCoors[0], hallCoors[1]);
                        curRoom.parent = tempRoom;
                        tempRoom.children.Add(curRoom);
                        curRoom.depth = curRoom.parent.depth + 1;
                        curRoom.isOptional = true;
                        rooms.Add(curRoom);
                        //curRoom.parentRoom = rooms.ElementAt(roomIndex);
                    }
                    
                    placeHall(tileMap, collisionMap, hallCoors[0], hallCoors[1], hallCoors[2], hallCoors[3]);
                    roomIndex++;
                    numRooms++;
                }
            }

            Room room = rooms.ElementAt(rooms.Count - 1);
            tileMap[room.dimensions.Y + room.dimensions.Height / 2, room.dimensions.X + room.dimensions.Width / 2] = 15;
            room.isLeaf = true;
            room = room.parent;

            while (room.parent != null)
            {
                room.isOptional = false;
                room.isLeaf = true;
                room = room.parent;
            }
            
            foreach(EnemyConfig tempConfig in chosenEnemies){
                room = rooms.ElementAt(random.Next(1,rooms.Count - 2));
                placeEnemy(collisionMap, room, spawns, tempConfig.enemyClass);
            }

            List<Room> possibleLockedRooms = rooms.FindAll(x => !x.isOptional && !x.startRoom && x.depth > 1);

            if (possibleLockedRooms.Count > 0)
            {
                Room lockedRoom = possibleLockedRooms[random.Next(0, possibleLockedRooms.Count - 1)];
                //tileMap[lockedRoom.hallEntrance.Y, lockedRoom.hallEntrance.X] = 15;
                SpawnFlag lockedDoorFlag;
                if (floorTex.Name == "hellTiles")
                    lockedDoorFlag = new SpawnFlag("Big_Door", lockedRoom.hallEntrance, (int)SPAWNTYPES.DOOR);
                else
                    lockedDoorFlag = new SpawnFlag("Generic_Door", lockedRoom.hallEntrance, (int)SPAWNTYPES.DOOR);
                spawns.Add(lockedDoorFlag);
                List<Room> possibleKeyRooms = new List<Room>(rooms);
                possibleKeyRooms = partitionPastRoom(possibleKeyRooms, lockedRoom);
                Room keyRoom;
                if (possibleKeyRooms.FindAll(x => x.isLeaf).Count > 0)
                {
                    List<Room> keyRooms = possibleKeyRooms.FindAll(x => x.isLeaf);
                    keyRoom = keyRooms[random.Next(0, keyRooms.Count - 1)];
                }
                else
                {
                    keyRoom = possibleKeyRooms[random.Next(0, possibleKeyRooms.Count - 1)];
                }

                if (keyRoom.spawns.Count > 0)
                {
                    SpawnFlag tempEnemyConfig = keyRoom.spawns[random.Next(0, keyRoom.spawns.Count - 1)];
                    tempEnemyConfig.hasKey = true;
                }
                else
                {
                    placeKey(collisionMap, keyRoom);
                }
            }

            List<Room> possiblePotionRooms = rooms;

            while(healthPotions > 0)
            {
                Room potionRoom = possiblePotionRooms[random.Next(0, possiblePotionRooms.Count - 1)];
                placePotion(collisionMap, potionRoom, spawns, "Weak_Potion");
                healthPotions--;
            }

            //Set room list here
            newWorld.setTileMap(tileMap, collisionMap);
            newWorld.setSpawns(spawns);
            return newWorld;
        }
Ejemplo n.º 6
0
        public World generateWorld(Texture2D floorTex, List <EnemyConfig> enemyConfigs, int tileSize, int difficulty)
        {
            rooms  = new List <Room>();
            spawns = new List <SpawnFlag>();
            int enemyDifficultyCap = difficulty / 5;
            int healthPotions      = difficulty / 30;
            List <EnemyConfig> availableEnemies = enemyConfigs.FindAll(x => x.difficulty <= difficulty);
            List <EnemyConfig> chosenEnemies    = new List <EnemyConfig>();

            while (enemyDifficultyCap > 0 && availableEnemies.Count > 0)
            {
                EnemyConfig choosenEnemy = availableEnemies[random.Next(0, availableEnemies.Count)];
                chosenEnemies.Add(choosenEnemy);
                enemyDifficultyCap -= choosenEnemy.difficulty;
                availableEnemies    = enemyConfigs.FindAll(x => x.difficulty <= difficulty);
            }
            maxRooms = (int)(difficulty / 5) + 3;
            int width  = (maxRooms * maxRoomWidth * 2) + (maxRooms * maxHallLength);
            int height = (maxRooms * maxRoomHeight * 2) + (maxRooms * maxHallLength);

            newWorld     = new World(floorTex, tileSize);
            tileMap      = new int[height, width];
            collisionMap = new bool[height, width];
            //remainingEnemies = numEnemies;

            for (int i = 0; i < tileMap.GetLength(0); i++)
            {
                tileMap[i, 0]         = -1;
                tileMap[i, width - 1] = -1;
            }

            for (int i = 0; i < tileMap.GetLength(1); i++)
            {
                tileMap[0, i]          = -1;
                tileMap[height - 1, i] = -1;
            }

            Rectangle validWorldSpace = new Rectangle(1, 1, width - 1, height - 1);
            Point     coors           = chooseRoomSite(tileMap, validWorldSpace);
            Room      firstRoom       = placeRoom(tileMap, collisionMap, coors.X, coors.Y);

            firstRoom.startRoom  = true;
            firstRoom.isOptional = false;
            firstRoom.depth      = 0;

            Point     spawnPos    = new Point(coors.X, coors.Y);
            SpawnFlag playerSpawn = new SpawnFlag("player", spawnPos, (int)SPAWNTYPES.ACTOR);

            spawns.Add(playerSpawn);
            newWorld.setSpawnTile(spawnPos);
            //tileMap[coors.Y, coors.X] = 14;

            rooms.Add(firstRoom);

            int  roomIndex = 0;
            int  numRooms  = 1;
            Room curRoom   = rooms.ElementAt(roomIndex);

            while (numRooms < maxRooms)
            {
                int[] hallCoors;

                //Console.WriteLine("Current room index" + roomIndex);

                //Console.WriteLine("Room#" + numRooms);
                //if(numRooms > 1)
                //    hallCoors = chooseHallSite(tileMap, curRoom.dimensions);
                //else
                hallCoors = chooseHallSite(tileMap, curRoom.dimensions);

                if (hallCoors[0] == -1)
                {
                    //Console.WriteLine("Couldn't find a good hall site");

                    if (roomIndex == 0)
                    {
                        roomIndex = random.Next(0, rooms.Count);
                    }
                    else
                    {
                        roomIndex--;
                    }

                    curRoom = rooms.ElementAt(roomIndex);
                }
                else
                {
                    if (random.Next(0, 4) == 0)
                    {
                        Room splitRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        splitRoom.hallEntrance = new Point(hallCoors[0], hallCoors[1]);
                        splitRoom.parent       = curRoom;
                        curRoom.children.Add(splitRoom);
                        splitRoom.depth      = splitRoom.parent.depth + 1;
                        splitRoom.isOptional = true;
                        rooms.Add(splitRoom);
                    }
                    else
                    {
                        Room tempRoom = curRoom;
                        curRoom = placeRoom(tileMap, collisionMap, hallCoors[4], hallCoors[5]);
                        curRoom.hallEntrance = new Point(hallCoors[0], hallCoors[1]);
                        curRoom.roomCenter   = new Point(hallCoors[0], hallCoors[1]);
                        curRoom.parent       = tempRoom;
                        tempRoom.children.Add(curRoom);
                        curRoom.depth      = curRoom.parent.depth + 1;
                        curRoom.isOptional = true;
                        rooms.Add(curRoom);
                        //curRoom.parentRoom = rooms.ElementAt(roomIndex);
                    }

                    placeHall(tileMap, collisionMap, hallCoors[0], hallCoors[1], hallCoors[2], hallCoors[3]);
                    roomIndex++;
                    numRooms++;
                }
            }

            Room room = rooms.ElementAt(rooms.Count - 1);

            tileMap[room.dimensions.Y + room.dimensions.Height / 2, room.dimensions.X + room.dimensions.Width / 2] = 15;
            room.isLeaf = true;
            room        = room.parent;

            while (room.parent != null)
            {
                room.isOptional = false;
                room.isLeaf     = true;
                room            = room.parent;
            }

            foreach (EnemyConfig tempConfig in chosenEnemies)
            {
                room = rooms.ElementAt(random.Next(1, rooms.Count - 2));
                placeEnemy(collisionMap, room, spawns, tempConfig.enemyClass);
            }

            List <Room> possibleLockedRooms = rooms.FindAll(x => !x.isOptional && !x.startRoom && x.depth > 1);

            if (possibleLockedRooms.Count > 0)
            {
                Room lockedRoom = possibleLockedRooms[random.Next(0, possibleLockedRooms.Count - 1)];
                //tileMap[lockedRoom.hallEntrance.Y, lockedRoom.hallEntrance.X] = 15;
                SpawnFlag lockedDoorFlag;
                if (floorTex.Name == "hellTiles")
                {
                    lockedDoorFlag = new SpawnFlag("Big_Door", lockedRoom.hallEntrance, (int)SPAWNTYPES.DOOR);
                }
                else
                {
                    lockedDoorFlag = new SpawnFlag("Generic_Door", lockedRoom.hallEntrance, (int)SPAWNTYPES.DOOR);
                }
                spawns.Add(lockedDoorFlag);
                List <Room> possibleKeyRooms = new List <Room>(rooms);
                possibleKeyRooms = partitionPastRoom(possibleKeyRooms, lockedRoom);
                Room keyRoom;
                if (possibleKeyRooms.FindAll(x => x.isLeaf).Count > 0)
                {
                    List <Room> keyRooms = possibleKeyRooms.FindAll(x => x.isLeaf);
                    keyRoom = keyRooms[random.Next(0, keyRooms.Count - 1)];
                }
                else
                {
                    keyRoom = possibleKeyRooms[random.Next(0, possibleKeyRooms.Count - 1)];
                }

                if (keyRoom.spawns.Count > 0)
                {
                    SpawnFlag tempEnemyConfig = keyRoom.spawns[random.Next(0, keyRoom.spawns.Count - 1)];
                    tempEnemyConfig.hasKey = true;
                }
                else
                {
                    placeKey(collisionMap, keyRoom);
                }
            }

            List <Room> possiblePotionRooms = rooms;

            while (healthPotions > 0)
            {
                Room potionRoom = possiblePotionRooms[random.Next(0, possiblePotionRooms.Count - 1)];
                placePotion(collisionMap, potionRoom, spawns, "Weak_Potion");
                healthPotions--;
            }

            //Set room list here
            newWorld.setTileMap(tileMap, collisionMap);
            newWorld.setSpawns(spawns);
            return(newWorld);
        }