//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public DungeonMapRoom() { this.floor = null; this.room = null; this.hasTreasure = false; this.isBossRoom = false; this.sprite = null; this.isDiscovered = false; this.location = Point2I.Zero; }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public DungeonMapRoom() { this.floor = null; this.room = null; this.hasTreasure = false; this.isBossRoom = false; this.sprite = null; this.isDiscovered = false; this.location = Point2I.Zero; }
public override void Update() { cursorTimer++; if (cursorTimer >= 64) { cursorTimer = 0; } // [SELECT] to close the map screen. if (Controls.Select.IsPressed()) { GameControl.CloseMapScreen(); return; } if (!isChangingFloors) { // [UP] and [DOWN] to change floors. if (Controls.Up.IsPressed() && viewFloorIndex < discoveredFloors.Count - 1) { viewFloorIndex++; isChangingFloors = true; viewFloor = discoveredFloors[viewFloorIndex]; AudioSystem.PlaySound(GameData.SOUND_MENU_CURSOR_MOVE); } else if (Controls.Down.IsPressed() && viewFloorIndex > 0) { viewFloorIndex--; isChangingFloors = true; viewFloor = discoveredFloors[viewFloorIndex]; AudioSystem.PlaySound(GameData.SOUND_MENU_CURSOR_MOVE); } } else { // Update changing of floor view position. int nextFloorViewPosition = viewFloorIndex * 80; if (floorViewPosition < nextFloorViewPosition) { floorViewPosition = Math.Min(floorViewPosition + floorViewSpeed, nextFloorViewPosition); } else if (floorViewPosition > nextFloorViewPosition) { floorViewPosition = Math.Max(floorViewPosition - floorViewSpeed, nextFloorViewPosition); } if (floorViewPosition == nextFloorViewPosition) { isChangingFloors = false; } } }
private void DrawFloor(Graphics2D g, DungeonMapFloor floor, Point2I position) { // Draw the floor background rectangle. g.DrawSprite(GameData.SPR_UI_MAP_FLOOR_BACKGROUND, GameData.VARIANT_LIGHT, new Rectangle2I(position, new Point2I(64, 64))); // Draw the rooms. for (int x = 0; x < floor.Width; x++) { for (int y = 0; y < floor.Height; y++) { Point2I drawPos = position + (new Point2I(x, y) * 8); DrawRoom(g, floor.Rooms[x, y], drawPos); } } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public void OnOpen() { Room playerRoom = GameControl.LastRoomOnMap; dungeon = playerRoom.Dungeon; playerRoomLocation = playerRoom.Location; playerFloorNumber = 0; viewFloorIndex = 0; floorViewSpeed = 8; isChangingFloors = false; cursorTimer = 0; viewFloor = null; // Add the dungeon floors. DungeonFloor[] levelFloors = dungeon.GetFloors(); lowestFloorNumber = levelFloors[0].FloorNumber; highestFloorNumber = levelFloors[levelFloors.Length - 1].FloorNumber; floors.Clear(); discoveredFloors.Clear(); for (int i = 0; i < levelFloors.Length; i++) { DungeonMapFloor floor = new DungeonMapFloor(levelFloors[i]); floors.Add(floor); if (floor.DungeonFloor.Level == playerRoom.Level) { playerFloorNumber = floor.FloorNumber; viewFloor = floor; viewFloorIndex = discoveredFloors.Count; } if (floor.IsDiscovered || dungeon.HasMap) { discoveredFloors.Add(floor); } } floorViewPosition = viewFloorIndex * 80; }
public override void Draw(Graphics2D g) { if (dungeon == null) { return; } // Draw the background. g.DrawImage(backgroundImage, Point2I.Zero); // TODO: Draw the dungeon name panel. // Draw the floors. Point2I floorBasePos = new Point2I(); if (floors.Count < 6) { floorBasePos.Y = 72 + (8 * (floors.Count / 2)); } else { floorBasePos.Y = 88 + (4 * (floors.Count - 6)); } for (int i = 0; i < floors.Count; i++) { DungeonMapFloor floor = floors[i]; if (discoveredFloors.Contains(floor)) { // Draw the floor's label box on the left side of the screen. Point2I floorPos = floorBasePos - new Point2I(0, i * 8); string floorName = floor.FloorNumberText; g.DrawString(GameData.FONT_SMALL, floorName, floorPos, new Color(248, 248, 216)); // drop shadow g.DrawString(GameData.FONT_SMALL, floorName, floorPos + new Point2I(0, -1), new Color(56, 32, 16)); g.DrawSprite(GameData.SPR_UI_MAP_FLOOR_BOX_LEFT, GameData.VARIANT_LIGHT, floorPos + new Point2I(32, 0)); g.DrawSprite(GameData.SPR_UI_MAP_FLOOR_BOX_RIGHT, GameData.VARIANT_LIGHT, floorPos + new Point2I(40, 0)); // Draw the icons around the name box. if (viewFloor == floor) { g.DrawSprite(GameData.SPR_UI_MAP_FLOOR_INDICATOR, GameData.VARIANT_LIGHT, floorPos + new Point2I(24, 0)); } if (playerFloorNumber == floor.FloorNumber) { g.DrawSprite(GameData.SPR_UI_MAP_PLAYER, GameData.VARIANT_LIGHT, floorPos + new Point2I(36, 0)); } if (floor.IsBossFloor && dungeon.HasCompass) { g.DrawSprite(GameData.SPR_UI_MAP_BOSS_FLOOR, GameData.VARIANT_LIGHT, floorPos + new Point2I(48, 0)); } // Draw the floor's room display on the right side of the screen. int discoveredFloorIndex = discoveredFloors.IndexOf(floor); Point2I floorRoomDisplayPos = new Point2I(80, 40 - (80 * discoveredFloorIndex) + floorViewPosition); if (floorRoomDisplayPos.Y < GameSettings.SCREEN_HEIGHT && floorRoomDisplayPos.Y > -80) { DrawFloor(g, floor, floorRoomDisplayPos); } // Draw room display cursor. if (!isChangingFloors && viewFloor == floor && cursorTimer < 32) { Point2I drawPos = floorRoomDisplayPos + (playerRoomLocation * 8); g.DrawSprite(GameData.SPR_UI_MAP_CURSOR, GameData.VARIANT_LIGHT, drawPos); } } } // Draw floor view traversal arrows. if (!isChangingFloors) { if (viewFloorIndex > 0) { g.DrawSprite(GameData.SPR_UI_MAP_ARROW_DOWN, GameData.VARIANT_LIGHT, 108, 108); } if (viewFloorIndex < discoveredFloors.Count - 1) { g.DrawSprite(GameData.SPR_UI_MAP_ARROW_UP, GameData.VARIANT_LIGHT, 108, 28); } } // Draw the items panel. if (dungeon.HasMap) { g.DrawSprite(GameData.SPR_REWARD_MAP, GameData.VARIANT_LIGHT, 8, 110); } if (dungeon.HasCompass) { g.DrawSprite(GameData.SPR_REWARD_COMPASS, GameData.VARIANT_LIGHT, 32, 110); } if (dungeon.HasBossKey) { g.DrawSprite(GameData.SPR_REWARD_BOSS_KEY, GameData.VARIANT_LIGHT, 8, 128); } if (dungeon.NumSmallKeys > 0) { g.DrawSprite(GameData.SPR_REWARD_SMALL_KEY, GameData.VARIANT_LIGHT, 32, 128); g.DrawString(GameData.FONT_SMALL, "X" + dungeon.NumSmallKeys.ToString(), new Point2I(40, 136), new Color(144, 136, 16)); // drop shadow g.DrawString(GameData.FONT_SMALL, "X" + dungeon.NumSmallKeys.ToString(), new Point2I(40, 136 - 1), new Color(32, 24, 16)); } }
//----------------------------------------------------------------------------- // Static Methods //----------------------------------------------------------------------------- public static DungeonMapRoom Create(Room room, DungeonMapFloor floor) { // Don't show empty rooms. if (IsRoomEmpty(room)) return null; // Create the map room object. DungeonMapRoom mapRoom = new DungeonMapRoom() { room = room, hasTreasure = room.HasUnopenedTreasure(), isDiscovered = room.IsDiscovered, isBossRoom = room.IsBossRoom, location = room.Location, sprite = null, floor = floor, }; // Determine the sprite to draw for this room based on its connections. Sprite[] connectedSprites = new Sprite[16] { GameData.SPR_UI_MAP_ROOM_NONE, GameData.SPR_UI_MAP_ROOM_RIGHT, GameData.SPR_UI_MAP_ROOM_UP, GameData.SPR_UI_MAP_ROOM_UP_RIGHT, GameData.SPR_UI_MAP_ROOM_LEFT, GameData.SPR_UI_MAP_ROOM_LEFT_RIGHT, GameData.SPR_UI_MAP_ROOM_LEFT_UP, GameData.SPR_UI_MAP_ROOM_LEFT_UP_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN, GameData.SPR_UI_MAP_ROOM_DOWN_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN_UP, GameData.SPR_UI_MAP_ROOM_DOWN_UP_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP_RIGHT, }; // Check for room connections. int[] connected = new int[] { 0, 0, 0, 0 }; for (int y = 0; y < room.Height; y++) { bool freeOnRight = true; bool freeOnLeft = true; for (int i = 0; i < room.LayerCount; i++) { TileDataInstance left = room.GetTile(0, y, i); if (left != null && left.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(left.Type)) freeOnLeft = false; TileDataInstance right = room.GetTile(room.Width - 1, y, i); if (right != null && right.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(right.Type)) freeOnRight = false;; } if (freeOnRight) connected[Directions.Right] = 1; if (freeOnLeft) connected[Directions.Left] = 1; } for (int x = 0; x < room.Width; x++) { bool freeOnUp = true; bool freeOnDown = true; for (int i = 0; i < room.LayerCount; i++) { TileDataInstance up = room.GetTile(x, 0, i); TileDataInstance down = room.GetTile(x, room.Height - 1, i); if (up != null && up.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(up.Type)) freeOnUp = false; if (down != null && down.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(down.Type)) freeOnDown = false; } if (freeOnUp) connected[Directions.Up] = 1; if (freeOnDown) connected[Directions.Down] = 1; } int spiteIndex = (connected[0]) + (connected[1] << 1) + (connected[2] << 2) + (connected[3] << 3); mapRoom.sprite = connectedSprites[spiteIndex]; return mapRoom; }
//----------------------------------------------------------------------------- // Static Methods //----------------------------------------------------------------------------- public static DungeonMapRoom Create(Room room, DungeonMapFloor floor) { // Don't show empty rooms. if (IsRoomEmpty(room)) { return(null); } // Create the map room object. DungeonMapRoom mapRoom = new DungeonMapRoom() { room = room, hasTreasure = room.HasUnopenedTreasure(), isDiscovered = room.IsDiscovered, isBossRoom = room.IsBossRoom, location = room.Location, sprite = null, floor = floor, }; // Determine the sprite to draw for this room based on its connections. Sprite[] connectedSprites = new Sprite[16] { GameData.SPR_UI_MAP_ROOM_NONE, GameData.SPR_UI_MAP_ROOM_RIGHT, GameData.SPR_UI_MAP_ROOM_UP, GameData.SPR_UI_MAP_ROOM_UP_RIGHT, GameData.SPR_UI_MAP_ROOM_LEFT, GameData.SPR_UI_MAP_ROOM_LEFT_RIGHT, GameData.SPR_UI_MAP_ROOM_LEFT_UP, GameData.SPR_UI_MAP_ROOM_LEFT_UP_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN, GameData.SPR_UI_MAP_ROOM_DOWN_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN_UP, GameData.SPR_UI_MAP_ROOM_DOWN_UP_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_RIGHT, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP, GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP_RIGHT, }; // Check for room connections. int[] connected = new int[] { 0, 0, 0, 0 }; for (int y = 0; y < room.Height; y++) { bool freeOnRight = true; bool freeOnLeft = true; for (int i = 0; i < room.LayerCount; i++) { TileDataInstance left = room.GetTile(0, y, i); if (left != null && left.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(left.Type)) { freeOnLeft = false; } TileDataInstance right = room.GetTile(room.Width - 1, y, i); if (right != null && right.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(right.Type)) { freeOnRight = false; } ; } if (freeOnRight) { connected[Directions.Right] = 1; } if (freeOnLeft) { connected[Directions.Left] = 1; } } for (int x = 0; x < room.Width; x++) { bool freeOnUp = true; bool freeOnDown = true; for (int i = 0; i < room.LayerCount; i++) { TileDataInstance up = room.GetTile(x, 0, i); TileDataInstance down = room.GetTile(x, room.Height - 1, i); if (up != null && up.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(up.Type)) { freeOnUp = false; } if (down != null && down.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(down.Type)) { freeOnDown = false; } } if (freeOnUp) { connected[Directions.Up] = 1; } if (freeOnDown) { connected[Directions.Down] = 1; } } int spiteIndex = (connected[0]) + (connected[1] << 1) + (connected[2] << 2) + (connected[3] << 3); mapRoom.sprite = connectedSprites[spiteIndex]; return(mapRoom); }
private void DrawFloor(Graphics2D g, DungeonMapFloor floor, Point2I position) { // Draw the floor background rectangle. g.DrawSprite(GameData.SPR_UI_MAP_FLOOR_BACKGROUND, GameData.VARIANT_LIGHT, new Rectangle2I(position, new Point2I(64, 64))); // Draw the rooms. for (int x = 0; x < floor.Width; x++) { for (int y = 0; y < floor.Height; y++) { Point2I drawPos = position + (new Point2I(x, y) * 8); DrawRoom(g, floor.Rooms[x, y], drawPos); } } }
public override void Update() { cursorTimer++; if (cursorTimer >= 64) cursorTimer = 0; // [SELECT] to close the map screen. if (Controls.Select.IsPressed()) { GameControl.CloseMapScreen(); return; } if (!isChangingFloors) { // [UP] and [DOWN] to change floors. if (Controls.Up.IsPressed() && viewFloorIndex < discoveredFloors.Count - 1) { viewFloorIndex++; isChangingFloors = true; viewFloor = discoveredFloors[viewFloorIndex]; AudioSystem.PlaySound(GameData.SOUND_MENU_CURSOR_MOVE); } else if (Controls.Down.IsPressed() && viewFloorIndex > 0) { viewFloorIndex--; isChangingFloors = true; viewFloor = discoveredFloors[viewFloorIndex]; AudioSystem.PlaySound(GameData.SOUND_MENU_CURSOR_MOVE); } } else { // Update changing of floor view position. int nextFloorViewPosition = viewFloorIndex * 80; if (floorViewPosition < nextFloorViewPosition) floorViewPosition = Math.Min(floorViewPosition + floorViewSpeed, nextFloorViewPosition); else if (floorViewPosition > nextFloorViewPosition) floorViewPosition = Math.Max(floorViewPosition - floorViewSpeed, nextFloorViewPosition); if (floorViewPosition == nextFloorViewPosition) isChangingFloors = false; } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public void OnOpen() { Room playerRoom = GameControl.LastRoomOnMap; dungeon = playerRoom.Dungeon; playerRoomLocation = playerRoom.Location; playerFloorNumber = 0; viewFloorIndex = 0; floorViewSpeed = 8; isChangingFloors = false; cursorTimer = 0; viewFloor = null; // Add the dungeon floors. DungeonFloor[] levelFloors = dungeon.GetFloors(); lowestFloorNumber = levelFloors[0].FloorNumber; highestFloorNumber = levelFloors[levelFloors.Length - 1].FloorNumber; floors.Clear(); discoveredFloors.Clear(); for (int i = 0; i < levelFloors.Length; i++) { DungeonMapFloor floor = new DungeonMapFloor(levelFloors[i]); floors.Add(floor); if (floor.DungeonFloor.Level == playerRoom.Level) { playerFloorNumber = floor.FloorNumber; viewFloor = floor; viewFloorIndex = discoveredFloors.Count; } if (floor.IsDiscovered || dungeon.HasMap) discoveredFloors.Add(floor); } floorViewPosition = viewFloorIndex * 80; }