Example #1
0
 public override void ProcessKeyboard(Keyboard info)
 {
     if (info.IsKeyPressed(Keys.Space) || info.IsKeyPressed(Keys.Enter))
     {
         Finished = true;
     }
 }
Example #2
0
        private bool ProcessKeyboardRunning(SadConsole.Input.Keyboard info)
        {
            bool processedKeyboard = false;

            if (player.ProcessKeyboard(info))
            {
                processedKeyboard = true;
                if (info.IsKeyDown(Keys.Up))
                {
                    upKeyAnimation.Run();
                }
                else if (info.IsKeyDown(Keys.Down))
                {
                    downKeyAnimation.Run();
                }
                else if (info.IsKeyDown(Keys.Left))
                {
                    leftKeyAnimation.Run();
                }
                else if (info.IsKeyDown(Keys.Right))
                {
                    rightKeyAnimation.Run();
                }
            }

            return(processedKeyboard);
        }
Example #3
0
        public bool ProcessMovement(SadConsole.Input.Keyboard info)
        {
            Direction moveDirection = Direction.NONE;

            // Simplified way to check if any key we care about is pressed and set movement direction.
            foreach (Keys key in s_movementDirectionMapping.Keys)
            {
                if (info.IsKeyPressed(key))
                {
                    moveDirection = s_movementDirectionMapping[key];
                    break;
                }
            }

            var moved = MoveTowards(moveDirection);

            if (moved)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        public override bool ProcessKeyboard(Keyboard info)
        {
            if (info.IsKeyPressed(Keys.Escape))
            {
                Screen.MenuConsole.OpenMainMenu();
            }

            ProcessMovement(info);

            ProcessAttack(info);

            if (info.IsKeyPressed(Keys.E))
            {
                var entity = Entities.FirstOrDefault(e => e.Transform.Position ==
                                                     Player.Transform.Position +
                                                     Player.Transform.Direction
                                                     .AsPoint()) as IInteractable;
                entity?.Interact();
            }
            if (info.IsKeyPressed(Keys.T))
            {
                var entity = Entities.FirstOrDefault(e => e.Transform.Position ==
                                                     Player.Transform.Position +
                                                     Player.Transform.Direction.AsPoint()) as Openable;
                entity?.TryToUnlock();
            }

            return(true);
        }
        public override void ProcessKeyboard(SadConsole.Console consoleObject, SadConsole.Input.Keyboard info, out bool handled)
        {
            // Upcast this because we know we're only using it with a Console type.
            var console = (ScrollingConsole)consoleObject;

            if (info.IsKeyDown(Keys.Left))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left - 1, console.ViewPort.Top, _originalWidth, _originalHeight);
            }

            if (info.IsKeyDown(Keys.Right))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left + 1, console.ViewPort.Top, _originalWidth, _originalHeight);
            }

            if (info.IsKeyDown(Keys.Up))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left, console.ViewPort.Top - 1, _originalWidth, _originalHeight);
            }

            if (info.IsKeyDown(Keys.Down))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left, console.ViewPort.Top + 1, _originalWidth, _originalHeight);
            }

            handled = true;
        }
Example #6
0
        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);
        }
Example #7
0
        public override void ProcessKeyboard(Console console, SadConsole.Input.Keyboard info, out bool handled)
        {
            if (info.IsKeyPressed(Keys.Space))
            {
                console.DefaultBackground = Color.White.GetRandomColor(Global.Random);
                console.Clear();
            }

            handled = true;
        }
Example #8
0
 private void ProcessAttack(Keyboard info)
 {
     if (info.IsKeyDown(Keys.Space))
     {
         Player.IsAttacking = true;
     }
     else
     {
         Player.IsAttacking = false;
     }
 }
Example #9
0
        private bool ProcessKeyboardGameOver(SadConsole.Input.Keyboard info)
        {
            bool processedKeyboard = false;

            if (info.IsKeyReleased(Keys.Multiply))
            {
                astrickKeyAnimation.Run();
                CreateMenu();
                processedKeyboard = true;
            }
            return(processedKeyboard);
        }
