Skip to content

Commit

Permalink
Added a third input.
Browse files Browse the repository at this point in the history
Since numbloc is not available on my Laptops Keybord^^
  • Loading branch information
LokiMidgard committed Feb 3, 2020
1 parent 16deb47 commit 6a11b1a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
40 changes: 38 additions & 2 deletions MedicalFactory/Input/KeyboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace PaToRo_Desktop.Engine.Input
{
public class KeyboardController : InputProvider
{
public const int SupportedNumber = 2;
public const int SupportedNumber = 3;
private int index;
private XnaInput.KeyboardState st;
private XnaInput.KeyboardState lastState;
Expand All @@ -35,7 +35,7 @@ private bool GetInternal0(XnaInput.KeyboardState st, Buttons btn)
{
Buttons.A => st.IsKeyDown(XnaInput.Keys.Q),
Buttons.B => st.IsKeyDown(XnaInput.Keys.E),
Buttons.Start => st.IsKeyDown(XnaInput.Keys.Enter),
Buttons.Start => st.IsKeyDown(XnaInput.Keys.Space),
_ => false,
};
}
Expand All @@ -50,13 +50,25 @@ private bool GetInternal1(XnaInput.KeyboardState st, Buttons btn)
};
}

private bool GetInternal2(XnaInput.KeyboardState st, Buttons btn)
{
return btn switch
{
Buttons.A => st.IsKeyDown(XnaInput.Keys.RightShift),
Buttons.B => st.IsKeyDown(XnaInput.Keys.RightControl),
Buttons.Start => st.IsKeyDown(XnaInput.Keys.Enter),
_ => false,
};
}

public override bool Get(Buttons btn)
{

return this.index switch
{
0 => this.GetInternal0(this.st, btn),
1 => this.GetInternal1(this.st, btn),
2 => this.GetInternal2(this.st, btn),
_ => false
};
}
Expand All @@ -66,6 +78,7 @@ public override bool GetLast(Buttons btn)
{
0 => this.GetInternal0(this.lastState, btn),
1 => this.GetInternal1(this.lastState, btn),
2 => this.GetInternal2(this.lastState, btn),
_ => false
};
}
Expand Down Expand Up @@ -97,13 +110,27 @@ private float YAxis1()
var down = this.st.IsKeyDown(XnaInput.Keys.NumPad2) ? 1 : 0;
return up + down;
}
private float XAxis2()
{
var left = this.st.IsKeyDown(XnaInput.Keys.Left) ? -1 : 0;
var right = this.st.IsKeyDown(XnaInput.Keys.Right) ? 1 : 0;
return left + right;
}

private float YAxis2()
{
var up = this.st.IsKeyDown(XnaInput.Keys.Up) ? -1 : 0;
var down = this.st.IsKeyDown(XnaInput.Keys.Down) ? 1 : 0;
return up + down;
}

public override float Get(Sliders sldr)
{
return this.index switch
{
0 => this.Get0(sldr),
1 => this.Get1(sldr),
2 => this.Get2(sldr),
_ => 0f
};
}
Expand All @@ -125,6 +152,15 @@ private float Get0(Sliders sldr)
_ => 0f
};
}
private float Get2(Sliders sldr)
{
return sldr switch
{
Sliders.LeftStickX => this.XAxis2(),
Sliders.LeftStickY => this.YAxis2(),
_ => 0f
};
}


public override void Rumble(float low, float high, int ms)
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ There are currently 2 Keyboard player supported
- Left: 'D'
- Right: 'A'
- Action: 'Q' or 'E'
- Start: 'Enter'
- Start: 'Space'
* Seccod input scheme
- Up: 'Num5'
- Down: 'Num2'
- Left: 'Num1'
- Right: 'Num3'
- Action: 'Num4' or 'Num6'
- Start: 'Num0'
* Third input scheme
- Up: 'Up'
- Down: 'Down'
- Left: 'Left'
- Right: 'Right'
- Action: 'LeftShift' or 'LeftControl'
- Start: 'Enter'

0 comments on commit 6a11b1a

Please sign in to comment.