Skip to content

Commit

Permalink
fix gamepad controls and screen scaling (fixes Switch)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneSchwettmann committed Nov 22, 2021
1 parent c0970e2 commit 0fa42e5
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/Draw.lua
Expand Up @@ -203,7 +203,7 @@ function drawTitleScreen()
love.graphics.printf("c - Configure controls", 0, centerY-7-16+75,width,"center")
love.graphics.printf("f - Toggle fullscreen", 0, centerY-7+75,width,"center")
love.graphics.printf("t - Toggle scaling (fullscreen only)", 0, centerY-7+16+75,width,"center")
love.graphics.printf("q - Quit", 0, centerY-7+32+75,width,"center")
love.graphics.printf("q or Select - Quit", 0, centerY-7+32+75,width,"center")
end
function drawControlScreen()
Expand Down Expand Up @@ -293,7 +293,7 @@ function drawGameOverScreen()
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", floor(centerX-100), floor(centerY+75-40), 200, 80 )
love.graphics.setColor(0,0,0,1)
love.graphics.printf("Press q to restart", 0, centerY-5+75,width,"center")
love.graphics.printf("Press Q to restart", 0, centerY-5+75,width,"center")
end
function drawProgressBar(x,y,width,height,percent)
Expand Down
111 changes: 72 additions & 39 deletions src/Input.lua
Expand Up @@ -87,39 +87,59 @@ function getInputPlayer(playerNumber)
local joyXInput,joyYInput = 0,0
if ( joystickNum <= numJoysticks ) then
local joystick = joysticks[joystickNum]
local numButtons = joystick:getButtonCount()
if joystick:getAxisCount()>=1 then
joyXInput,joyYInput = joystick:getAxes()
io.write(joyXInput)
end
if joystick:getHatCount()>=1 then
local hatDirection = joystick:getHat(1)
if hatDirection == 'u' then
joyYInput = -1
joyXInput = 0
elseif hatDirection == 'd' then
joyYInput = 1
elseif hatDirection == 'l' then
joyXInput = -1
elseif hatDirection == 'r' then
joyXInput = 1
elseif hatDirection == 'ld' then
joyXInput = -1
joyYInput = 1
elseif hatDirection == 'lu' then
joyXInput = -1
joyYInput = -1
elseif hatDirection == 'rd' then
joyXInput = 1
joyYInput = 1
elseif hatDirection == 'ru' then
joyXInput = 1
joyYInput = -1
end
end
if numButtons>0 then
if anyButtonPressed(joystick, numButtons) then
buttonInput=true
if (joystick:isGamepad()) then
joyXInput = joystick:getGamepadAxis("leftx")
joyYInput = joystick:getGamepadAxis("lefty")
if joystick:isGamepadDown("dpup") then
joyYInput = -1
elseif joystick:isGamepadDown("dpdown") then
joyYInput = 1
end
if joystick:isGamepadDown("dpleft") then
joyXInput = -1
elseif joystick:isGamepadDown("dpright") then
joyXInput = 1
end
if joystick:isGamepadDown("a", "b", "x", "y") then
buttonInput = true
end
if joystick:isGamepadDown("back") then
love.keypressed("q")
end
else
local numButtons = joystick:getButtonCount()
if joystick:getAxisCount()>=1 then
joyXInput,joyYInput = joystick:getAxes()
end
if joystick:getHatCount()>=1 then
local hatDirection = joystick:getHat(1)
if hatDirection == 'u' then
joyYInput = -1
joyXInput = 0
elseif hatDirection == 'd' then
joyYInput = 1
elseif hatDirection == 'l' then
joyXInput = -1
elseif hatDirection == 'r' then
joyXInput = 1
elseif hatDirection == 'ld' then
joyXInput = -1
joyYInput = 1
elseif hatDirection == 'lu' then
joyXInput = -1
joyYInput = -1
elseif hatDirection == 'rd' then
joyXInput = 1
joyYInput = 1
elseif hatDirection == 'ru' then
joyXInput = 1
joyYInput = -1
end
end
if numButtons>0 then
if anyButtonPressed(joystick, numButtons) then
buttonInput=true
end
end
end
if joyXInput > 0.25 then
Expand Down Expand Up @@ -156,18 +176,31 @@ end
function love.gamepadpressed(joystick, button)
-- press fire on title screen to start single player game with joystick controls
if (displayingTitleScreen
and button ~= "dpup"
and button ~= "dpdown"
and button ~= "dpleft"
and button ~= "dpright") then
and button ~= "dpup"
and button ~= "dpdown"
and button ~= "dpleft"
and button ~= "dpright") then
if (button == "back") then
love.keypressed('q')
end
for i=1,#joysticks,1 do
if joysticks[i]:getID()==joystick:getID() then
-- set first player to the joystick that was pressed and start game
controls[1]=i+2
numPlayers=1
for j=1,5,1 do
if controls[j]==i+2 then
numPlayers=j
end
end
startGame()
end
end
elseif (gameLost
and button ~= "dpup"
and button ~= "dpdown"
and button ~= "dpleft"
and button ~= "dpright"
and button ~= "back") then
titleScreen()
end
end

Expand Down
17 changes: 15 additions & 2 deletions src/Load.lua
Expand Up @@ -182,9 +182,9 @@ function love.load()
fsaa=flags.msaa
initializeFullscreenMode()
love.graphics.setDefaultFilter("nearest","nearest")
if fullscreen then
-- if fullscreen then
toggleScaling()
end
-- end

--canvas1X=love.graphics.newCanvas(width,height)
--canvas1X:setFilter("nearest","nearest")
Expand Down Expand Up @@ -249,6 +249,19 @@ function love.load()
joysticks = love.joystick.getJoysticks()
numJoysticks = love.joystick.getJoystickCount();

if numJoysticks == 0 then
controls = {1,2,3,4,5}
elseif numJoysticks == 1 then
controls = {3,1,2,4,5}
elseif numJoysticks == 2 then
controls = {3,4,1,2,5}
elseif numJoysticks == 3 then
controls = {3,4,5,1,2}
elseif numJoysticks == 4 then
controls = {3,4,5,6,1}
elseif numJoysticks >= 5 then
controls = {3,4,5,6,7}
end
--pauseGame()
titleScreen()
end
Expand Down

0 comments on commit 0fa42e5

Please sign in to comment.