public Controller(GraphicsDeviceManager graphics) { this.graphics = graphics; map = new Map(this, STARTMAPSIZE + level * 2); player = new Player(this); camera = new Camera(this, player.position, 32); player.health = player.maxHealth; map.CreateRandomLevel(3 + (int)level / 2, 2 + (int)level / 10, 2 + (int)level / 10, 3 + (int)level / 10, 3 + (int)level / 10); inv = new Inventory(this); inventory = inv.inventory; }
public Inventory(Controller controller) { this.controller = controller; player = controller.player; }
public void CreateRandomLevel(int numberOfRooms, int roomSizeX, int roomSizeY, int maxRoomSizeX, int maxRoomSizeY) { this.player = controller.player; ResetFloorVars(); while (roomList.Count == 0 || !CheckIfAllConnected(roomList)) { ResetFloorVars(); //CREATE BIG ROOMS for (int i = 0; i < numberOfRooms; i++) { GenerateRandomIsolatedRoom(roomSizeX, roomSizeY, maxRoomSizeX, maxRoomSizeY); } //CORRIDORS for (int i = 0; i < roomList.Count; i++) { Room tempRoom; int x1, x2, y1, y2; for (int i2 = 0; i2 < roomList.Count; i2++) { if (roomList[i].cornerNW.X <= roomList[i2].cornerNW.X) { x1 = roomList[i].cornerNW.X; x2 = roomList[i2].cornerSE.X; } else { x1 = roomList[i2].cornerNW.X; x2 = roomList[i].cornerSE.X; } tempRoom = new Room(controller, this, new Point(x1, roomList[i].cornerNW.Y), new Point(x2, roomList[i].cornerNW.Y + 1)); if (roomList[i2] != roomList[i]) { if (tempRoom.Intersects(roomList[i2])) { GenerateRoom(tempRoom.cornerNW, tempRoom.cornerSE); break; } } } for (int i2 = 0; i2 < roomList.Count; i2++) { if (roomList[i].cornerNW.Y <= roomList[i2].cornerNW.Y) { y1 = roomList[i].cornerNW.Y; y2 = roomList[i2].cornerSE.Y; } else { y1 = roomList[i2].cornerNW.Y; y2 = roomList[i].cornerSE.Y; } tempRoom = new Room(controller, this, new Point(roomList[i].cornerNW.X, y1), new Point(roomList[i].cornerNW.X + 1, y2)); if (tempRoom.Intersects(roomList[i2]) && roomList[i2] != roomList[i] /*&& IsIsolated(rm)*/) { GenerateRoom(tempRoom.cornerNW, tempRoom.cornerSE); break; } } } //ELIMINATE ISOLATED ROOMS for (int i = roomList.Count - 1; i > -1; i--) { if (IsIsolated(roomList[i]) && roomList.Count > 0) { for (int ix = roomList[i].cornerNW.X; ix < roomList[i].cornerSE.X; ix++) { for (int iy = roomList[i].cornerNW.Y; iy < roomList[i].cornerSE.Y; iy++) { mapArray[ix, iy] = (int)Element.Wall; } } for (int ib = bigRoomList.Count - 1; ib > -1; ib--) { if (bigRoomList[ib] == roomList[i]) { bigRoomList.RemoveAt(ib); break; } } roomList.RemoveAt(i); } } } //MAKE DOORS foreach (Room r in roomList) { CheckForDoors(r); } //STAIRS bool posInBig; Point stairs; do { posInBig = false; stairs = GenerateFreePos(); foreach (Room r in bigRoomList) { if (r.ContainsPoint(stairs)) { posInBig = true; break; } } } while (!posInBig); mapArray[stairs.X, stairs.Y] = (int)Element.Stairs; //PLAYER do { posInBig = false; player.position = GenerateFreePos(); foreach (Room r in bigRoomList) { if (r.ContainsPoint(player.position)) { posInBig = true; break; } } } while (!posInBig); //GENERATING ITEMS Point temp; bool overlap = false; for (int i = 0; i < bigRoomList.Count; i++) { overlap = false; temp = GenerateFreePos(); foreach (Item it in itemList) { if (temp == it.position) { overlap = true; } } if (temp != Point.Zero && temp != player.position && !overlap) { itemList.Add(new Item(controller, temp, (Map.Element)mapArray[temp.X, temp.Y])); mapArray[temp.X, temp.Y] = (int)Element.Item; } } //ENEMIES overlap = false; for (int i = 0; i < bigRoomList.Count + (int)controller.level / 10; i++) { overlap = false; temp = GenerateFreePos(); foreach (Enemy e in enemyList) { if (temp == e.position) { overlap = true; } } if (temp != Point.Zero && temp != player.position && !overlap) { Type t = typeof(Enemy.EnemyType); enemyList.Add(new Enemy(controller, temp, (Enemy.EnemyType)controller.random.Next(Enum.GetValues(t).Length))); } } mapString = ArrayToString(mapArray); controller.camera.ResetPosition(); GenerateFog(); GenerateMinimapFog(); }