Replaced SDLApp code in Game, no longer extends it

This commit is contained in:
Matt Thorson
2020-05-06 21:13:34 -07:00
parent 12c10909c9
commit 0a709b5788
8 changed files with 142 additions and 35 deletions

24
src/Input/Input.bf Normal file
View File

@ -0,0 +1,24 @@
using SDL2;
namespace Strawberry
{
static public class Input
{
static public bool KeyCheck(SDL.Scancode key)
{
if (Game.KeyboardState == null)
return false;
return Game.KeyboardState[(int)key];
}
static public bool KeyPressed(SDL.Scancode key)
{
return KeyCheck(key) && (Game.PreviousKeyboardState == null || !Game.PreviousKeyboardState[(int)key]);
}
static public bool KeyReleased(SDL.Scancode key)
{
return (Game.PreviousKeyboardState != null && Game.PreviousKeyboardState[(int)key]) && !KeyCheck(key);
}
}
}

View File

@ -141,9 +141,9 @@ namespace Strawberry
public override void Update()
{
if (Game.IsKeyDown(PositiveKeycode))
if (Input.KeyCheck(PositiveKeycode))
{
if (Game.IsKeyDown(NegativeKeycode))
if (Input.KeyCheck(NegativeKeycode))
{
switch (OverlapBehavior)
{
@ -170,7 +170,7 @@ namespace Strawberry
value = 1;
}
}
else if (Game.IsKeyDown(NegativeKeycode))
else if (Input.KeyCheck(NegativeKeycode))
{
turned = false;
value = -1;

View File

@ -129,7 +129,7 @@ namespace Strawberry
{
get
{
return Game.IsKeyDown(Keycode);
return Input.KeyCheck(Keycode);
}
}
}