Initial commit
This commit is contained in:
commit
35a9dd9f87
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"runtime.version": "LuaJIT",
|
||||
"diagnostics.globals": [
|
||||
"ngx"
|
||||
],
|
||||
"workspace.library": [
|
||||
"${3rd}/love2d/library"
|
||||
]
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue