-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapScreen.cs
98 lines (82 loc) · 4.57 KB
/
MapScreen.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using GoRogue.Random;
using SadConsole;
using SadConsole.Input;
using SadRogue.Integration;
using SadRogue.Primitives;
using ShaiRandom.Generators;
using System.Diagnostics;
namespace AsciiGame
{
internal class MapScreen : ScreenObject
{
public bool debug = true;
public readonly MyGameMap Map;
public readonly RogueLikeEntity Player;
public readonly MessageLogConsole MessageLog;
public readonly GameInfoConsole GameInfo;
public readonly Console BorderConsole;
public readonly PopUpConsole PopUp;
// public readonly Console TurnDisplay;
public readonly ScreenSurface Border;
const int MessageLogHeight = 5;
const int DebugLogHeight = 5;
public MapScreen(MyGameMap map)
{
// Record the map we're rendering
Map = map;
// Create a renderer for the map, specifying viewport size. The value in DefaultRenderer is automatically
// managed by the map, and renders whenever the map is the active screen.
//
// CUSTOMIZATION: Pass in custom fonts/viewport sizes here.
//
// CUSTOMIZATION: If you want multiple renderers to render the same map, you can call CreateRenderer and
// manage them yourself; but you must call the map's RemoveRenderer when you're done with these renderers,
// and you must add any non-default renderers to the SadConsole screen object hierarchy, IN ADDITION
// to the map itself.
Map.DefaultRenderer = Map.CreateRenderer((Program.Width, Program.Height - MessageLogHeight));
//Map.DefaultRenderer.Font = SadConsole.Game.Instance.LoadFont("./fonts/C64.font");
// Make the Map (which is also a screen object) a child of this screen. You MUST have the map as a child
// of the active screen, even if you are using entirely custom renderers.
Map.Parent = this;
// Make sure the map is focused so that it and the entities can receive keyboard input
Map.IsFocused = true;
// Generate player, add to map at a random walkable position, and calculate initial FOV
Player = MapObjectFactory.Player();
Player.Position = GlobalRandom.DefaultRNG.RandomPosition(Map.WalkabilityView, true);
Player.Name = "Player";
Map.AddEntity(Player);
Player.AllComponents.GetFirst<PlayerFOVController>().CalculateFOV();
// Center view on player as they move
Map.DefaultRenderer?.SadComponents.Add(new SadConsole.Components.SurfaceComponentFollowTarget { Target = Player });
// Create message log
MessageLog = new MessageLogConsole(Program.Width / 2, MessageLogHeight);
MessageLog.Parent = this;
MessageLog.Position = new(0, Program.Height - MessageLogHeight);
// Create menu pop up
PopUp = new PopUpConsole(Program.Width / 2, MessageLogHeight);
PopUp.Parent = this;
PopUp.Position = new(0, MessageLogHeight + 20);
PopUp.DefaultBackground = Color.AnsiBlue;
PopUp.IsVisible = false;
// Create turn display
/*TurnDisplay = new TurnDisplayConsole(Program.Width / 2, MessageLogHeight);
TurnDisplay.Parent = this;
TurnDisplay.Position = new(MessageLog.Width + 1, Program.Height - MessageLogHeight);*/
// Create debug log
GameInfo = new GameInfoConsole(Program.Width / 2, MessageLogHeight);
GameInfo.Parent = this;
GameInfo.Position = new(MessageLog.Width + 1, Program.Height - MessageLogHeight);
GameInfo.IsVisible = debug;
// Create border between map and UI
BorderConsole = new Console(Map.Width, Map.Height);
BorderConsole.Position = Map.Position;
BorderConsole.Parent = this;
BorderConsole.DrawBox(new SadRogue.Primitives.Rectangle(Map.Position.X, Map.Position.Y, Program.Width, Program.Height - MessageLogHeight), new ColoredGlyph(Color.Red, Color.Black, '#'));
BorderConsole.DrawBox(new SadRogue.Primitives.Rectangle(MessageLog.Width, Program.Height - MessageLogHeight, 1, Program.Height - MessageLogHeight), new ColoredGlyph(Color.Red, Color.Black, '|'));
Border = new ScreenSurface(Program.Width, 1);
Border.Surface.DrawLine(new Point(60, 5), new Point(66, 20), '$', Color.AnsiBlue, Color.AnsiBlueBright, Mirror.None);
Border.UseMouse = false;
//BorderConsole.Children.Add(Border);
}
}
}