Skip to content

Instantly share code, notes, and snippets.

@Grenfur
Created June 3, 2018 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grenfur/dfe39c01464110279df09053e4cf917e to your computer and use it in GitHub Desktop.
Save Grenfur/dfe39c01464110279df09053e4cf917e to your computer and use it in GitHub Desktop.
TestRogue
using RLNET;
using TestRogue.Core;
using TestRogue.Systems;
using TestRogue.Interface;
namespace TestRogue
{
public class Game
{
private static readonly int _screenWidth = 100;
private static readonly int _screenHeight = 70;
private static RLRootConsole _rootConsole;
private static readonly int _mapWidth = 80;
private static readonly int _mapHeight = 48;
private static RLConsole _mapConsole;
private static readonly int _messageWidth = 80;
private static readonly int _messageHeight = 11;
private static RLConsole _messageConsole;
private static readonly int _statWidth = 20;
private static readonly int _statHeight = 70;
private static RLConsole _statConsole;
private static readonly int _inventoryWidth = 80;
private static readonly int _inventoryHeight = 11;
private static RLConsole _inventoryConsole;
private static bool _renderRequired = true;
public static Player Player { get; private set; }
public static DungeonMap DungeonMap { get; private set; }
public static CommandSystem CommandSystem { get; private set; }
public static void Main()
{
string fontFileName = "terminal8x8.png";
string consoleTitle = "TestRogue";
_rootConsole = new RLRootConsole(fontFileName, _screenWidth, _screenHeight, 8, 8, 1f, consoleTitle);
_mapConsole = new RLConsole(_mapWidth, _mapHeight );
_messageConsole = new RLConsole(_messageWidth, _messageHeight );
_statConsole = new RLConsole(_statWidth, _statHeight);
_inventoryConsole = new RLConsole(_inventoryWidth, _inventoryHeight);
Player = new Player();
MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight);
DungeonMap = mapGenerator.CreateMap();
DungeonMap.UpdatePlayerFieldOfView();
CommandSystem = new CommandSystem();
_rootConsole.Update += OnRootConsoleUpdate;
_rootConsole.Render += OnRootConsoleRender;
_messageConsole.SetBackColor(0, 0, _messageWidth, _messageHeight, Swatch.DbDeepWater);
_messageConsole.Print(1, 1, "Message", Colors.TextHeading);
_statConsole.SetBackColor(0, 0, _statWidth, _statHeight, Swatch.DbOldStone);
_statConsole.Print(1, 1, "Stats", Colors.TextHeading);
_inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Swatch.DbWood);
_inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading);
_rootConsole.Run();
}
private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e)
{
bool didPlayerAct = false;
RLKeyPress keyPress = _rootConsole.Keyboard.GetKeyPress();
if (keyPress != null)
{
if (keyPress.Key == RLKey.Up)
{
didPlayerAct = CommandSystem.MovePlayer(Direction.Up);
}
else if (keyPress.Key == RLKey.Down)
{
didPlayerAct = CommandSystem.MovePlayer(Direction.Down);
}
else if (keyPress.Key == RLKey.Left)
{
didPlayerAct = CommandSystem.MovePlayer(Direction.Left);
}
else if (keyPress.Key == RLKey.Right)
{
didPlayerAct = CommandSystem.MovePlayer(Direction.Right);
}
else if (keyPress.Key == RLKey.Escape)
{
_rootConsole.Close();
}
}
if (didPlayerAct)
{
_renderRequired = true;
}
}
private static void OnRootConsoleRender(object sender, UpdateEventArgs e)
{
if (_renderRequired)
{
DungeonMap.Draw(_mapConsole);
Player.Draw(_mapConsole, DungeonMap);
RLRootConsole.Blit(_mapConsole, 0, 0, _mapWidth, _mapHeight, _rootConsole, 0, _inventoryHeight);
RLRootConsole.Blit(_statConsole, 0, 0, _statWidth, _statHeight, _rootConsole, _mapWidth, 0);
RLRootConsole.Blit(_messageConsole, 0, 0, _messageWidth, _messageHeight, _rootConsole, 0, _screenHeight - _messageHeight);
RLRootConsole.Blit(_inventoryConsole, 0, 0, _inventoryWidth, _inventoryHeight, _rootConsole, 0, 0);
_rootConsole.Draw();
}
}
}
}
namespace TestRogue.Core
{
public enum Direction
{
None = 0,
DownLeft = 1,
Down = 2,
DownRight = 3,
Left = 4,
Center = 5,
Right = 6,
UpLeft = 7,
Up = 8,
UpRight = 9,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment