Initial commit

This commit is contained in:
mars 2023-04-10 23:14:24 -04:00
commit 7ae9f72610
2 changed files with 89 additions and 0 deletions

9
.luarc.json Normal file
View File

@ -0,0 +1,9 @@
{
"runtime.version": "LuaJIT",
"diagnostics.globals": [
"ngx"
],
"workspace.library": [
"${3rd}/love2d/library"
]
}

80
main.lua Normal file
View File

@ -0,0 +1,80 @@
MultiMenu = {}
MultiMenu.__index = MultiMenu
setmetatable(
MultiMenu,
{
__call = function(self, options)
setmetatable({}, self)
self:initialize(options)
return self
end
}
)
function MultiMenu:initialize(options)
self.options = options
self.selected = 1
end
function MultiMenu:draw()
-- option drawing constants
local x = 400
local y_anchor = 200
local spacing = 50
y_anchor = y_anchor - spacing
-- draw all the options
for idx, option in ipairs(self.options) do
local y = y_anchor + idx * spacing
love.graphics.print(option, x, y)
end
-- cursor metric constants
local cursor_width = 10
local cursor_depth = 20
local cursor_spacing = 20
-- calculate the cursor's position
local cursor_x = x - cursor_spacing
local cursor_y = y_anchor + spacing * self.selected
-- draw the cursor
love.graphics.polygon("fill",
cursor_x, cursor_y,
cursor_x - cursor_depth, cursor_y - cursor_width,
cursor_x - cursor_depth, cursor_y + cursor_width
)
end
function MultiMenu:up()
if self.selected == 1 then
self.selected = #self.options
else
self.selected = self.selected - 1
end
end
function MultiMenu:down()
if self.selected == #self.options then
self.selected = 1
else
self.selected = self.selected + 1
end
end
function love.load()
Menu = MultiMenu({ "Fight", "Use", "Pkmn", "Flee" })
end
function love.draw()
Menu:draw()
end
function love.keypressed(key)
if key == "up" then
Menu:up()
elseif key == "down" then
Menu:down()
end
end