added a menu with listed hotkeys, cleaned code

This commit is contained in:
mango 2025-09-05 15:10:09 -07:00
commit 101e762d12

View file

@ -1,63 +1,85 @@
function love.load() function love.load()
require("sdl") require("sdl")
local Button = require "button"
joysticks = love.joystick.getJoysticks() joysticks = love.joystick.getJoysticks()
fightstick = joysticks[1] fightstick = joysticks[1]
local Button = require "button"
--movement keys MENU = true
local col1 = {255/255, 179/255, 102/255}
local col2 = {150/255, 109/255, 209/255}
local col3 = {255/255, 0/255, 0/255}
--movement buttons
movement = { movement = {
Button(25, 40, 29, "dpleft", {255/255, 179/255, 102/255}), Button(25, 40, 29, "dpleft", col1),
Button(90, 40, 29, "dpdown", {255/255, 179/255, 102/255}), Button(90, 40, 29, "dpdown", col1),
Button(147, 71, 29, "dpright", {255/255, 179/255, 102/255}), Button(147, 71, 29, "dpright", col1),
Button(168, 180, 36, "dpup", {255/255, 179/255, 102/255}), Button(168, 180, 36, "dpup", col1),
} }
--attack keys, add {x,x,x} value to change color of button --attack buttons
attack = { attack = {
Button(207, 43, 29, "x", {150/255, 109/255, 209/255}), Button(207, 43, 29, "x", col2),
Button(265, 17, 29, "y", {150/255, 109/255, 209/255}), Button(265, 17, 29, "y", col2),
Button(330, 22, 29, "rightshoulder", {150/255, 109/255, 209/255}), Button(330, 22, 29, "rightshoulder", col2),
Button(395, 38, 29, "leftshoulder", {150/255, 109/255, 209/255}), Button(395, 38, 29, "leftshoulder", col2),
Button(202, 110, 29, "a", {150/255, 109/255, 209/255}), Button(202, 110, 29, "a", col2),
Button(263, 86, 29, "b", {150/255, 109/255, 209/255}), Button(263, 86, 29, "b", col2),
Button(330, 88, 29, "triggerright", {150/255, 109/255, 209/255}), Button(330, 88, 29, "triggerright", col2),
Button(394, 105, 29, "triggerleft", {150/255, 109/255, 209/255}), Button(394, 105, 29, "triggerleft", col2),
} }
end end
function love.keypressed(key) function love.keypressed(key)
--pressing b will change the borderless setting, and the position of the window is prevented from resetting during this if key == "space" then
if key == "b" then MENU = not MENU
if BORDERLESS then elseif key == "b" then
BORDERLESS = false BORDERLESS = not BORDERLESS
love.window.setMode(WINDOWWIDTH, WINDOWHEIGHT, {borderless=false, x=windowx, y=windowy}) love.window.setMode(WINDOWWIDTH, WINDOWHEIGHT, {borderless = BORDERLESS})
else elseif key == "r" then
BORDERLESS = true resize()
love.window.setMode(WINDOWWIDTH, WINDOWHEIGHT, {borderless=true, x=windowx, y=windowy}) elseif key == "q" then
end love.event.quit()
end end
end end
function love.update(dt) function love.update(dt)
windowx, windowy, _ = love.window.getPosition() windowx, windowy, _ = love.window.getPosition()
--movement keys mousex, mousey = love.mouse.getPosition()
if not MENU then
--movement buttons
for i, v in ipairs(movement) do for i, v in ipairs(movement) do
v:update(dt) v:update(dt)
end end
--attack keys --attack button
for i, v in ipairs(attack) do for i, v in ipairs(attack) do
v:update(dt) v:update(dt)
end end
end
end end
function love.draw() function love.draw()
love.graphics.scale(WINDOWSCALE, WINDOWSCALE) love.graphics.scale(WINDOWSCALE, WINDOWSCALE)
love.graphics.setLineWidth(2) love.graphics.setLineWidth(2)
--movement keys if not MENU then
--movement buttons
for i, v in ipairs(movement) do for i, v in ipairs(movement) do
v:draw() v:draw()
end end
--attack keys --attack buttons
for i, v in ipairs(attack) do for i, v in ipairs(attack) do
v:draw() v:draw()
end end
elseif MENU then
love.graphics.newFont(10)
love.graphics.setColor(150/255, 150/255, 150/255)
love.graphics.print("hotkeys:", 0, 0)
love.graphics.print("borderless = b", 0, 16)
love.graphics.print("window scale = s", 0, 32)
love.graphics.print("quit = q", 0, 48)
love.graphics.printf("open/close this menu with spacebar", 0, 254, 480, "center")
love.graphics.setColor(60/255, 60/255, 60/255)
love.graphics.newFont(6)
love.graphics.printf("made by levi leggott - 2025", 0, 238, 480, "center")
end
end end