Add MultiMenu select() + callbacks + more leaf ranger animations
This commit is contained in:
parent
a228729f52
commit
ec2d98a707
28
main.lua
28
main.lua
|
@ -27,15 +27,37 @@ function love.load()
|
|||
}
|
||||
|
||||
BlockyFont = Font(blockyFont, 8, 8, blockFontChars)
|
||||
Menu = MultiMenu(BlockyFont, { "Fight", "Use", "Pkmn", "Flee" })
|
||||
|
||||
local leafRangerSprites = love.graphics.newImage("assets/leaf-ranger.png")
|
||||
local leafRangerAtlas = Atlas(leafRangerSprites, 288, 128)
|
||||
|
||||
local function sprites(row, len)
|
||||
local start = (row - 1) * 22 + 1
|
||||
return Animation:new_spanned(leafRangerAtlas, start, start + len - 1)
|
||||
end
|
||||
|
||||
LeafRangerAnimations = {
|
||||
idle = Animation:new_spanned(leafRangerAtlas, 1, 12),
|
||||
idle = sprites(1, 12),
|
||||
run = sprites(2, 10),
|
||||
hurt = sprites(16, 6),
|
||||
death = sprites(17, 20),
|
||||
}
|
||||
|
||||
local options = {}
|
||||
|
||||
for name, anim in pairs(LeafRangerAnimations) do
|
||||
options[#options + 1] = {
|
||||
text = name,
|
||||
callback = function()
|
||||
LeafRanger.animation = anim
|
||||
LeafRanger.step = 0
|
||||
LeafRanger.frame = 1
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
Menu = MultiMenu(BlockyFont, options)
|
||||
|
||||
LeafRanger = {
|
||||
animation = LeafRangerAnimations.idle,
|
||||
step = 0,
|
||||
|
@ -71,6 +93,8 @@ function love.keypressed(key)
|
|||
Menu:up()
|
||||
elseif key == "down" then
|
||||
Menu:down()
|
||||
elseif key == "space" then
|
||||
Menu:select()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ function MultiMenu:draw()
|
|||
-- draw all the options
|
||||
for idx, option in ipairs(self.options) do
|
||||
local y = y_anchor + idx * spacing
|
||||
self.font:draw(option, x, y)
|
||||
self.font:draw(option.text, x, y)
|
||||
end
|
||||
|
||||
-- cursor metric constants
|
||||
|
@ -59,4 +59,8 @@ function MultiMenu:down()
|
|||
end
|
||||
end
|
||||
|
||||
function MultiMenu:select()
|
||||
self.options[self.selected].callback()
|
||||
end
|
||||
|
||||
return MultiMenu
|
||||
|
|
Loading…
Reference in New Issue