static void Main(string[] args) { rootConsole = new RLRootConsole("cheepicus12x12.png", rootWidth, rootHeigth, 12, 12, 1f, "TestRL"); rootConsole.Update += OnRootConsoleUpdate; rootConsole.Render += OnRootConsoleRender; mapConsole = new RLConsole(mapWidth, mapHeigth); inventoryConsole = new RLConsole(inventoryWidth, inventoryHeigth); logConsole = new RLConsole(logWidth, logHeigth); statsConsole = new RLConsole(statsWidth, statsHeigth); mapConsole.SetBackColor(0, 0, mapWidth, mapHeigth, RLColor.Black); //mapConsole.Print(1, 1, "Map", RLColor.White); logConsole.SetBackColor(0, 0, logWidth, logHeigth, RLColor.Gray); logConsole.Print(1, 1, "Log", RLColor.White); inventoryConsole.SetBackColor(0, 0, inventoryWidth, inventoryHeigth, RLColor.Brown); inventoryConsole.Print(1, 1, "Inventory", RLColor.White); statsConsole.SetBackColor(0, 0, statsWidth, statsHeigth, RLColor.Cyan); statsConsole.Print(1, 1, "Stats", RLColor.White); MapGenerator mapGenerator = new MapGenerator(mapWidth, mapHeigth); dungeonMap = mapGenerator.CreateCave(true); cmd = new Command(); player = new Player(); dungeonMap.UpdateFOV(player); rootConsole.Run(); }
private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e) { // draw the console that we setup //Write this code at the start too check if your console update method has actually worked first //_rootConsole.Print(10, 10, "It worked", RLColor.Green); bool didPlayerAct = false; RLKeyPress keyPress = _rootConsole.Keyboard.GetKeyPress(); if (commandSystem.IsPlayerTurn) { //if you have pressed a key if (keyPress != null) { //checks what key you have pressed if it was up down left or right and depending on the key //uses the command system class too find you new position on the map 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 player is on a stairs going down cell and presses period it will create a new map and message log and //command system it will increase the map level and show it and change player act too true else if (keyPress.Key == RLKey.Period) { if (DungeonMap.CanMoveDownToNextLevel()) { MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 20, 13, 7, ++_mapLevel); DungeonMap = mapGenerator.CreateMap(); messageLog = new MessageLog(); commandSystem = new CommandSystem(); _rootConsole.Title = $"RougeSharp - Level {_mapLevel}"; didPlayerAct = true; player.MaxHealth += 5; player.Health = player.MaxHealth; player.Gold += 20; } } } } if (didPlayerAct) { //counts the steps player took //messageLog.Add($"Step # {++_steps}"); _renderRequired = true; commandSystem.EndPlayerTurn(); } else { commandSystem.ActivateMonsters(); _renderRequired = true; } //set the background color and text for each console except the map and message consoles //_messageConsole.SetBackColor(0, 0, _messageWidth, _messageHeight, RLColor.Red); //_statConsole.SetBackColor(0, 0, _statWidth, _statHeight, RLColor.Red); //_statConsole.Print(1, 1, "Stats", Colors.TextHeading); _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, RLColor.Cyan); _inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading); }
public void Blit(RLConsole console) { console.SetBackColor(0, 0, console.Width, console.Height, RLColor.Black); console.Print(console.Width / 2 - 4, console.Height / 2 - 1, "YOU DIED", RLColor.White); console.Print(console.Width / 2 - 11, console.Height / 2 + 1, "You made it to level " + this.level, RLColor.White); }
protected void Clear() { _console.Clear(); _console.SetBackColor(0, 0, _width, _height, _backColor); }
//Main Game loop public static void Main() { SchedulingSystem = new SchedulingSystem(); //Generates a semi-random number from the current timestamp int seed = (int)DateTime.UtcNow.Ticks; mapSeed = seed; //Sets the random number to be equal to the current seed Random = new DotNetRandom(seed); //File name for the custom font (RLNet library requires custom 8x8 font) string fontFile = "terminal8x8.png"; //Title included at the top of the console window // UPDATE LATER TO SHOW CURRENT DUNGEON LEVEL string windowTitle = "Shiv - Seed: " + seed + " Level: " + mapLevel; //Creates a new commands to control the player Commands = new Commands(); //Creates new console window using below parameters //(font file name, screen width, screen height, width per tile, // height per tile, scale of tiles, console title) rootConsole = new RLRootConsole(fontFile, screenWidth, screenHeight, 8, 8, 1f, windowTitle); //Instantiates console subdivisions mapConsole = new RLConsole(mapWidth, mapHeight); messageConsole = new RLConsole(messageWidth, messageHeight); statsConsole = new RLConsole(statsWidth, statsHeight); inventoryConsole = new RLConsole(inventoryWidth, inventoryHeight); armourConsole = new RLConsole(armourWidth, armourHeight); //Creates a new map generator MapGenerator mapGenerator = new MapGenerator(mapWidth, mapHeight, 40, 14, 7, mapLevel); //Creates a new map using the map generator instantiated above DungeonMap = mapGenerator.CreateMap(); //Updates the Player's field of view on the map DungeonMap.UpdatePlayerFOV(); Inventory = new Inventory(); //Sets background color for each subdivision of the console window //Prints string to label each subdivision mapConsole.SetBackColor(0, 0, mapWidth, mapHeight, Colors.FloorBackground); messageConsole.SetBackColor(0, 0, messageWidth, messageHeight, Palette.AlternateLightest); messageConsole.Print(1, 1, "Messages", Colors.TextHeading); messageConsole.Print(1, 2, "________", Colors.TextHeading); statsConsole.SetBackColor(0, 0, statsWidth, statsHeight, Palette.AlternateLightest); statsConsole.Print(1, 1, "Stats", Colors.TextHeading); statsConsole.Print(1, 2, "_____", Colors.TextHeading); statsConsole.Print(1, 21, "Enemies:", Colors.TextHeading); statsConsole.Print(1, 22, "________", Colors.TextHeading); inventoryConsole.SetBackColor(0, 0, inventoryWidth, inventoryHeight, Palette.PrimaryDarker); inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading); inventoryConsole.Print(1, 2, "_________", Colors.TextHeading); inventoryConsole.Print(1, 5, "Slot 1: " + Inventory.slot1, Colors.TextHeading); inventoryConsole.Print(1, 7, "Slot 2: " + Inventory.slot2, Colors.TextHeading); inventoryConsole.Print(1, 9, "Slot 3: " + Inventory.slot3, Colors.TextHeading); inventoryConsole.Print(1, 11, "Slot 4: " + Inventory.slot4, Colors.TextHeading); inventoryConsole.Print(1, 13, "Slot 5: " + Inventory.slot5, Colors.TextHeading); armourConsole.SetBackColor(0, 0, armourWidth, armourHeight, Palette.PrimaryDarker); armourConsole.Print(1, 1, "Armour", Colors.TextHeading); armourConsole.Print(1, 2, "______", Colors.TextHeading); armourConsole.Print(1, 5, "Head: " + Player.Head, Colors.TextHeading); armourConsole.Print(1, 7, "Neck: " + Player.Neck, Colors.TextHeading); armourConsole.Print(1, 9, "Chest: " + Player.Chest, Colors.TextHeading); armourConsole.Print(1, 11, "Legs: " + Player.Legs, Colors.TextHeading); armourConsole.Print(1, 13, "Gloves: " + Player.Gloves, Colors.TextHeading); armourConsole.Print(1, 15, "Boots: " + Player.Boots, Colors.TextHeading); armourConsole.Print(1, 21, "Weapon: " + Player.Weapon, Colors.TextHeading); armourConsole.Print(1, 23, "Shield: " + Player.Shield, Colors.TextHeading); //Instantiates a handler for RLNet's update event rootConsole.Update += OnRootConsoleUpdate; //Instantiates a handler for RLNet's render event rootConsole.Render += OnRootConsoleRender; //Begin the game loop rootConsole.Run(); }
public void DrawStats(RLConsole statConsole) { statConsole.Print(1, 1, $"Title: {Name}", Colors.Text); int healthWidth = Convert.ToInt32(((double)Health / (double)MaxHealth) * 16.0); int remainingHealthWidth = 16 - healthWidth; if (Status == "Poisoned") { statConsole.SetBackColor(1, 3, healthWidth, 1, RLColor.LightGreen); } else { statConsole.SetBackColor(1, 3, healthWidth, 1, RLColor.LightRed); } if (Status == "Poisoned") { statConsole.SetBackColor(1 + healthWidth, 3, remainingHealthWidth, 1, Colors.PoisonBacking); } else { statConsole.SetBackColor(1 + healthWidth, 3, remainingHealthWidth, 1, Colors.HPBacking); } if (Status == "Poisoned") { statConsole.Print(1, 3, $"HP: {Health}/{MaxHealth}", RLColor.Green); } else { statConsole.Print(1, 3, $"HP: {Health}/{MaxHealth}", RLColor.Red); } int manaWidth = Convert.ToInt32(((double)Mana / (double)MaxMana) * 16.0); int remainingManaWidth = 16 - manaWidth; statConsole.SetBackColor(1, 5, manaWidth, 1, RLColor.LightBlue); statConsole.SetBackColor(1 + manaWidth, 5, remainingManaWidth, 1, Colors.MPBacking); statConsole.Print(1, 5, $"MP: {Mana}/{MaxMana}", RLColor.Blue); statConsole.Print(1, 7, $"Attack: {Attack} ({AttackChance}%)", RLColor.LightRed); statConsole.Print(1, 9, $"Defense: {Defense} ({DefenseChance}%)", RLColor.LightBlue); statConsole.Print(1, 11, $"Level: {Level} ", RLColor.LightGreen); statConsole.Print(1, 13, $"To next: {Experience}", RLColor.LightGreen); if (Status == "Dead") { statConsole.Print(1, 15, $"Status: {Status}", Swatch.DbBlood); } else if (Status == "Poisoned") { statConsole.Print(1, 15, $"Status: {Status}", RLColor.Green); } else if (Status == "Stuck") { statConsole.Print(1, 15, $"Status: {Status}", Swatch.DbBlood); } else if (Status == "Starving") { statConsole.Print(1, 15, $"Status: {Status}", Swatch.DbBlood); } else if (Status == "Starving") { statConsole.Print(1, 15, $"Status: {Status}", Swatch.DbBlood); } else { statConsole.Print(1, 15, $"Status: {Status}", Colors.Gold); } statConsole.Print(1, 17, $"Gold: {Gold}", Colors.Gold); }
private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e) { bool didUnitAct = false; bool didPlayerAct = false; bool didMenuUpdate = false; RLKeyPress keyPress = _rootConsole.Keyboard.GetKeyPress(); if (_currentState == _gameStates.MainMenu) { _mapConsole.SetBackColor(0, 0, _mapWidth, _mapHeight, RLColor.Black); _mapConsole.Print(1, 1, "Press G to start a new game", Colors.TextHeading); renderRequired = true; if (keyPress != null) { if (keyPress.Key == RLKey.G) { _currentState = _gameStates.InGame; //on a state change we need to redraw the interface guiRedraw = true; } } //draw menu } else if (_currentState == _gameStates.InGame) { //handle player input when we're ingame if (CommandSystem.isPlayerTurn) { if (keyPress != null) { switch (keyPress.Key) { case RLKey.Up: didPlayerAct = CommandSystem.MovePlayer(Directions.Up); break; case RLKey.Down: didPlayerAct = CommandSystem.MovePlayer(Directions.Down); break; case RLKey.Left: didPlayerAct = CommandSystem.MovePlayer(Directions.Left); break; case RLKey.Right: didPlayerAct = CommandSystem.MovePlayer(Directions.Right); break; case RLKey.Escape: _rootConsole.Close(); break; } if (didPlayerAct) { renderRequired = true; mapRedraw = true; CommandSystem.EndPlayerTurn(); } } } else if (!CommandSystem.isPlayerTurn) { CommandSystem.ActivateMonsters(); renderRequired = true; } //draw gui if not drawn if (guiRedraw) { _mapConsole.Clear(); _mapConsole.SetBackColor(0, 0, _mapWidth, _mapHeight, Colors.FloorBackground); mapRedraw = true; _messageConsole.Clear(); _messageConsole.SetBackColor(0, 0, _messageWidth, _messageHeight, Swatch.DbDeepWater); _statConsole.Clear(); _statConsole.SetBackColor(0, 0, _statWidth, _statHeight, Swatch.DbOldStone); _inventoryConsole.Clear(); _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Swatch.DbWood); _inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading); renderRequired = true; guiRedraw = false; } if (mapRedraw) { MessageLog.Draw(_messageConsole); DungeonMap.Draw(_mapConsole, _statConsole); Player.Draw(_mapConsole, DungeonMap); Player.DrawStats(_statConsole); renderRequired = true; mapRedraw = false; } } }
public void Update(RLConsole console, RLConsole statsConsole) { var posBit = (int)Core.ComponentTypes.Position; var rendBit = (int)Core.ComponentTypes.Render; int statBit = (int)Core.ComponentTypes.Health; int detailsBit = (int)Core.ComponentTypes.CreatureDetails; int yPos = 16; int xPos = 2; Dictionary <int, int> ents = EntityManager.EntityBitLookUp; foreach (KeyValuePair <int, int> pair in ents) { int eid = pair.Key; int furnitureRes = (int)Core.ComponentTypes.Furniture & pair.Value; if (furnitureRes > 0) { Components.RenderComp rc = (Components.RenderComp)EntityManager.GetSingleComponentByID(eid, Core.ComponentTypes.Render); Components.PositionComp pc = (Components.PositionComp)EntityManager.GetSingleComponentByID(eid, Core.ComponentTypes.Position); console.Set(pc.X, pc.Y, rc.Colour, Core.Colours.FloorBackground, rc.Glyph); } } foreach (KeyValuePair <int, int> pair in ents) { int res = posBit & pair.Value; int res2 = rendBit & pair.Value; int actRes = (int)Core.ComponentTypes.Actor & pair.Value; char renderChar = 'X'; RLColor c = RLColor.White; List <Components.Component> comps = EntityManager.GetCompsByID(pair.Key); if ((res > 0 && res2 > 0) && (actRes == 0)) { Components.RenderComp rendComp = (Components.RenderComp)comps.Find(s => s.CompType == Core.ComponentTypes.Render); Components.PositionComp posComp = (Components.PositionComp)comps.Find(s => s.CompType == Core.ComponentTypes.Position); if (rendComp != null && posComp != null) { console.Set(posComp.X, posComp.Y, rendComp.Colour, Core.Colours.FloorBackground, rendComp.Glyph); } if (rendComp != null) { renderChar = rendComp.Glyph; c = rendComp.Colour; } } //draw stats } foreach (KeyValuePair <int, int> pair in ents) { // draw only actors on top if ((pair.Value & (int)Core.ComponentTypes.Actor) > 0) { List <Components.Component> comps = EntityManager.GetCompsByID(pair.Key); Components.RenderComp rendComp = (Components.RenderComp)comps.Find(s => s.CompType == Core.ComponentTypes.Render); Components.PositionComp posComp = (Components.PositionComp)comps.Find(s => s.CompType == Core.ComponentTypes.Position); Components.AIComp aiComp = (Components.AIComp)comps.Find(x => x.CompType == Core.ComponentTypes.AI); RLColor rColor; if (aiComp.Fleeing) { rColor = RLColor.Red; } else { rColor = rendComp.Colour; } if (rendComp != null && posComp != null) { console.Set(posComp.X, posComp.Y, rColor, Core.Colours.FloorBackground, rendComp.Glyph); } int res3 = statBit & pair.Value; if (res3 > 0) { Components.HealthComp healthStat = (Components.HealthComp)comps.Find(s => s.CompType == Core.ComponentTypes.Health); Components.CreatureDetailsComp detailsComp = (Components.CreatureDetailsComp)comps.Find(x => x.CompType == Core.ComponentTypes.CreatureDetails); Components.InventoryComp invComp = (Components.InventoryComp)comps.Find(x => x.CompType == Core.ComponentTypes.Inventory); if (healthStat != null && detailsComp != null) { statsConsole.Print(xPos, yPos, detailsComp.PersonalName + " the " + detailsComp.Name, rendComp.Colour); yPos++; statsConsole.Print(xPos, yPos, rendComp.Glyph.ToString(), rendComp.Colour); int width = Convert.ToInt32(((double)healthStat.Health / (double)healthStat.MaxHealth) * 16); int remainingWidth = 16 - width; statsConsole.SetBackColor(xPos + 2, yPos, width, 1, Core.Swatch.Primary); statsConsole.SetBackColor(xPos + 2 + width, yPos, remainingWidth, 1, Core.Swatch.PrimaryDarkest); statsConsole.Print(xPos + 2, yPos, $": {healthStat.Health.ToString()}", Core.Swatch.DbLight); yPos++; if (invComp != null) { statsConsole.Print(xPos, yPos, $"Carrying {invComp.Treasure.Count.ToString()} Gold", rendComp.Colour); } yPos = yPos + 2; } } } } // stats console int count = 0; for (int yp = 0; yp < EntityManager.GetHeight(); yp++) { for (int xp = 0; xp < EntityManager.GetWidth(); xp++) { if (EntityManager.Positions[yp, xp].Count > 0) { HashSet <int> ent = EntityManager.Positions[yp, xp]; foreach (int indvID in ent) { List <Components.Component> inner = EntityManager.Entities[indvID]; foreach (Components.Component ec in inner) { if (ec.CompType == Core.ComponentTypes.Collectable) { count++; } } } } } } statsConsole.Print(1, 1, $"collectables=: {count.ToString()}", Core.Colours.TextHeading); }
public void DrawArena(RLConsole console) { // Use RogueSharp to calculate the current field-of-view for the player var position = Floor.Player.TryGetPosition(); Floor.FloorMap.ComputeFov(position.X, position.Y, 50, true); foreach (var cell in Floor.FloorMap.GetAllCells()) { // When a Cell is in the field-of-view set it to a brighter color if (cell.IsInFov) { Floor.FloorMap.SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true); if (cell.IsWalkable) { console.Set(cell.X, cell.Y, RLColor.Gray, null, '.'); } else { console.Set(cell.X, cell.Y, RLColor.LightGray, null, '#'); } } // If the Cell is not in the field-of-view but has been explored set it darker else { if (cell.IsWalkable) { console.Set(cell.X, cell.Y, new RLColor(30, 30, 30), null, '.'); } else { console.Set(cell.X, cell.Y, RLColor.Gray, null, '#'); } } } // Draw enemies, alert + scan radii List <RogueSharp.Cell> alertCells = new List <RogueSharp.Cell>(); List <RogueSharp.Cell> scanCells = new List <RogueSharp.Cell>(); foreach (var e in Floor.InspectMapEntities().Where(e => e != Floor.Player)) { var entityPosition = e.TryGetPosition(); if (e.TryGetDestroyed()) { console.Set(entityPosition.X, entityPosition.Y, RLColor.Gray, null, 'D'); } else { console.Set(entityPosition.X, entityPosition.Y, RLColor.Red, null, 'E'); var componentAI = e.GetComponentOfType <Component_AI>(); if (componentAI != null) { var infoCells = componentAI.AlertCells(this.Floor); scanCells.AddRange(infoCells.ScanCells); alertCells.AddRange(infoCells.AlertCells); } } } foreach (var cell in scanCells) { console.SetBackColor(cell.X, cell.Y, RLColor.LightBlue); } foreach (var cell in alertCells) { console.SetBackColor(cell.X, cell.Y, RLColor.LightRed); } // Draw player console.Set(position.X, position.Y, RLColor.Green, null, '@'); // Highlight examined if (this.examineMenu.Examining) { var examinedPostion = this.examineMenu.ExaminedEntity.TryGetPosition(); console.SetBackColor(examinedPostion.X, examinedPostion.Y, RLColor.Yellow); } // Highlight targeting if (this.targetMenu.Targeting) { var playerPosition = Floor.Player.TryGetPosition(); // TODO: Artemis is crying var cellsInRange = Floor.CellsInRadius(playerPosition.X, playerPosition.Y, this.inventoryMenu.SelectedItem.GetComponentOfType <Component_Usable>().TargetRange); foreach (RogueSharp.Cell cell in cellsInRange) { if (cell.IsInFov && cell.IsWalkable) { console.SetBackColor(cell.X, cell.Y, RLColor.LightGreen); } } console.SetBackColor(this.targetMenu.X, this.targetMenu.Y, RLColor.Green); } // Draw commands foreach (var command in dungeon.ExecutedCommands) { if (command is GameEvent_PrepareAttack) { var cmd = (GameEvent_PrepareAttack)command; var attackerPos = cmd.CommandEntity.TryGetPosition(); var targetPos = cmd.Target.TryGetPosition(); var lineCells = this.Floor.FloorMap.GetCellsAlongLine(attackerPos.X, attackerPos.Y, targetPos.X, targetPos.Y); foreach (var cell in lineCells) { console.SetBackColor(cell.X, cell.Y, RLColor.LightRed); } } } dungeon.ClearExecutedCommands(); }
// Event handler for RLNET's Update event private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e) { bool didPlayerAct = false; RLKeyPress keyPress = _rootConsole.Keyboard.GetKeyPress(); if (CommandSystem.IsPlayerTurn) { 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(); } else if (keyPress.Key == RLKey.Period) { if (DungeonMap.CanMoveDownToNextLevel()) { MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 20, 13, 7, ++_mapLevel); DungeonMap = mapGenerator.CreateMap(); MessageLog = new MessageLog(); CommandSystem = new CommandSystem(); _rootConsole.Title = $"RougeSharp RLNet Tutorial - Level {_mapLevel}"; didPlayerAct = true; } } } if (didPlayerAct) { _renderRequired = true; CommandSystem.EndPlayerTurn(); } } else { CommandSystem.ActivateMonsters(); _renderRequired = true; } //Set background color andd text for our consoles //this is temporary, btw _mapConsole.SetBackColor(0, 0, _mapWidth, _mapHeight, Colors.FloorBackground); _mapConsole.Print(1, 1, "Map", Colors.TextHeading); _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Swatch.DbWood); _inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading); }
public static void Main() { //Setting the seed on base with the system time int seed = (int)DateTime.UtcNow.Ticks; Random = new DotNetRandom(seed); // This must be the exact name of the bitmap font file we are using or it will error. string fontFileName = "terminal8x8.png"; // The title will appear at the top of the console //Also include the seed code in the title string consoleTitle = $"RougeSharp V3 Tutorial - Level {_mapLevel} - Seed {seed}"; // Tell RLNet to use the bitmap font that we specified and that each tile is 8 x 8 pixels _rootConsole = new RLRootConsole(fontFileName, _screenWidth, _screenHeight, 8, 8, 1f, consoleTitle); //Enter name /*_rootConsole.Print(30, 35, "What's yer name, traveler?", RLColor.White); * PlayerName = Console.ReadLine(); * _rootConsole.Print(50, 35, PlayerName, RLColor.White);*/ // Create a new MessageLog and print the random seed used to generate the level MessageLog = new MessageLog(); MessageLog.Add("The rogue arrives on level 1"); MessageLog.Add($"Level created with seed '{seed}'"); //Initialize the sub consoles that we will Blit to the root console _mapConsole = new RLConsole(_mapWidth, _mapHeight); _messageConsole = new RLConsole(_messageWidth, _messageHeight); _statConsole = new RLConsole(_statWidth, _statHeight); _inventoryConsole = new RLConsole(_inventoryWidth, _inventoryHeight); //Instantiete a new Schedule system SchedulingSystem = new SchedulingSystem(); //Sets maps generator MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 20, 13, 7, _mapLevel); DungeonMap = mapGenerator.CreateMap(); //Updater field of view DungeonMap.UpdatePlayerFieldOfView(); //Command setting in main CommandSystem = new CommandSystem(); // Set up a handler for RLNET's Update event _rootConsole.Update += OnRootConsoleUpdate; // Set up a handler for RLNET's Render event _rootConsole.Render += OnRootConsoleRender; // Set background color and text for each console _messageConsole.SetBackColor(0, 0, _messageWidth, _messageHeight, Palette.DbDeepWater); _messageConsole.Print(1, 1, "Messages", Colors.TextHeading); _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Palette.DbWood); _inventoryConsole.Print(1, 1, "Inventory", Colors.TextHeading); // Begin RLNET's game loop _rootConsole.Run(); }
// Event handler for RLNET's Render event private static void OnRootConsoleRender(object sender, UpdateEventArgs e) { DateTime _currentTime = DateTime.Now; if (!_gameOver && _time.AddMilliseconds(160) < _currentTime) { _renderRequired = true; _nextAnimation = true; _time = _currentTime; } if (_renderRequired && !_gameOver) { _rootConsole.Clear(); _mapConsole.Clear(); _statConsole.Clear(); _messageConsole.Clear(); _inventoryConsole.Clear(); Point mapBlitOrigin = GetMapBlitOrigin(); _statConsole.SetBackColor(0, 0, _statWidth, _statHeight, Colors.Alternate); _messageConsole.SetBackColor(0, 0, _messageWidth, _messageHeight, Colors.Secondary); if (_mapLevel == 1) { _mapConsole.SetBackColor(mapBlitOrigin.X, mapBlitOrigin.Y, _onConsoleMapWidth, _onConsoleMapHeight, RLColor.Black); } else { for (int i = 0; i < _onConsoleMapHeight; i++) { _mapConsole.SetBackColor(mapBlitOrigin.X, mapBlitOrigin.Y + i, _onConsoleMapWidth, 1, RLColor.Blend(Colors.gradient1, Colors.gradient2, 1f - i / (_onConsoleMapHeight - 1f))); } } _inventoryConsole.SetBackColor(0, 0, _inventoryWidth, _inventoryHeight, Colors.Compliment); _inventoryConsole.Print(1, 1, "Inventaire", RLColor.White); Map.Draw(_mapConsole, _statConsole, _nextAnimation); Player.Draw(_mapConsole, Map, _nextAnimation); MessageLog.Draw(_messageConsole); Player.DrawStats(_statConsole); Inventory.DrawWithEffect(_inventoryConsole, _mapConsole); ICell cell = Map.GetCell(Player.X, Player.Y); Point mousePos = GetMousePosOnMap(); if (Map.IsInFov(mousePos.X, mousePos.Y) && Map.GetMonsterAt(mousePos.X, mousePos.Y) != null) { CellSelection.DrawPath(Player.Coord, mousePos, _mapConsole); _mapConsole.SetBackColor(mousePos.X, mousePos.Y, Colors.AlternateDarker); } _renderRequired = CellSelection.ShockWaveEffect(_mapConsole); _nextAnimation = false; if (Map is InvertedMap invertedMap) { _mapConsole = invertedMap.InvertMap(_mapConsole); mapBlitOrigin = new Point(_mapWidth - mapBlitOrigin.X - _onConsoleMapWidth, _mapHeight - mapBlitOrigin.Y - _onConsoleMapHeight); } // Blit the sub consoles to the root console in the correct locations RLConsole.Blit(_mapConsole, mapBlitOrigin.X, mapBlitOrigin.Y, _onConsoleMapWidth, _onConsoleMapHeight, _rootConsole, 0, _inventoryHeight); RLConsole.Blit(_statConsole, 0, 0, _statWidth, _statHeight, _rootConsole, _onConsoleMapWidth, 0); RLConsole.Blit(_messageConsole, 0, 0, _messageWidth, _messageHeight, _rootConsole, 0, _screenHeight - _messageHeight); RLConsole.Blit(_inventoryConsole, 0, 0, _inventoryWidth, _inventoryHeight, _rootConsole, 0, 0); // Tell RLNET to draw the console that we set _rootConsole.Draw(); } else if (_gameOver) { _UIConsole.Clear(); _UIConsole.SetBackColor(0, 0, _screenWidth, _screenHeight, Colors.ComplimentLighter); menu.Draw(_UIConsole, GetMousePos()); RLConsole.Blit(_UIConsole, 0, 0, _UIWidth, _UIHeight, _rootConsole, 0, 0); _rootConsole.Draw(); } }