Draw MultiMenu with Font

This commit is contained in:
mars 2023-04-19 16:37:22 -04:00
parent 4bbdb426ea
commit eb159db4b5
3 changed files with 16 additions and 11 deletions

View File

@ -1,5 +1,6 @@
local Atlas = require "atlas"
---@class Font
---A set of character sprites that can be drawn as strings.
local Font = Atlas:extend()

View File

@ -14,8 +14,6 @@ local pushOpts = {
push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, pushOpts)
function love.load()
Menu = MultiMenu({ "Fight", "Use", "Pkmn", "Flee" })
local blockyFont = love.graphics.newImage("assets/small-blocky-font.png")
local blockFontChars = {
@ -28,6 +26,7 @@ function love.load()
}
BlockyFont = Font(blockyFont, 8, 8, blockFontChars)
Menu = MultiMenu(BlockyFont, { "Fight", "Use", "Pkmn", "Flee" })
local leafRanger = love.graphics.newImage("assets/leaf-ranger.png")

View File

@ -3,32 +3,37 @@ local Object = require "lib/classic"
---@class MultiMenu
local MultiMenu = Object:extend()
function MultiMenu:new(options)
---Creates a new multimenu.
---@param font Font
---@param options table
function MultiMenu:new(font, options)
self.font = font
self.options = options
self.selected = 1
end
function MultiMenu:draw()
-- option drawing constants
local x = 400
local y_anchor = 200
local spacing = 50
local x = 20
local y_anchor = 50
local spacing = 10
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)
self.font:draw(option, x, y)
end
-- cursor metric constants
local cursor_width = 10
local cursor_depth = 20
local cursor_spacing = 20
local cursor_width = 4
local cursor_depth = 8
local cursor_spacing = 8
local cursor_offset = 4
-- calculate the cursor's position
local cursor_x = x - cursor_spacing
local cursor_y = y_anchor + spacing * self.selected
local cursor_y = y_anchor + cursor_offset + spacing * self.selected
-- draw the cursor
love.graphics.polygon("fill",