mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-08-17 05:40:40 +08:00
Gamepad input started
This commit is contained in:
@ -1,24 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,8 +5,6 @@ namespace Strawberry
|
||||
{
|
||||
public class VirtualAxis : VirtualInput
|
||||
{
|
||||
public enum OverlapBehaviors { TakeNewer, TakeOlder, CancelOut }
|
||||
|
||||
public float Value { get; private set; }
|
||||
public int Valuei { get; private set; }
|
||||
public bool Pressed { get; private set; }
|
||||
@ -141,9 +139,9 @@ namespace Strawberry
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (Input.KeyCheck(PositiveKeycode))
|
||||
if (Game.KeyCheck(PositiveKeycode))
|
||||
{
|
||||
if (Input.KeyCheck(NegativeKeycode))
|
||||
if (Game.KeyCheck(NegativeKeycode))
|
||||
{
|
||||
switch (OverlapBehavior)
|
||||
{
|
||||
@ -170,7 +168,7 @@ namespace Strawberry
|
||||
value = 1;
|
||||
}
|
||||
}
|
||||
else if (Input.KeyCheck(NegativeKeycode))
|
||||
else if (Game.KeyCheck(NegativeKeycode))
|
||||
{
|
||||
turned = false;
|
||||
value = -1;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using SDL2;
|
||||
|
||||
namespace Strawberry
|
||||
{
|
||||
@ -84,12 +85,18 @@ namespace Strawberry
|
||||
|
||||
// Setup Calls
|
||||
|
||||
public VirtualButton Key(SDL2.SDL.Scancode keycode)
|
||||
public VirtualButton Key(SDL.Scancode keycode)
|
||||
{
|
||||
nodes.Add(new KeyboardKey(keycode));
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualButton Button(SDL.SDL_GameControllerButton button)
|
||||
{
|
||||
nodes.Add(new GamepadButton(button));
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualButton PressBuffer(float time)
|
||||
{
|
||||
pressBuffer = time;
|
||||
@ -118,9 +125,9 @@ namespace Strawberry
|
||||
|
||||
private class KeyboardKey : Node
|
||||
{
|
||||
public SDL2.SDL.Scancode Keycode;
|
||||
public SDL.Scancode Keycode;
|
||||
|
||||
public this(SDL2.SDL.Scancode keycode)
|
||||
public this(SDL.Scancode keycode)
|
||||
{
|
||||
Keycode = keycode;
|
||||
}
|
||||
@ -129,7 +136,50 @@ namespace Strawberry
|
||||
{
|
||||
get
|
||||
{
|
||||
return Input.KeyCheck(Keycode);
|
||||
return Game.KeyCheck(Keycode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class GamepadButton : Node
|
||||
{
|
||||
public SDL.SDL_GameControllerButton Button;
|
||||
|
||||
public this(SDL.SDL_GameControllerButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
|
||||
override public bool Check
|
||||
{
|
||||
get
|
||||
{
|
||||
return Game.GamepadButtonCheck(Button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class GamepadAxis : Node
|
||||
{
|
||||
public SDL.SDL_GameControllerAxis Axis;
|
||||
public float Threshold;
|
||||
public ThresholdConditions Condition;
|
||||
|
||||
public this(SDL.SDL_GameControllerAxis axis, float threshold, ThresholdConditions condition = .GreaterThan)
|
||||
{
|
||||
Axis = axis;
|
||||
Threshold = threshold;
|
||||
Condition = condition;
|
||||
}
|
||||
|
||||
override public bool Check
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Condition == .GreaterThan)
|
||||
return Game.GamepadAxisCheck(Axis) >= Threshold;
|
||||
else
|
||||
return Game.GamepadAxisCheck(Axis) <= Threshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ namespace Strawberry
|
||||
{
|
||||
public abstract class VirtualInput
|
||||
{
|
||||
public enum OverlapBehaviors { TakeNewer, TakeOlder, CancelOut }
|
||||
public enum ThresholdConditions { GreaterThan, LessThan }
|
||||
|
||||
public this()
|
||||
{
|
||||
Game.VirtualInputs.Add(this);
|
||||
|
Reference in New Issue
Block a user