public override bool ProcessKeyboard(SadConsole.Input.Keyboard info) { // Forward the keyboard data to the entity to handle the movement code. // We could detect if the users hit ESC and popup a menu or something. // By not setting the entity as the active object, twe let this // "game level" (the console we're hosting the entity on) determine if // the keyboard data should be sent to the entity. // Process logic for moving the entity. bool keyHit = false; var oldPosition = player.Position; if (info.IsKeyReleased(Keys.Up)) { player.Position = new Point(player.Position.X, player.Position.Y - 1); keyHit = true; } else if (info.IsKeyReleased(Keys.Down)) { player.Position = new Point(player.Position.X, player.Position.Y + 1); keyHit = true; } if (info.IsKeyReleased(Keys.Left)) { player.Position = new Point(player.Position.X - 1, player.Position.Y); keyHit = true; } else if (info.IsKeyReleased(Keys.Right)) { player.Position = new Point(player.Position.X + 1, player.Position.Y); keyHit = true; } if (keyHit) { // Check if the new position is valid if (textSurface.RenderArea.Contains(player.Position)) { // Entity moved. Let's draw a trail of where they moved from. SetGlyph(playerPreviousPosition.X, playerPreviousPosition.Y, 250); playerPreviousPosition = player.Position; return(true); } else // New position was not in the area of the console, move back { player.Position = oldPosition; } } // You could have multiple entities in the game for example, and change // which entity gets keyboard commands. return(false); }
public override bool ProcessKeyboard(SadConsole.Input.Keyboard info) { if (info.IsKeyDown(Keys.Left)) { ViewPort = new Rectangle(ViewPort.Left - 1, ViewPort.Top, 80, 23); } if (info.IsKeyDown(Keys.Right)) { ViewPort = new Rectangle(ViewPort.Left + 1, ViewPort.Top, 80, 23); } if (info.IsKeyDown(Keys.Up)) { ViewPort = new Rectangle(ViewPort.Left, ViewPort.Top - 1, 80, 23); } if (info.IsKeyDown(Keys.Down)) { ViewPort = new Rectangle(ViewPort.Left, ViewPort.Top + 1, 80, 23); } if (info.IsKeyReleased(Keys.Space)) { NextAnsi(); LoadAnsi(); } if (info.IsKeyReleased(Keys.L)) { if (writer == null || lineCounter == lines.Length) { NextAnsi(); lineCounter = 0; Clear(); lines = doc.AnsiString.Split('\n'); writer = new SadConsole.Ansi.AnsiWriter(doc, this); } writer.AnsiReadLine(lines[lineCounter], true); lineCounter++; if (lineCounter > lines.Length) { writer = null; } } return(true); }
public override bool ProcessKeyboard(SadConsole.Input.Keyboard info) { if (info.IsKeyReleased(Keys.P)) { if (PlayGame != null) { PlayGame(this, new EventArgs()); } return(true); } if (info.IsKeyReleased(Keys.I)) { PrintInstructions(); return(true); } return(false); }
private void ProcessMovement(Keyboard info) { if (info.IsKeyDown(Keys.Up)) { Player.Transform.Direction = Direction.Up; Player.IsMoving = true; } if (info.IsKeyDown(Keys.Right)) { Player.Transform.Direction = Direction.Right; Player.IsMoving = true; } if (info.IsKeyDown(Keys.Left)) { Player.Transform.Direction = Direction.Left; Player.IsMoving = true; } if (info.IsKeyDown(Keys.Down)) { Player.Transform.Direction = Direction.Down; Player.IsMoving = true; } if (info.IsKeyReleased(Keys.Up) && Player.Transform.Direction == Direction.Up) { Player.IsMoving = false; } if (info.IsKeyReleased(Keys.Left) && Player.Transform.Direction == Direction.Left) { Player.IsMoving = false; } if (info.IsKeyReleased(Keys.Right) && Player.Transform.Direction == Direction.Right) { Player.IsMoving = false; } if (info.IsKeyReleased(Keys.Down) && Player.Transform.Direction == Direction.Down) { Player.IsMoving = false; } if (info.IsKeyUp(Keys.Up) && info.IsKeyUp(Keys.Left) && info.IsKeyUp(Keys.Right) && info.IsKeyUp(Keys.Down)) { Player.IsMoving = false; } }
private bool ProcessKeyboardGameOver(SadConsole.Input.Keyboard info) { bool processedKeyboard = false; if (info.IsKeyReleased(Keys.Multiply)) { astrickKeyAnimation.Run(); CreateMenu(); processedKeyboard = true; } return(processedKeyboard); }
public override bool ProcessKeyboard(SadConsole.Input.Keyboard info) { if (info.KeysReleased.Count > 0) { if (releaseCount > 0) { releaseCount--; return(true); } if (playAgain == false) { Print(8, 24, "PLAY AGAIN (Y/N)? ", Color.White); playAgain = true; return(true); } if (info.IsKeyReleased(Keys.Y)) { if (RestartGame != null) { RestartGame(this, new EventArgs()); } return(true); } if (info.IsKeyReleased(Keys.N)) { if (QuitGame != null) { QuitGame(this, new EventArgs()); } return(true); } return(false); } else { return(false); } }
public override bool ProcessKeyboard(SadConsole.Input.Keyboard info) { if (info.IsKeyReleased(Keys.C)) { backIndex++; if (backIndex == backgroundcycle.Length) { backIndex = 0; } Library theme = Theme.Clone(); theme.Colors.ControlBack = backgroundcycle[backIndex]; theme.Colors.RebuildAppearances(); Theme = theme; } return(base.ProcessKeyboard(info)); }
public override bool ProcessKeyboard(SadConsole.Input.Keyboard info) { if (info.IsKeyReleased(Keys.C)) { backIndex++; if (backIndex == backgroundcycle.Length) { backIndex = 0; } var colors = (ThemeColors ?? Library.Default.Colors); colors.ControlBack = backgroundcycle[backIndex]; colors.RebuildAppearances(); //ThemeColors = colors; IsDirty = true; } return(base.ProcessKeyboard(info)); }
public bool ProcessKeyboard(SadConsole.Input.Keyboard info) { // Process logic for moving the entity. bool keyHit = false; if (info.IsKeyDown(Keys.Up)) { this.CurrentDirection = Direction.Up; keyHit = true; } else if (info.IsKeyDown(Keys.Down)) { this.CurrentDirection = Direction.Down; keyHit = true; } if (info.IsKeyDown(Keys.Left)) { this.CurrentDirection = Direction.Left; keyHit = true; } else if (info.IsKeyDown(Keys.Right)) { this.CurrentDirection = Direction.Right; keyHit = true; } switch (CurrentDirection) { case Direction.Up: if (info.IsKeyReleased(Keys.Up)) { this.CurrentDirection = Direction.None; keyHit = true; } break; case Direction.Down: if (info.IsKeyReleased(Keys.Down)) { this.CurrentDirection = Direction.None; keyHit = true; } break; case Direction.Left: if (info.IsKeyReleased(Keys.Left)) { this.CurrentDirection = Direction.None; keyHit = true; } break; case Direction.Right: if (info.IsKeyReleased(Keys.Right)) { this.CurrentDirection = Direction.None; keyHit = true; } break; } return(keyHit); }
public override bool ProcessKeyboard(Keyboard state) { if (state.IsKeyReleased(Keys.Enter)) { DoAction("play"); return(true); } if (state.IsKeyReleased(Keys.C)) { DoAction("create"); return(true); } if (state.IsKeyReleased(Keys.S)) { DoAction("send"); return(true); } if (state.IsKeyReleased(Keys.B)) { DoAction("bind"); return(true); } if (state.IsKeyReleased(Keys.W)) { DoAction("watch"); return(true); } if (state.IsKeyReleased(Keys.P)) { DoAction("play"); return(true); } if (state.IsKeyReleased(Keys.L)) { _controller.PrintMogwaiKeys(); LogInConsole("TASK", "loging public keys into a file."); return(true); } if (state.IsKeyReleased(Keys.T)) { _controller.Tag(); return(true); } if (state.IsKeyReleased(Keys.I)) { _transferFunds = (_transferFunds - 1) % 7 + 2; return(true); } if (state.IsKeyReleased(Keys.Down)) { _controller.Next(); return(true); } if (state.IsKeyReleased(Keys.Up)) { _controller.Previous(); return(true); } if (state.IsKeyReleased(Keys.Right)) { _borderSurface.SetGlyph(0, 0, ++_glyphIndex, Color.DarkCyan); _borderSurface.Print(10, 0, _glyphIndex.ToString(), Color.Yellow); return(true); } if (state.IsKeyReleased(Keys.Left)) { _borderSurface.SetGlyph(0, 0, --_glyphIndex, Color.DarkCyan); _borderSurface.Print(10, 0, _glyphIndex.ToString(), Color.Yellow); return(true); } return(false); }
public override bool ProcessKeyboard(Keyboard state) { if (state.IsKeyReleased(Keys.Enter)) { State = SadGuiState.Selection; return(true); } if (Program.DEBUG) { if (state.IsKeyReleased(Keys.Q)) { _glyphIndex++; Print(_glyphX, _glyphY, $"[c:sg {_glyphIndex}:1] ", Color.DarkCyan); Print(_glyphX + 2, _glyphY, $"{_glyphIndex}", Color.Yellow); return(true); } if (state.IsKeyReleased(Keys.A)) { _glyphIndex--; Print(_glyphX, _glyphY, $"[c:sg {_glyphIndex}:1] ", Color.DarkCyan); Print(_glyphX + 2, _glyphY, $"{_glyphIndex}", Color.Yellow); return(true); } if (state.IsKeyReleased(Keys.Right)) { Print(_glyphX, _glyphY, $"[c:sg {_oldglyphIndex}:1] ", Color.DarkCyan); _glyphX++; _oldglyphIndex = GetGlyph(_glyphX, _glyphY); Print(_glyphX, _glyphY, $"[c:sg {_glyphIndex}:1] ", Color.DarkCyan); return(true); } if (state.IsKeyReleased(Keys.Left)) { Print(_glyphX, _glyphY, $"[c:sg {_oldglyphIndex}:1] ", Color.DarkCyan); _glyphX--; _oldglyphIndex = GetGlyph(_glyphX, _glyphY); Print(_glyphX, _glyphY, $"[c:sg {_glyphIndex}:1] ", Color.DarkCyan); return(true); } if (state.IsKeyReleased(Keys.Up)) { Print(_glyphX, _glyphY, $"[c:sg {_oldglyphIndex}:1] ", Color.DarkCyan); _glyphY--; _oldglyphIndex = GetGlyph(_glyphX, _glyphY); Print(_glyphX, _glyphY, $"[c:sg {_glyphIndex}:1] ", Color.DarkCyan); return(true); } if (state.IsKeyReleased(Keys.Down)) { Print(_glyphX, _glyphY, $"[c:sg {_oldglyphIndex}:1] ", Color.DarkCyan); _glyphY++; _oldglyphIndex = GetGlyph(_glyphX, _glyphY); Print(_glyphX, _glyphY, $"[c:sg {_glyphIndex}:1] ", Color.DarkCyan); return(true); } Print(0, 0, $"x:{_glyphX} y:{_glyphY} ind:{_glyphIndex}", Color.Cyan); } return(false); }