Skip to content

Commit

Permalink
touch controls are now visible if touching
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneSchwettmann committed Mar 23, 2017
1 parent bdab8c1 commit a9dadcb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
32 changes: 31 additions & 1 deletion src/Draw.lua
Expand Up @@ -22,7 +22,7 @@ function love.draw()
if displayingTitleScreen then
drawTitleScreen()
elseif displayingControls then
drawControlScreen()
drawControlScreen()
else

love.graphics.setColor(255,255,255,255)
Expand Down Expand Up @@ -87,6 +87,36 @@ function love.draw()
love.graphics.draw(canvas2X,borderX,borderY)
love.graphics.scale(1.0/graphicsScaleFactor,1.0/graphicsScaleFactor)
end
-- draw the virtual gamepad directly to the screen
if touching then
-- virtual gamepad button coordinates i,j (1,1) top left, (3,3) bottom right
love.graphics.setColor(255,255,255,128)
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
local dPadButtonSizeX = dPadButtonSizeRel*width
local dPadButtonSizeY = dPadButtonSizeX
local dPadTopLeftX=0
local dPadTopLeftY=height-3*dPadButtonSizeY
local i=0
local j=0
--for i=0,2,1 do
-- for j=0,2,1 do
-- love.graphics.rectangle("line",dPadTopLeftX+i*dPadButtonSizeX,dPadTopLeftY+j*dPadButtonSizeY,dPadButtonSizeX,dPadButtonSizeY)
-- end
--end
for i=0,3,1 do
-- horizontal lines
love.graphics.line(dPadTopLeftX+1,dPadTopLeftY+i*dPadButtonSizeY,dPadTopLeftX+3*dPadButtonSizeX-1,dPadTopLeftY+i*dPadButtonSizeY)
-- vertical lines
love.graphics.line(dPadTopLeftX+i*dPadButtonSizeX,dPadTopLeftY+1,dPadTopLeftX+i*dPadButtonSizeX,dPadTopLeftY+3*dPadButtonSizeY-1)
end
-- virtual firebutton rectangle
local fireButtonSizeX = fireButtonSizeRel*width
local fireButtonSizeY = fireButtonSizeX
local fireButtonTopLeftX=width-fireButtonSizeX
local fireButtonTopLeftY=height-fireButtonSizeY
love.graphics.rectangle("line",fireButtonTopLeftX+i*fireButtonSizeX,fireButtonTopLeftY+j*dPadButtonSizeY,fireButtonSizeX,fireButtonSizeY)
end
--[[
if gameWasPaused==true then
love.graphics.print("Starting in: "..(timeToWaitAfterPause-timeSinceUnpausing).." s", centerX-50, centerY-5)
Expand Down
4 changes: 2 additions & 2 deletions src/Input.lua
Expand Up @@ -13,7 +13,7 @@ function getInputPlayer(playerNumber)
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
-- relative (square) button size
local dPadButtonSizeX = 0.1*width
local dPadButtonSizeX = dPadButtonSizeRel*width
local dPadButtonSizeY = dPadButtonSizeX
-- top left coordinate of virtual gamepad
local dPadTopLeftX=0
Expand All @@ -25,7 +25,7 @@ function getInputPlayer(playerNumber)
xInput = i-2
yInput = j-2
end
local fireButtonSizeX = 0.3*width
local fireButtonSizeX = fireButtonSizeRel*width
local fireButtonSizeY = fireButtonSizeX
-- large virtual firebutton on the bottom right
local fireButtonTopLeftX=width-fireButtonSizeX
Expand Down
4 changes: 4 additions & 0 deletions src/Load.lua
Expand Up @@ -17,6 +17,10 @@ function love.load()
statusBarHeight=50

touching = false
-- gamepad touch button sizes as fraction of displaywidth
dPadButtonSizeRel = 0.1
fireButtonSizeRel = 0.3


defaultAudioSourceZPos = 0.5 -- controls the amount of stereo panning, 0 is absolute only left/right, 1 is barely noticeable panning

Expand Down

0 comments on commit a9dadcb

Please sign in to comment.