Example #10
0
        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);
        }
Example #11
0
        public override void ProcessKeyboard(Keyboard info)
        {
            base.ProcessKeyboard(info);

            if (info.IsKeyPressed(Keys.Enter) || info.IsKeyPressed(Keys.Space))
            {
                Result   = Answers[PointerIndex].Item1;
                Finished = true;
            }

            if (info.IsKeyPressed(Keys.Escape) && DefaultAnswer != null)
            {
                Result   = DefaultAnswer;
                Finished = true;
            }
        }
Example #12
0
 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);
 }
        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;
        }
Example #14
0
        private bool ProcessMovement(SadConsole.Input.Keyboard info)
        {
            Direction moveDirection = Direction.NONE;

            // Simplified way to check if any key we care about is pressed and set movement direction.
            foreach (var key in _movementDirectionMapping.Keys)
            {
                if (info.IsKeyPressed(key))
                {
                    moveDirection = _movementDirectionMapping[key];
                    break;
                }
            }

            Position += moveDirection;
            return(moveDirection != Direction.NONE);
        }
Example #15
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            switch (gameState)
            {
            case GameState.MenuScreen:
                return(ProcessKeyboardMenu(info));

            case GameState.Running:
                return(ProcessKeyboardRunning(info));

            case GameState.GameOver:
                return(ProcessKeyboardGameOver(info));

            default:
                return(false);
            }
        }
Example #16
0
        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;
            }
        }
        public override void ProcessKeyboard(SadConsole.Console consoleObject, SadConsole.Input.Keyboard info, out bool handled)
        {
            // Upcast this because we know we're only using it with a Console type.
            var console = (InputConsole)consoleObject;

            // Check each key pressed.
            foreach (var key in info.KeysPressed)
            {
                // If the character associated with the key pressed is a printable character, print it
                if (key.Character != '\0')
                {
                    currentInput = currentInput + key.Character.ToString();
                }

                // Special character - BACKSPACE
                else if (key.Key == Keys.Back)
                {
                    if (currentInput.Length <= 0)
                    {
                        continue;
                    }

                    currentInput = currentInput.Substring(0, currentInput.Length - 1);
                }

                // Special character - ENTER
                else if (key.Key == Keys.Enter)
                {
                    EnterPressedAction(currentInput);
                    currentInput = "";
                    console.Cursor.NewLine();
                }
            }

            console.Cursor.DisableWordBreak = true;
            console.Cursor.CarriageReturn();
            console.Cursor.Print("                                                                ");
            console.Cursor.CarriageReturn();
            console.Cursor.Print(console.Prompt + " " + currentInput);
            console.Cursor.DisableWordBreak = false;

            handled = true;
        }
Example #18
0
 protected void MovePointer(Keyboard info)
 {
     if (info.IsKeyPressed(Keys.Left))
     {
         PointerIndex -= Rows;
     }
     else if (info.IsKeyPressed(Keys.Right))
     {
         PointerIndex += Rows;
     }
     else if (info.IsKeyPressed(Keys.Down))
     {
         PointerIndex += 1;
     }
     else if (info.IsKeyPressed(Keys.Up))
     {
         PointerIndex -= 1;
     }
 }
Example #19
0
        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));
        }
Example #20
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
#if DEBUG
            if (info.IsKeyPressed(Keys.F4))
            {
                if (CurrentMap is ExampleMap exampleMap)
                {
                    exampleMap.FovVisibilityHandler.ToggleState();
                    return(true);
                }
            }
#endif

            if (ProcessMovement(info))
            {
                return(true);
            }

            return(base.ProcessKeyboard(info));
        }
