public static void DrawSeparator(this SadConsole.Console console, int y, string corner, Color c) { StringBuilder separator = new StringBuilder(); separator.Append(corner); for (int i = 1; i < console.Width - 1; i++) { separator.Append("-"); } separator.Append(corner); console.Print(0, y, separator.ToString(), c); }
public static void RenderMap(Player player, SadConsole.Console console, Window window) { Point worldIndex = player.WorldIndex; Point startPoint = window.CalculateMapStartPoint(); for (int i = startPoint.X; i - startPoint.X < GUI.MapWidth; i++) { for (int j = startPoint.Y; j - startPoint.Y < window.Height; j++) { Program.WorldMap[worldIndex.X, worldIndex.Y].DrawCell(i, j, player, console, window); } } }
protected virtual void RenderEnd(SadConsole.Console surface, bool force = false) { if (surface.IsDirty || force) { AfterRenderCallback?.Invoke(Global.SpriteBatch); Global.SpriteBatch.End(); surface.IsDirty = false; Global.GraphicsDevice.SetRenderTarget(null); } }
public static bool TryWorldToConsole(World world, out Console console) { console = null; if (world != null) { console = new Console(world.Width, world.Height); Drawing.DrawWorldOnConsole(console, world); } return(console != null); }
public override void ProcessMouse(SadConsole.Console console, MouseConsoleState state, out bool handled) { if (state.Mouse.IsOnScreen) { console.Print(0, 0, "cellposition X : " + state.CellPosition.X + " ; Y : " + state.CellPosition.Y); //console.SetBackground(state.CellPosition.X, state.CellPosition.Y, Color.HotPink); var child = console.Children[0]; child.Position = state.CellPosition; //console.Clear(); } handled = false; }
public override void Draw(Console console, TimeSpan delta) { for (int y = 0; y < game.Map.Length; y++) { for (int x = 0; x < game.Map[y].Length; x++) { { console.Print(x + 1, y + 1, game.Map[y][x].ToString()); } } } console.Print((int)game.Player.Position.Y + 1, (int)game.Player.Position.X + 1, "P"); }
/// <summary> /// Renders a surface to the screen. /// </summary> /// <param name="surface">The surface to render.</param> /// <param name="force">When <see langword="true"/> draws the surface even if <see cref="CellSurface.IsDirty"/> is <see langword="false"/>.</param> public override void Render(SadConsole.Console surface, bool force = false) { RenderBegin(surface, force); RenderCells(surface, force); foreach (var control in Controls) { RenderControlCells(control, surface.IsDirty || force); } //RenderControls(surface, force); RenderTint(surface, force); RenderEnd(surface, force); }
public void ShowLevelUpMenu(Console console, string header, Entity player, int width, int screenWidth, int screenHeight) { if (_levelUpMenu == null) { var options = new List <string> { $"Constitution (+20 HP, from {player.Get<FighterComponent>().MaxHp})", $"Strength (+1 attack, from {player.Get<FighterComponent>().Power})", $"Agility (+1 defense, from {player.Get<FighterComponent>().Defense})" }; _levelUpMenu = ShowMenu(console, header, options, width, screenWidth, screenHeight, Color.DarkGreen); } }
/// <summary> /// Executes the instruction. This base class method should be called from derived classes. If the IsFinished property is set to true, will try to repeat if needed and will raise all appropriate events. /// </summary> public override void Update(SadConsole.Console console, TimeSpan delta) { if (IsFinished) { if (RepeatCount > 0 || RepeatCount == -1) { Repeat(); } else { OnFinished(console); } } }
public void Draw(SadConsole.Console console) { console.Print(2, 2, "[D] Review data cubes", Palette.White); console.Print(2, 3, "[O] Options", Palette.White); console.Print(2, 4, "[S] Save game", Palette.White); if (this.justSaved) { console.Print(2, 6, "Game saved!", Palette.Blue); } console.Print(2, console.Height - 4, "[ESC] Back to game", Palette.White); console.Print(2, console.Height - 3, "[Q] Quit", Palette.White); }
private void PrintOption(SadConsole.Console target, int x, int y, string caption, bool isEnabled, string onLabel, string offLabel) { target.Print(x, y, caption, Palette.Blue); if (isEnabled) { target.Print(x + caption.Length + 1, y, $"[{onLabel}]", EnabledColour); target.Print(x + caption.Length + onLabel.Length + 4, y, offLabel, DisabledColour); } else { target.Print(x + caption.Length + 1, y, onLabel, DisabledColour); target.Print(x + caption.Length + onLabel.Length + 2, y, $"[{offLabel}]", EnabledColour); } }
public object Load(string file) { string[] text = System.IO.File.ReadAllLines(file); int maxLineWidth = text.Max(s => s.Length); SadConsole.Console importConsole = new SadConsole.Console(maxLineWidth, text.Length); importConsole.VirtualCursor.AutomaticallyShiftRowsUp = false; foreach (var line in text) { importConsole.VirtualCursor.Print(line); } return(importConsole.TextSurface); }
private void ShowCubesList(SadConsole.Console console) { // Print data cubes in order of floor acquired, so the user sees any gaps. // Because of padding/border, print floor Bn on (x, y=n). var cubesByFloor = new Dictionary <int, DataCube>(); for (var floor = DataCube.FirstDataCubeFloor; floor < DataCube.FirstDataCubeFloor + DataCube.NumCubes; floor++) { var cube = player.DataCubes.SingleOrDefault(d => d.FloorNumber == floor); if (cube != null) { console.Print(2, floor + 1, $"[{cube.FloorNumber}] {cube.Title}", Palette.White); } } }
public void ShowWinScreen() { Timer aTimer; aTimer = new System.Timers.Timer(3000); aTimer.Elapsed += ResetGame; aTimer.AutoReset = false; aTimer.Enabled = true; GameLoop.UIManager.MapWindow.Hide(); win.PositionOffset = new Point(1, 1); win.PositionMode = UI.DrawImageComponent.PositionModes.Pixels; GameOverScreen = new Console(GameLoop.GameWidth, GameLoop.GameHeight); GameOverScreen.Components.Add(win); SadConsole.Global.CurrentScreen = GameOverScreen; }
public void Draw(Console mapConsole, IMap map) { if (!map.GetCell(X, Y).IsExplored) { return; } if (map.IsInFov(X, Y)) { //mapConsole.CellData.SetCharacter(X, Y, Symbol, Color, Colors.FloorBackgroundFov); } else { //mapConsole.CellData.SetCharacter(X, Y, '.', Colors.Floor, Colors.FloorBackground); } }
public void Draw(Console console, IMap map) { if (!map.IsExplored(X, Y)) { return; } if (map.IsInFov(X, Y)) { //console.CellData.SetCharacter(X, Y, Symbol, Color, Colors.FloorBackgroundFov); } else { //console.CellData.SetCharacter(X, Y, Symbol, Color.Multiply(Color.Gray, 0.5f), Colors.FloorBackground); } }
private static void OnInitialize() { var console = new SadConsole.Console(80, 25); console.FillWithRandomGarbage(); _ = console.Fill(new Rectangle(3, 3, 23, 3), Color.Violet, Color.Black, 0, 0); console.Print(4, 4, "Hello world!"); console.IsFocused = true; console.Cursor.IsVisible = true; // Add the custom keyboard handler. console.Components.Add(new MyKeyboardComponent()); // Focus the screen to the default console. SadConsole.Global.CurrentScreen = console; }
public void Render() { Console.Clear(); if (lines.Count == 0 || curDisplayedLines == 0) { return; } if (DateTime.Now - lines[lines.Count - curDisplayedLines].WriteTime > msgTime) { curDisplayedLines--; } for (int i = 0; i < curDisplayedLines; i++) { Program.Window.PrintMessage(i, lines[lines.Count - (curDisplayedLines - i)].Text, GUI.MapWidth - 1, lines[lines.Count - 1 - i].Color); } }
// TODO - queue multiple "simultaneous" inputs registered public override void ProcessKeyboard(Console console, Keyboard info, out bool handled) { handled = false; // check for movements if (info.IsKeyPressed(Keys.Left)) { master.MovePlayer(Direction.Left, info.IsKeyDown(Keys.LeftShift) || info.IsKeyDown(Keys.RightShift)); handled = true; } else if (info.IsKeyPressed(Keys.Right)) { master.MovePlayer(Direction.Right, info.IsKeyDown(Keys.LeftShift) || info.IsKeyDown(Keys.RightShift)); handled = true; } else if (info.IsKeyPressed(Keys.Up)) { master.MovePlayer(Direction.Up, info.IsKeyDown(Keys.LeftShift) || info.IsKeyDown(Keys.RightShift)); handled = true; } else if (info.IsKeyPressed(Keys.Down)) { master.MovePlayer(Direction.Down, info.IsKeyDown(Keys.LeftShift) || info.IsKeyDown(Keys.RightShift)); handled = true; } else if (info.IsKeyPressed(Keys.Space)) { switch (master.controlType) { case ControlType.DrivingWagon: master.controlType = ControlType.OnFoot; master.bigMobs.Add(master.wagon); break; case ControlType.OnFoot: master.controlType = ControlType.DrivingWagon; master.bigMobs.Remove(master.wagon); break; } handled = true; } if (handled) { master.DrawMap(); } }
public void Draw(Console console, IMap map) { if (!map.GetCell(X, Y).IsExplored) { return; } if (map.IsInFov(X, Y)) { if (IsUp) { //console.CellData.SetCharacter(X, Y, '<', Colors.Player); int tilePos = Y * GameLoop.World.CurrentMap.Width + X; GameLoop.World.CurrentMap.Tiles[tilePos].Glyph = '<'; GameLoop.World.CurrentMap.Tiles[tilePos].Foreground = Colors.Player; } else { //console.CellData.SetCharacter(X, Y, '>', Colors.Player); int tilePos = Y * GameLoop.World.CurrentMap.Width + X; GameLoop.World.CurrentMap.Tiles[tilePos].Glyph = '>'; GameLoop.World.CurrentMap.Tiles[tilePos].Foreground = Colors.Player; } } else { if (IsUp) { //console.CellData.SetCharacter(X, Y, '<', Colors.Floor); int tilePos = Y * GameLoop.World.CurrentMap.Width + X; GameLoop.World.CurrentMap.Tiles[tilePos].Glyph = '<'; GameLoop.World.CurrentMap.Tiles[tilePos].Foreground = Colors.Floor; } else { //console.CellData.SetCharacter(X, Y, '>', Colors.Floor); int tilePos = Y * GameLoop.World.CurrentMap.Width + X; GameLoop.World.CurrentMap.Tiles[tilePos].Glyph = '>'; GameLoop.World.CurrentMap.Tiles[tilePos].Foreground = Colors.Floor; } } }
public override void ProcessKeyboard(Console console, Keyboard info, out bool handled) { game.Keys.ForwardPressed = info.IsKeyDown(Keys.W); game.Keys.BackwardPressed = info.IsKeyDown(Keys.S); game.Keys.LeftPressed = info.IsKeyDown(Keys.A); game.Keys.RightPressed = info.IsKeyDown(Keys.D); game.Keys.StrafeLeftPressed = info.IsKeyDown(Keys.Q); game.Keys.StrafeRightPressed = info.IsKeyDown(Keys.E); if (info.IsKeyDown(Keys.Space)) { console.Print(1, 1, "SPACE"); } handled = true; }
private void InitDisplay() { // init display style for (int x = 1; x < windowWidth - 1; x++) { borders[Coord.Get(x, 0)] = '─'; borders[Coord.Get(x, windowHeight - 1)] = '─'; borders[Coord.Get(x, windowHeight - 1 - statusHeight - 1)] = '─'; borders[Coord.Get(x, windowHeight - 1 - statusHeight - 1 - logHeight - 1)] = '─'; } for (int y = 1; y < windowHeight - 1; y++) { borders[Coord.Get(0, y)] = '│'; borders[Coord.Get(windowWidth - 1, y)] = '│'; } borders[Coord.Get(0, 0)] = '┌'; borders[Coord.Get(windowWidth - 1, 0)] = '┐'; borders[Coord.Get(0, windowHeight - 1)] = '└'; borders[Coord.Get(windowWidth - 1, windowHeight - 1)] = '┘'; borders[Coord.Get(0, windowHeight - 1 - statusHeight - 1)] = '├'; borders[Coord.Get(0, windowHeight - 1 - statusHeight - 1 - logHeight - 1)] = '├'; borders[Coord.Get(windowWidth - 1, windowHeight - 1 - statusHeight - 1)] = '┤'; borders[Coord.Get(windowWidth - 1, windowHeight - 1 - statusHeight - 1 - logHeight - 1)] = '┤'; log = new string[logHeight]; for (int i = 0; i < log.Length; i++) { log[i] = ""; } // Setup terminal SadConsole.Game.Create(windowWidth, windowHeight); SadConsole.Game.OnInitialize = () => { console = new Console(windowWidth, windowHeight); console.IsFocused = true; console.Cursor.IsEnabled = false; console.Components.Add(new SadKeyboardController(this)); SadConsole.Global.CurrentScreen = console; DrawMap(); Message("Welcome to Rogue Delivery!"); Message("Arrow keys to move, space to jump in and out of wagon."); Message("Hold shift when moving to slide instead of turn."); }; }
public override void ProcessKeyboard(SadConsole.Console console, Keyboard info, out bool handled) { if (info.IsKeyReleased(Microsoft.Xna.Framework.Input.Keys.Escape)) { Environment.Exit(0); } if (info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Space)) { var cursorPos = console.Cursor.Position; console.SetGlyph(cursorPos.X, cursorPos.Y + 1, 1, Color.Aquamarine); console.SetGlyph(cursorPos.X, cursorPos.Y - 1, 3); console.SetGlyph(cursorPos.X, cursorPos.Y, 5); //console.DefaultBackground = Color.White.GetRandomColor(SadConsole.Global.Random); //console.Clear(); } handled = false; }
private void ShowSelectedCube(SadConsole.Console console) { console.Print(2, 2, cubeShown.Title, Palette.LightRed); var lastY = this.PrettyPrint(console, 2, 4, cubeShown.Text, Palette.OffWhite); if (cubeShown.FloorNumber == 1) { lastY = this.PrettyPrint(console, 2, lastY + 2, "Our engineers outfitted you with a prototype combat shield that recharges instantly, but it needs space to work - any nearby entities will prevent it from recharging.", Palette.OffWhite); var signature = "-The Khalifa"; console.Print(console.Width - 2 - signature.Length, lastY + 2, signature, Palette.OffWhite); } else if (cubeShown == DataCube.EndGameCube) { console.Print(2, lastY + 2, "Congratulations on completing the game!", Palette.White); console.Print(2, lastY + 4, "Thanks for playing! If you have any feedback,", Palette.Blue); console.Print(2, lastY + 5, "please send it to @nightblade99 on Twitter!", Palette.Blue); } }
public static Scene Load(string file, Console baseConsole = null, params Type[] types) { var scene = SadConsole.Serializer.Load <Scene>(file, types); if (baseConsole == null) { scene.baseConsole = new Console(scene.backgroundSurface) { Renderer = new Renderers.LayeredSurfaceRenderer() } } ; else { scene.baseConsole = baseConsole; } return(scene); }
public void Draw(SadConsole.Console console) { if (this.cubeShown == null) { this.ShowCubesList(console); } else { this.ShowSelectedCube(console); } if (cubeShown != DataCube.EndGameCube) { console.Print(2, console.Height - 4, $"[{Options.KeyBindings[GameAction.OpenMenu]}] Go back", Palette.White); } else { console.Print(2, console.Height - 4, $"[{Options.KeyBindings[GameAction.OpenMenu]}] Quit to title", Palette.White); } }
public void Draw(Console mapConsole, Console statConsole, Console inventoryConsole) { //mapConsole.Clear(); foreach (Cell cell in GetAllCells()) { SetConsoleSymbolForCell(mapConsole, cell); } foreach (Door door in Doors) { door.Draw(mapConsole, this); } StairsUp.Draw(mapConsole, this); StairsDown.Draw(mapConsole, this); foreach (TreasurePile treasurePile in _treasurePiles) { IDrawable drawableTreasure = treasurePile.Treasure as IDrawable; drawableTreasure?.Draw(mapConsole, this); } //statConsole.Clear(); int i = 0; foreach (Monster monster in _monsters) { monster.Draw(mapConsole, this); if (IsInFov(monster.X, monster.Y)) { //monster.DrawStats(statConsole, i); i++; } } Player player = GameLoop.World.Player; player.Draw(mapConsole, this); //player.DrawStats(statConsole); //player.DrawInventory(inventoryConsole); }
private static void Init() { // Any custom loading and prep. We will use a sample console for now _console = new SadConsole.Console(Width, Height); _board = new GameBoard(Width, Height); var random = new Random(); for (var i = 0; i < Width; i++) { for (var j = 0; j < Height; j++) { _board.Board[i, j] = random.Next(2) == 1; } } PrintBoard(); // Set our new console as the thing to render and process SadConsole.Global.CurrentScreen = _console; }
public CoreGameConsole(int width, int height, Dungeon dungeon) : base(width, height) { var fontMaster = SadConsole.Global.LoadFont("Fonts/AliTheAndroid.font"); var normalSizedFont = fontMaster.GetFont(SadConsole.Font.FontSizes.Two); this.Font = normalSizedFont; this.ScreenTilesWidth = (int)Math.Floor(1.0f * ScreenWidth / normalSizedFont.Size.X); this.ScreenTilesHeight = (int)Math.Floor(1.0f * ScreenHeight / normalSizedFont.Size.Y); this.backBuffer = new SadConsole.Console(width, height); this.dungeon = dungeon; this.messageConsole = new SadConsole.Console(this.Width, 2); this.messageConsole.Position = new Point(0, this.Height - this.messageConsole.Height); this.Children.Add(this.messageConsole); EventBus.Instance.AddListener(GameEvent.ShowSubMenu, (obj) => { if (this.subMenuConsole == null) { this.subMenuConsole = new InGameSubMenuConsole(this.dungeon.CurrentFloor.Player); this.subMenuConsole.Position = new Point((Width - this.subMenuConsole.Width) / 2, (Height - this.subMenuConsole.Height) / 2); this.Children.Add(this.subMenuConsole); } }); EventBus.Instance.AddListener(GameEvent.HideSubMenu, (data) => { if (this.subMenuConsole != null) { this.Children.Remove(this.subMenuConsole); this.subMenuConsole = null; InGameSubMenuConsole.IsOpen = false; } }); // Fix: starting the game shows one frame of everything filled with the stairs/portal character this.Fill(Color.Black, Color.Black, ' '); }
protected virtual void RenderCells(SadConsole.Console surface, bool force = false) { if (surface.IsDirty || force) { if (surface.Tint.A != 255) { if (surface.DefaultBackground.A != 0) { Global.SpriteBatch.Draw(surface.Font.FontImage, new Rectangle(0, 0, surface.AbsoluteArea.Width, surface.AbsoluteArea.Height), surface.Font.GlyphRects[surface.Font.SolidGlyphIndex], surface.DefaultBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.2f); } for (int i = 0; i < surface.RenderCells.Length; i++) { ref Cell cell = ref surface.RenderCells[i]; if (!cell.IsVisible) { continue; } if (cell.Background != Color.Transparent && cell.Background != surface.DefaultBackground) { Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[surface.Font.SolidGlyphIndex], cell.Background, 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.Foreground != Color.Transparent) { Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[cell.Glyph], cell.Foreground, 0f, Vector2.Zero, cell.Mirror, 0.4f); } foreach (CellDecorator decorator in cell.Decorators) { if (decorator.Color != Color.Transparent) { Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[decorator.Glyph], decorator.Color, 0f, Vector2.Zero, decorator.Mirror, 0.5f); } } } } }