added a menu with listed hotkeys, cleaned code
This commit is contained in:
parent
d2f7af607a
commit
101e762d12
1 changed files with 60 additions and 38 deletions
78
main.lua
78
main.lua
|
@ -1,63 +1,85 @@
|
|||
function love.load()
|
||||
require("sdl")
|
||||
local Button = require "button"
|
||||
joysticks = love.joystick.getJoysticks()
|
||||
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 = {
|
||||
Button(25, 40, 29, "dpleft", {255/255, 179/255, 102/255}),
|
||||
Button(90, 40, 29, "dpdown", {255/255, 179/255, 102/255}),
|
||||
Button(147, 71, 29, "dpright", {255/255, 179/255, 102/255}),
|
||||
Button(168, 180, 36, "dpup", {255/255, 179/255, 102/255}),
|
||||
Button(25, 40, 29, "dpleft", col1),
|
||||
Button(90, 40, 29, "dpdown", col1),
|
||||
Button(147, 71, 29, "dpright", col1),
|
||||
Button(168, 180, 36, "dpup", col1),
|
||||
}
|
||||
--attack keys, add {x,x,x} value to change color of button
|
||||
--attack buttons
|
||||
attack = {
|
||||
Button(207, 43, 29, "x", {150/255, 109/255, 209/255}),
|
||||
Button(265, 17, 29, "y", {150/255, 109/255, 209/255}),
|
||||
Button(330, 22, 29, "rightshoulder", {150/255, 109/255, 209/255}),
|
||||
Button(395, 38, 29, "leftshoulder", {150/255, 109/255, 209/255}),
|
||||
Button(202, 110, 29, "a", {150/255, 109/255, 209/255}),
|
||||
Button(263, 86, 29, "b", {150/255, 109/255, 209/255}),
|
||||
Button(330, 88, 29, "triggerright", {150/255, 109/255, 209/255}),
|
||||
Button(394, 105, 29, "triggerleft", {150/255, 109/255, 209/255}),
|
||||
Button(207, 43, 29, "x", col2),
|
||||
Button(265, 17, 29, "y", col2),
|
||||
Button(330, 22, 29, "rightshoulder", col2),
|
||||
Button(395, 38, 29, "leftshoulder", col2),
|
||||
Button(202, 110, 29, "a", col2),
|
||||
Button(263, 86, 29, "b", col2),
|
||||
Button(330, 88, 29, "triggerright", col2),
|
||||
Button(394, 105, 29, "triggerleft", col2),
|
||||
}
|
||||
end
|
||||
|
||||
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 == "b" then
|
||||
if BORDERLESS then
|
||||
BORDERLESS = false
|
||||
love.window.setMode(WINDOWWIDTH, WINDOWHEIGHT, {borderless=false, x=windowx, y=windowy})
|
||||
else
|
||||
BORDERLESS = true
|
||||
love.window.setMode(WINDOWWIDTH, WINDOWHEIGHT, {borderless=true, x=windowx, y=windowy})
|
||||
end
|
||||
if key == "space" then
|
||||
MENU = not MENU
|
||||
elseif key == "b" then
|
||||
BORDERLESS = not BORDERLESS
|
||||
love.window.setMode(WINDOWWIDTH, WINDOWHEIGHT, {borderless = BORDERLESS})
|
||||
elseif key == "r" then
|
||||
resize()
|
||||
elseif key == "q" then
|
||||
love.event.quit()
|
||||
end
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
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
|
||||
v:update(dt)
|
||||
end
|
||||
--attack keys
|
||||
--attack button
|
||||
for i, v in ipairs(attack) do
|
||||
v:update(dt)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
love.graphics.scale(WINDOWSCALE, WINDOWSCALE)
|
||||
love.graphics.setLineWidth(2)
|
||||
--movement keys
|
||||
if not MENU then
|
||||
--movement buttons
|
||||
for i, v in ipairs(movement) do
|
||||
v:draw()
|
||||
end
|
||||
--attack keys
|
||||
--attack buttons
|
||||
for i, v in ipairs(attack) do
|
||||
v:draw()
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue