protected override void Handle(ProgramData data) { Entity stairsEntity = null; StairsComponent stairsComponent = null; foreach (var entity in Entities.With <StairsComponent>()) { stairsComponent = entity.Get <StairsComponent>(); if (entity.X == data.GameData.Player.X && entity.Y == data.GameData.Player.Y) { stairsEntity = entity; break; } } if (stairsEntity != null) { data.GameData.DungeonLevel = data.GameData.DungeonLevel.GoToFloor(stairsComponent.ToFloor, data.GameData.Player, data.GameData.MessageLog); data.GameData.SetEntities(data.GameData.DungeonLevel.Entities); data.FovRecompute = true; data.DefaultConsole.Clear(); } else { data.GameData.MessageLog.AddMessage("There are no stairs here.", Color.Yellow); } }
public static Entity CreateStairsEntity() { var e = CreateEntity(Guid.NewGuid().ToString(), "jump point"); e.AddComponent(DisplayComponent.Create(_texJumpPointPath, "The jump point to the next sector.", true, ITEM_Z_INDEX)); e.AddComponent(StairsComponent.Create()); return(e); }
public void MakeMap(int maxRooms, int minRoomSize, int maxRoomSize, int mapWidth, int mapHeight, Entity player, List <Entity> entities) { var rooms = new List <Rectangle>(); Point lastCenter = new Point(0, 0); if (!entities.Contains(player)) { entities.Add(player); } for (int i = 0; i < maxRooms; i++) { var width = Rng.Next(minRoomSize, maxRoomSize + 1); var height = Rng.Next(minRoomSize, maxRoomSize + 1); var x = Rng.Next(mapWidth - width); var y = Rng.Next(mapHeight - height); var newRoom = new Rectangle(x, y, width, height); if (rooms.Any(room => newRoom.Intersects(room))) { continue; } CreateRoom(newRoom); var newCenter = newRoom.Center; lastCenter.Set(newCenter); if (rooms.Count == 0) { player.X = newCenter.X; player.Y = newCenter.Y; if (DungeonLevel > 1) { var upStairsComponent = new StairsComponent { ToFloor = DungeonLevel - 1 }; var upStairs = new Entity { X = lastCenter.X, Y = lastCenter.Y, Character = '<', Color = Color.White, Name = $"Stairs to Level {upStairsComponent.ToFloor}", RenderOrder = RenderOrder.Stairs }; upStairs.Add(upStairsComponent); entities.Add(upStairs); } } else { var prevCenter = rooms[rooms.Count - 1].Center; if (Rng.Next(2) == 1) { CreateHorizontalTunnel(prevCenter.X, newCenter.X, prevCenter.Y); CreateVerticalTunnel(prevCenter.Y, newCenter.Y, newCenter.X); } else { CreateVerticalTunnel(prevCenter.Y, newCenter.Y, prevCenter.X); CreateHorizontalTunnel(prevCenter.X, newCenter.X, newCenter.Y); } } PlaceEntities(newRoom, entities); rooms.Add(newRoom); } var downStairsComponent = new StairsComponent { ToFloor = DungeonLevel + 1 }; var downStairs = new Entity { X = lastCenter.X, Y = lastCenter.Y, Character = '>', Color = Color.White, Name = $"Stairs to Level {downStairsComponent.ToFloor}", RenderOrder = RenderOrder.Stairs }; downStairs.Add(downStairsComponent); entities.Add(downStairs); }