Castle.Player.ProcessKeyboard C# (CSharp) Method

ProcessKeyboard() public method

public ProcessKeyboard ( SadConsole info ) : bool
info SadConsole
return bool
        public bool ProcessKeyboard(SadConsole.Input.KeyboardInfo 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;
        }

Usage Example

Example #1
0
 public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
 {
     if (info == null)
     {
         return(false);
     }
     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);
         }
     }
 }