Skip to content

Commit

Permalink
- move inputs to it's table
Browse files Browse the repository at this point in the history
  • Loading branch information
SoapyMan committed Apr 2, 2022
1 parent bd2afd1 commit ac5526a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions game/scripts/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ local headAngle = 0

local function GetCameraInput()
local input = {
lookLeft = ButtonState[SDL.Scancode.A],
lookRight = ButtonState[SDL.Scancode.D],
lookBack = ButtonState[SDL.Scancode.S],
lookLeft = Input.ButtonState[SDL.Scancode.A],
lookRight = Input.ButtonState[SDL.Scancode.D],
lookBack = Input.ButtonState[SDL.Scancode.S],
}
return input
end
Expand Down
12 changes: 7 additions & 5 deletions game/scripts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,10 @@ end
-- unless you know what it is
-------------------------------------------------

ButtonState = {}
JustPressed = {}
Input = {
ButtonState = {},
JustPressed = {}
}

local function errorHandler ( errobj )
MsgError("ERROR - "..errobj)
Expand All @@ -415,7 +417,7 @@ EngineHost = {
-- You can draw here ImGUI stuff
PostFrame = function( dt )
xpcall(RenderUI, errorHandler)
JustPressed = {}
Input.JustPressed = {}
end,

MouseMove = function( x, y, xrel, yrel)
Expand Down Expand Up @@ -449,8 +451,8 @@ EngineHost = {
pauseState = not pauseState
end

JustPressed[num] = down
ButtonState[num] = down
Input.JustPressed[num] = down
Input.ButtonState[num] = down
end, errorHandler)

end
Expand Down
25 changes: 16 additions & 9 deletions game/scripts/test_game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ local TestGame = {

TestGame.UpdateCamera = function(dt)

if JustPressed[SDL.Scancode.C] == true then
if Input.JustPressed[SDL.Scancode.C] == true then
TestGame.CameraNumber = (TestGame.CameraNumber + 1) & 1
end

Expand Down Expand Up @@ -229,32 +229,39 @@ TestGame.Init = function(residentModel)
end
end

local copState = false

TestGame.UpdateCarPads = function()
local input = {
accel = ButtonState[SDL.Scancode.Up],
brake = ButtonState[SDL.Scancode.Down],
wheelspin = ButtonState[SDL.Scancode.LeftShift],
handbrake = ButtonState[SDL.Scancode.Space],
accel = Input.ButtonState[SDL.Scancode.Up],
brake = Input.ButtonState[SDL.Scancode.Down],
wheelspin = Input.ButtonState[SDL.Scancode.LeftShift],
handbrake = Input.ButtonState[SDL.Scancode.Space],
steering = 0,
fastSteer = false,
horn = 0
}

if ButtonState[SDL.Scancode.Left] then
if Input.ButtonState[SDL.Scancode.Left] then
input.steering = -1
end

if ButtonState[SDL.Scancode.Right] then
if Input.ButtonState[SDL.Scancode.Right] then
input.steering = 1
end

if ButtonState[SDL.Scancode.LeftControl] then
if Input.ButtonState[SDL.Scancode.LeftControl] then
input.fastSteer = true
end

if ButtonState[SDL.Scancode.H] then
if Input.ButtonState[SDL.Scancode.H] then
input.horn = input.horn + 1
end

if Input.JustPressed[SDL.Scancode.T] then
copState = not copState
Music.FunkUpDaBGMTunez(copState)
end

-- update local player inputs
players.localPlayer.input = PlayerInputData(input)
Expand Down

0 comments on commit ac5526a

Please sign in to comment.