Code: Select all
function love.load()
optbox = {
x = 240,
y = 70,
xmin = 240,
xmax = 490,
ymin = 70,
ymax = 270
} -- ending optbox
whichkey = "up" -- move these later! don't need to be global
whichkeyindex = 1 -- move these later! don't need to be global
rebinding = "no"
rebindingState = "key"
controlsGame = {
key = {
up = "up",
down = "down",
left = "left",
right = "right",
trick1 = "w",
trick2 = "a",
trick3 = "d",
trick4 = "s",
accept = "return",
cancel = "backspace",
pause = "escape"
},
button = {
up = "---",
down = "---",
left = "---",
right = "---",
trick1 = "---",
trick2 = "---",
trick3 = "---",
trick4 = "---",
accept = "---",
cancel = "---",
pause = "---"
},
order = { "up", "down", "left", "right", "trick1", "trick2", "trick3", "trick4", "pause", "accept", "cancel" }
} -- ending controlsGame
end -- ending love.load
function love.draw()
love.graphics.printf("Controls", 0, 0, 640, "center")
love.graphics.printf("Highlight and press B for rebind", 0, 20, 640, "center")
love.graphics.print("Action",0,50)
love.graphics.print("Key",250, 50)
love.graphics.print("Button", 500, 50)
love.graphics.print("Move up", 0, 70)
love.graphics.print("Move down", 0, 90)
love.graphics.print("Move left", 0, 110)
love.graphics.print("Move right", 0, 130)
love.graphics.print("Trick 1", 0, 150)
love.graphics.print("Trick 2", 0, 170)
love.graphics.print("Trick 3", 0, 190)
love.graphics.print("Trick 4", 0, 210)
love.graphics.print("Pause", 0, 230)
love.graphics.print("Accept", 0, 250)
love.graphics.print("Cancel", 0, 270)
love.graphics.print(controlsGame.key.up, 250, 70)
love.graphics.print(controlsGame.key.down, 250, 90)
love.graphics.print(controlsGame.key.left, 250, 110)
love.graphics.print(controlsGame.key.right, 250, 130)
love.graphics.print(controlsGame.key.trick1, 250, 150)
love.graphics.print(controlsGame.key.trick2, 250, 170)
love.graphics.print(controlsGame.key.trick3, 250, 190)
love.graphics.print(controlsGame.key.trick4, 250, 210)
love.graphics.print(controlsGame.key.pause, 250, 230)
love.graphics.print(controlsGame.key.accept, 250, 250)
love.graphics.print(controlsGame.key.cancel, 250, 270)
love.graphics.print(controlsGame.button.up, 500, 70)
love.graphics.print(controlsGame.button.down, 500, 90)
love.graphics.print(controlsGame.button.left, 500, 110)
love.graphics.print(controlsGame.button.right, 500, 130)
love.graphics.print(controlsGame.button.trick1, 500, 150)
love.graphics.print(controlsGame.button.trick2, 500, 170)
love.graphics.print(controlsGame.button.trick3, 500, 190)
love.graphics.print(controlsGame.button.trick4, 500, 210)
love.graphics.print(controlsGame.button.pause, 500, 230)
love.graphics.print(controlsGame.button.accept, 500, 250)
love.graphics.print(controlsGame.button.cancel, 500, 270)
love.graphics.rectangle("line", optbox.x, optbox.y, 100, 15)
if rebinding == "yes" then
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle("fill", 320, 240, 100, 25)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Press new " .. rebindingState .. ".", 322, 245)
end
love.graphics.print(whichkeyindex,0,0) -- debug
love.graphics.print(whichkey,0, 10) -- debug
end -- ending love.draw
function love.keypressed(key)
if rebinding == "no" then
if key == "escape" then
love.event.quit()
end
if key == controlsGame.key.up then
if optbox.y > optbox.ymin then
optbox.y = optbox.y - 20
whichkeyindex = whichkeyindex - 1
whichkey = controlsGame["order"][whichkeyindex]
end
end
if key == controlsGame.key.down then
if optbox.y < optbox.ymax then
optbox.y = optbox.y + 20
whichkeyindex = whichkeyindex + 1
whichkey = controlsGame["order"][whichkeyindex]
end
end
if key == controlsGame.key.left then
if optbox.x > optbox.xmin then
optbox.x = optbox.x - 250
end
end
if key == controlsGame.key.right then
if optbox.x < optbox.xmax then
optbox.x = optbox.x + 250
end
end
if key == "b" then
if optbox.x == 240 then
rebindingState = "key"
elseif optbox.x == 490 then
rebindingState = "button"
end
rebinding = "yes"
end
end
if rebinding == "yes" then
if key == "escape" then
rebinding = "no"
elseif rebindingState == "key" then
local newkey = key
controlsGame["key"][whichkey] = newkey
rebinding = "no"
end
end -- ending rebinding
end -- ending love.keypressed
(also I know the display is unoptimized, I figured out how I wanted to do that after I got through all of this ;)