Skip to content

Commit

Permalink
Added experimental gamepad support.
Browse files Browse the repository at this point in the history
  • Loading branch information
clarvalon committed Apr 12, 2020
1 parent 3115977 commit 731262e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Content/Game/Game.FULL.xml
Expand Up @@ -284,6 +284,7 @@
<OnEveryFrameAlwaysLate>late_repeatedly_execute_always</OnEveryFrameAlwaysLate>
<OnMouseClick>on_mouse_click</OnMouseClick>
<OnKeyPress>on_key_press</OnKeyPress>
<OnButtonPress />
<LeftEdgeX>0</LeftEdgeX>
<RightEdgeX>0</RightEdgeX>
<TopEdgeY>0</TopEdgeY>
Expand All @@ -295,6 +296,7 @@
<Script ScriptID="repeatedly_execute_always" ParametersSignature="None" ReturnType="void" />
<Script ScriptID="on_key_press" ParametersSignature="KeyCode" ReturnType="void" />
<Script ScriptID="on_mouse_click" ParametersSignature="MouseButton" ReturnType="void" />
<Script ScriptID="ButtonPress" ParametersSignature="Buttons" />
<Width>0</Width>
<Height>0</Height>
</Room>
Expand All @@ -309,6 +311,7 @@
<OnKeyPress>on_key_press</OnKeyPress>
<OnLeave>room_Leave</OnLeave>
<OnCall>on_call</OnCall>
<OnButtonPress>on_button_press</OnButtonPress>
<LeftEdgeX>0</LeftEdgeX>
<RightEdgeX>634</RightEdgeX>
<TopEdgeY>80</TopEdgeY>
Expand All @@ -321,6 +324,7 @@
<Script ScriptID="room_RepExec" ParametersSignature="None" />
<Script ScriptID="on_key_press" ParametersSignature="KeyCode" ReturnType="void" />
<Script ScriptID="on_call" ParametersSignature="Int" />
<Script ScriptID="on_button_press" ParametersSignature="Buttons" />
<Polygon ScriptID="WalkableArea1" BaseLine="0" IntID="1" ScalingLevel="100" MinScalingLevel="100" MaxScalingLevel="100" UseContinuousScaling="false">
<Enabled>true</Enabled>
<Outers>
Expand Down Expand Up @@ -1258,9 +1262,11 @@
<Script ScriptID="ChangeOption" ParametersSignature="Unknown" />
<Script ScriptID="CancelMenu" ParametersSignature="Unknown" />
<Script ScriptID="on_key_press" ParametersSignature="KeyCode" />
<Script ScriptID="on_button_press" ParametersSignature="Buttons" />
</Scripts>
<InstanceID>GameMenu</InstanceID>
<OnKeyPress>on_key_press</OnKeyPress>
<OnButtonPress>on_button_press</OnButtonPress>
</Module>
<Module>
<ScriptID>GUIUtils</ScriptID>
Expand Down
47 changes: 46 additions & 1 deletion VisualStudio/LastnFurious.Script/Script/Modules/GameMenu.cs
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Xml.Serialization;
using Clarvalon.XAGE.Global;
using Microsoft.Xna.Framework.Input;

namespace LastnFurious
{
Expand Down Expand Up @@ -527,7 +528,51 @@ public void CancelMenu()
}
}

public void on_key_press(eKeyCode key)
public void on_button_press(Buttons button)
{
if (!gGameMenu.Visible)
return;
if (MenuType == eMenuCredits)
{
SwitchToMenu(eMenuStart);
return;
}
if (button == Buttons.B || button == Buttons.Back)
{
CancelMenu();
}
else if (button == Buttons.DPadUp || button == Buttons.LeftThumbstickUp)
{
if (MMSelection > 0)
{
MMSelection -= 1;
UpdateSelection();
}
}
else if (button == Buttons.DPadDown || button == Buttons.LeftThumbstickDown)
{
if (MMSelection < MMOptionCount - 1)
{
MMSelection += 1;
UpdateSelection();
}
}
else if (button == Buttons.DPadLeft || button == Buttons.LeftThumbstickLeft)
{
ChangeOption(true);
}
else if (button == Buttons.DPadRight || button == Buttons.LeftThumbstickRight)
{
ChangeOption(false);
}
else if (button == Buttons.A || button == Buttons.Start)
{
ConfirmSelection();
}
ClaimEvent();
}

public void on_key_press(eKeyCode key)
{
if (!gGameMenu.Visible)
return;
Expand Down
26 changes: 24 additions & 2 deletions VisualStudio/LastnFurious.Script/Script/Modules/RaceUI.cs
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Xml.Serialization;
using Clarvalon.XAGE.Global;
using Microsoft.Xna.Framework.Input;

namespace LastnFurious
{
Expand All @@ -30,19 +31,40 @@ public void repeatedly_execute_always()
return;
if (PlayersCarIndex < 0 || !Cars[PlayersCarIndex].IsInit)
return;

var gamePadState = GetGamePadState();

// Accelerator
if (IsKeyPressed(eKeyUpArrow))
Cars[PlayersCarIndex].Accelerator = 1.0f;
else
else if (gamePadState.Triggers.Right > 0f)
Cars[PlayersCarIndex].Accelerator = gamePadState.Triggers.Right;
else
Cars[PlayersCarIndex].Accelerator = 0.0f;

// Brakes
if (IsKeyPressed(eKeyDownArrow))
Cars[PlayersCarIndex].Brakes = 1.0f;
else if (gamePadState.Triggers.Left > 0f)
Cars[PlayersCarIndex].Brakes = gamePadState.Triggers.Left;
else
Cars[PlayersCarIndex].Brakes = 0.0f;

// Steering
float deadzone = 0.1f;
if (IsKeyPressed(eKeyLeftArrow))
Cars[PlayersCarIndex].steeringWheelAngle = -UISteeringAngle;
else if (IsKeyPressed(eKeyRightArrow))
Cars[PlayersCarIndex].steeringWheelAngle = UISteeringAngle;
else
else if (gamePadState.ThumbSticks.Left.X < -deadzone)
Cars[PlayersCarIndex].steeringWheelAngle = gamePadState.ThumbSticks.Left.X;
else if (gamePadState.ThumbSticks.Left.X > deadzone)
Cars[PlayersCarIndex].steeringWheelAngle = gamePadState.ThumbSticks.Left.X;
else if (gamePadState.DPad.Left == ButtonState.Pressed)
Cars[PlayersCarIndex].steeringWheelAngle = -UISteeringAngle;
else if (gamePadState.DPad.Right == ButtonState.Pressed)
Cars[PlayersCarIndex].steeringWheelAngle = UISteeringAngle;
else
Cars[PlayersCarIndex].steeringWheelAngle = 0.0f;
}

Expand Down
15 changes: 15 additions & 0 deletions VisualStudio/LastnFurious.Script/Script/Rooms/JR_Track01.cs
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Xml.Serialization;
using Clarvalon.XAGE.Global;
using Microsoft.Xna.Framework.Input;

namespace LastnFurious
{
Expand Down Expand Up @@ -430,6 +431,20 @@ public override void on_key_press(eKeyCode key)
}
}

public override void on_button_press(Buttons button)
{
if (IsGamePaused())
return;
if (!gGameMenu.Visible && (button == Buttons.A || button == Buttons.B))
{
if (IsAIRace)
DisplayGameMenu(eMenuMain, false);
else
DisplayGameMenu(eMenuMainInGame, true);
ClaimEvent();
}
}

public override void on_call(int value)
{
if (value == eRoom305_StartSinglePlayer)
Expand Down

0 comments on commit 731262e

Please sign in to comment.