Advertisement
Frumkin

Untitled

Jul 31st, 2021
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1.         private static class Input {
  2.             public static bool IsKeyPressed(Key key) {
  3.                 int index = (int)key;
  4.                 return KeysDown[index] && !keysDownPrevious[index];
  5.             }
  6.  
  7.             public static bool IsMousePressed(MouseButton mouseButton) {
  8.                 int index = (int)mouseButton;
  9.                 return MouseButtonsDown[index] && !mouseButtonsDownPrevious[index];
  10.             }
  11.  
  12.             private static readonly byte AmountOfKeys = (byte)Enum.GetNames(typeof(Key)).Length;
  13.             private static readonly byte AmountOfMouseButtons = (byte)Enum.GetNames(typeof(MouseButton)).Length;
  14.  
  15.             public static void Handle() {
  16.                 for (byte index = 0; index < AmountOfKeys - 1; index += 1) {
  17.                     keysDownPrevious[index] = KeysDown[index];
  18.                 }
  19.  
  20.                 for (byte index = 0; index < AmountOfMouseButtons - 1; index += 1) {
  21.                     mouseButtonsDownPrevious[index] = MouseButtonsDown[index];
  22.                 }
  23.             }
  24.  
  25.             public static bool[] KeysDown = new bool[AmountOfKeys];
  26.             public static bool[] MouseButtonsDown = new bool[AmountOfKeys];
  27.  
  28.             private static bool[] keysDownPrevious = new bool[AmountOfKeys];
  29.             private static bool[] mouseButtonsDownPrevious = new bool[AmountOfMouseButtons];
  30.  
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement