public void initStartingWorld()
 {
     curLevel = 1;
     curWorld = this.worldFactory.generateWorld(worldPrototypes["temple"], 5);
     Node<World> rootWorld = new Node<World>(curWorld);
     curWorldNode = rootWorld;
     //Node<World> newWorldNode = Node<World>(curWorld);
     worldTree.setRoot(rootWorld);
 }
Example #2
0
        public void DrawFloor()
        {
            curWorld = worldManager.getCurWorld();
            Texture2D floorTileTex = curWorld.getFloorTileTex();
            int[,] tileMap = curWorld.getTileMap();
            int tileSize = curWorld.getTileSize();
            Rectangle screenRectangle;
            Rectangle sourceRectangle;
            


            for (int i = 0; i <= this.drawSpace.Height / tileSize + 1; i++)
            {
                for (int k = 0; k <= this.drawSpace.Width / tileSize + 1; k++)
                {
                    screenRectangle = new Rectangle((int)(k * tileSize - this.drawSpace.X % tileSize), (int)(i * tileSize - this.drawSpace.Y % tileSize), (int)(tileSize), (int)(tileSize));

                    if (i + (this.drawSpace.Y / tileSize) >= 0 && k + (this.drawSpace.X / tileSize) >= 0 && i + (this.drawSpace.Y / tileSize) < tileMap.GetLength(1) && k + (this.drawSpace.X / tileSize) < tileMap.GetLength(0))
                    //if (world.isInBounds(this.drawSpace.X + k * tileSize, this.drawSpace.Y + i * tileSize))
                    {
                        sourceRectangle = new Rectangle(tileMap[i + this.drawSpace.Y / tileSize, k + this.drawSpace.X / tileSize] * tileSize,
                                                        0,
                                                        tileSize,
                                                        tileSize);
                        spriteBatch.Draw(floorTileTex, screenRectangle, sourceRectangle, Color.White);
                    }
                }
            }
        }
 public World createNextWorld(int worldIndex)
 {
     World tempWorld = this.worldFactory.generateWorld(worldPrototypes["temple"], 5);
     Node<World> tempNode = new Node<World>(tempWorld);
     curWorldNode.Children.Insert(worldIndex, tempNode);
     curWorldNode = curWorldNode.Children[worldIndex];
     curWorld = curWorldNode.Value;
     curLevel++;
     return tempWorld;
 }
        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;
        }
        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;

        }
 public void restart()
 {
     curLevel = -1;
     curWorld = null;
     curWorldNode = null;
     worldChange(this, EventArgs.Empty);
 }
 public World createNextWorld(int worldIndex)
 {
     World prevWorld = curWorld;
     curLevel++;
     int difficulty = (int)((5 * Math.Log(curLevel) * curLevel)+ 5* Math.Sin(3*curLevel/2) + 5);
     World tempWorld;
     if (curLevel % 5 == 0)
     {
        List<WorldConfig> worldConfigs = worldPrototypes.Values.ToList();
        worldConfigs.Remove(prevWorld.worldConfig);
        tempWorld = this.worldFactory.generateWorld(worldConfigs[random.Next(0, worldConfigs.Count)], difficulty);
     }else{
         tempWorld = this.worldFactory.generateWorld(prevWorld.worldConfig, difficulty);
     }
     Node<World> tempNode = new Node<World>(tempWorld);
     curWorldNode.Children.Insert(worldIndex, tempNode);
     curWorldNode = curWorldNode.Children[worldIndex];
     curWorld = curWorldNode.Value;
     
     if (curWorld.themeMusic != prevWorld.themeMusic)
     {
         SoundManager.Instance.crossFadeSongs(prevWorld.themeMusic, curWorld.themeMusic);
     }
     return tempWorld;
 }
 public void initStartingWorld()
 {
     curLevel = 1;
     //curWorld = this.worldFactory.generateWorld(worldPrototypes["forest"], 5);
     curWorld = loadTutorialLevel();
     Node<World> rootWorld = new Node<World>(curWorld);
     curWorldNode = rootWorld;
     //Node<World> newWorldNode = Node<World>(curWorld);
     worldTree.setRoot(rootWorld);
     onWorldChange();
 }
 public void initTutorial()
 {
     curLevel = 1;
     curWorld = loadTutorialLevel();
     curWorld.isTutorial = true;
     Node<World> rootWorld = new Node<World>(curWorld);
     curWorldNode = rootWorld;
     worldTree.setRoot(rootWorld);
     SoundManager.Instance.playSong(curWorld.themeMusic);
     onWorldChange();
 }
 public void initStartingWorld()
 {
     curLevel = 1;
     curWorld = this.worldFactory.generateWorld(worldPrototypes["forest"], 5);
     Node<World> rootWorld = new Node<World>(curWorld);
     curWorldNode = rootWorld;
     worldTree.setRoot(rootWorld);
     SoundManager.Instance.playSong(curWorld.themeMusic);
     onWorldChange();
 }
Example #11
0
        private void World_Change(Object sender, EventArgs eventArgs)
        {

            WorldManager worldManager = (WorldManager)sender;
            this.curWorld = worldManager.curWorld;
            actors.Clear();
        }
Example #12
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;
        }
        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);
        }