Example #21
0
        public bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            // Process logic for moving the entity.
            bool keyHit = false;

            if (info.IsKeyDown(Keys.Up))
            {
                if (CurrentDirection != Direction.Down)
                {
                    this.CurrentDirection = Direction.Up;
                }
                keyHit = true;
            }
            else if (info.IsKeyDown(Keys.Down))
            {
                if (CurrentDirection != Direction.Up)
                {
                    this.CurrentDirection = Direction.Down;
                }
                keyHit = true;
            }

            if (info.IsKeyDown(Keys.Left))
            {
                if (CurrentDirection != Direction.Right)
                {
                    this.CurrentDirection = Direction.Left;
                }
                keyHit = true;
            }
            else if (info.IsKeyDown(Keys.Right))
            {
                if (CurrentDirection != Direction.Left)
                {
                    this.CurrentDirection = Direction.Right;
                }
                keyHit = true;
            }

            return(keyHit);
        }
Example #22
0
        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));
        }
Example #23
0
        public override bool ProcessKeyboard(Keyboard info)
        {
            Direction moveDirection = Direction.NONE;

            // Simplified way to check if any key we care about is pressed and set movement direction.
            foreach (Keys key in s_movementDirectionMapping.Keys)
            {
                if (info.IsKeyPressed(key))
                {
                    moveDirection = s_movementDirectionMapping[key];
                    break;
                }
            }

            if (moveDirection != Direction.NONE)
            {
                Game.InputManager.MovePlayer(this, moveDirection);
            }

            return(base.ProcessKeyboard(info));
        }
Example #24
0
 public override bool ProcessKeyboard(Keyboard info)
 {
     if (wait)
     {
         CurrentMessage.ProcessKeyboard(info);
         if (CurrentMessage.Finished)
         {
             if (CurrentMessage.NonBlocking)
             {
                 Blocking = true;
             }
             CurrentMessage.OnPostProcessing();
             wait = false;
             if (MessageQueue.Count > 0)
             {
                 var nextMessage = MessageQueue.Dequeue();
                 //skip SimpleMessages to the last
                 while (nextMessage.Finished && MessageQueue.Count > 0 && MessageQueue.Peek().Finished)
                 {
                     nextMessage = MessageQueue.Dequeue();
                 }
                 PrintMessageAndWait(nextMessage);
             }
             else
             {
                 if (ClearInactive && CurrentMessage.GetType() != typeof(SimpleMessage))
                 {
                     ConsoleObjects.Clear();
                 }
                 else
                 {
                     ConsoleObjects.Remove(CurrentMessage.WaitPointer);
                 }
                 this.IsActive = false;
             }
         }
     }
     return(Blocking);
 }
Example #25
0
        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);
            }
        }
Example #26
0
 public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
 {
     if (gameOver == false)
     {
         if (player.ProcessKeyboard(info))
         {
             return(true);
         }
         else
         {
             base.ProcessKeyboard(info);
         }
         return(false);
     }
     else
     {
         if (info.KeysReleased.Count > 0)
         {
             if (firstRelease)
             {
                 firstRelease = false;
                 return(true);
             }
             else
             {
                 if (StopGamePlay != null)
                 {
                     StopGamePlay(this, new EventArgs());
                 }
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Example #27
0
 public override void ProcessKeyboard(Keyboard info)
 {
     base.ProcessKeyboard(info);
     if (info.IsKeyPressed(Keys.Enter) || info.IsKeyPressed(Keys.Space))
     {
         if (Answers.Count == 0)
         {
             Finished = true;
         }
         else
         {
             ProcessItem(Answers[PointerIndex].Item1);
         }
     }
     if (info.IsKeyPressed(Keys.Escape))
     {
         Finished = true;
     }
     if ((info.IsKeyPressed(Keys.Up) || info.IsKeyPressed(Keys.Down)) && Answers.Count > 0)
     {
         Screen.MessageConsole.PrintMessage(Answers[PointerIndex].Item1.Details());
     }
 }
Example #28
0
        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(SadConsole.Input.Keyboard info) => mainData.ProcessKeyboard(info);
Example #30
0
        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);
        }