Exemplo n.º 1
0
 public void HandleInput(Input input)
 {
     cols.HandleInput(input);
     if (input.GetKeyState(Keys.Escape) == InputState.Pressed)
     {
         Exit();
     }
 }
Exemplo n.º 2
0
        public void HandleKeyInput(Input.Input input)
        {
            Keys[] pressed = input.GetPressedKeys();

            if (selected && editable)
            {
                if (pressed.Length > 0) // dont do anything if keys have not been pressed
                {
                    for (int i = 0; i < pressed.Length; i++)
                    {
                        if (input.GetKeyState(pressed[i]) == InputState.Pressed)
                        {
                            if (KeyConverter.IsTypeableKey(pressed[i])) // no unicode characters
                            {
                                bool shift = input.IsKeyDown(Keys.RightShift) || input.IsKeyDown(Keys.LeftShift);
                                int asciiKey = KeyConverter.ConvertToAscii(pressed[i],shift);

                                if (!shift && asciiKey >= 65 && asciiKey <= 90)
                                {
                                    text = StringManip.AddCharAtPos(text, (char)(asciiKey + 32), textPos); // lower case
                                }
                                else
                                {
                                    text = StringManip.AddCharAtPos(text, (char)asciiKey, textPos);
                                }
                                textPos++;
                            }
                            else if (pressed[i] == Keys.Back) // explicitly handle backspace
                            {
                                if (text.Length > 0)
                                {
                                    text = StringManip.RemoveCharAtPos(text, textPos);
                                    textPos--;
                                    if (textPos < 0)
                                    {
                                        textPos = 0;
                                    }
                                }
                            }
                            else if (pressed[i] == Keys.Delete)
                            {
                                if (text.Length > 0 && textPos != text.Length)
                                {
                                    text = StringManip.RemoveCharAtPos(text, textPos + 1);
                                    if (textPos > text.Length)
                                    {
                                        textPos = text.Length;
                                    }
                                }
                            }
                            else if (pressed[i] == Keys.Enter) // explicitly handle enter
                            {
                                if (Enter != null)
                                {
                                    Enter(null, new EventArgs());
                                }
                                else
                                {
                                    text += '\n';
                                }
                            }
                            else if (pressed[i] == Keys.Left)
                            {
                                textPos--;
                                if (textPos < 0)
                                {
                                    textPos = 0;
                                }
                            }
                            else if (pressed[i] == Keys.Right)
                            {
                                textPos++;
                                if (textPos > text.Length)
                                {
                                    textPos = text.Length;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public override void HandleInput(Input input)
 {
     velocity.X = 0;
     if (input.GetKeyState(controls["left"]) == InputState.Pressed ||
         input.GetKeyState(controls["left"]) == InputState.Held)
     {
         velocity.X -= xvel;
     }
     if (input.GetKeyState(controls["right"]) == InputState.Pressed ||
         input.GetKeyState(controls["right"]) == InputState.Held)
     {
         velocity.X += xvel;
     }
     if (velocity.X > 0)
     {
         flipped = false;
     }
     else if (velocity.X < 0)
     {
         flipped = true;
     }
     if (input.GetKeyState(controls["jump"]) == InputState.Pressed ||
         input.GetKeyState(controls["jump"]) == InputState.Held)
     {
         if (jumpPossible)
         {
             velocity.Y = -jumpPower;
         }
     }
     if (!isHit)
     {
         if (input.GetKeyState(controls["eat"]) == InputState.Pressed ||
             input.GetKeyState(controls["eat"]) == InputState.Held)
         {
             eating = true;
         }
         else
         {
             eating = false;
         }
         if (input.GetKeyState(controls["attack"]) == InputState.Pressed)
         {
             attacking = true;
         }
     }
 }