local Animator = require "animator" local Atlas = require "atlas" local Font = require "font" local MultiMenu = require "multimenu" local NineSlice = require "nine_slice" local Units = require "units" local push = require "lib/push" local gameWidth, gameHeight = 480, 360 local windowWidth, windowHeight = love.window.getDesktopDimensions() windowWidth, windowHeight = windowWidth * .7, windowHeight * .7 --make the window a bit smaller than the screen itself local pushOpts = { fullscreen = false, resizable = true, } push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, pushOpts) function love.load() local blockFontChars = { " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "×", "+", ",", "-", ".", "/", --first line "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", --second line "@", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", --third line "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "[", "\\", "]", "^", "_", --fourth line "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", --third line "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "{", "|", "}", "~", --fourth line } BlockyFont = Font("assets/small-blocky-font.png", 8, 8, blockFontChars) local uiAtlas = Atlas("assets/flat-ui.png", 32, 32) Window = NineSlice(uiAtlas, { tl = 26, top = 27, tr = 28, left = 50, center = 51, right = 52, bl = 74, bottom = 75, br = 76, }) local options = {} for idx, unit in ipairs(Units) do local state_menu = {} for name, state in pairs(unit.states) do state_menu[#state_menu + 1] = { text = name, callback = function() ActiveUnit:setState(name) end } end options[#options + 1] = { text = unit.name, callback = function() StateMenu = MultiMenu(BlockyFont, state_menu, 32, 32, Window) end, } end UnitMenu = MultiMenu(BlockyFont, options, 16, 16, Window) ActiveUnit = Animator(Units[1].states, "idle") end function love.draw() push:start() BlockyFont:draw("Hello, world!") ActiveUnit:draw(240, 180) UnitMenu:draw() if StateMenu then StateMenu:draw() end push:finish() end function love.update(dt) ActiveUnit:update(dt) end function love.keypressed(key) local menu if StateMenu then menu = StateMenu else menu = UnitMenu end local changed = false if key == "up" then menu:up() changed = true elseif key == "down" then menu:down() changed = true elseif key == "space" then menu:select() elseif key == "escape" then StateMenu = nil end if changed and not StateMenu then ActiveUnit = Animator(Units[UnitMenu.selected].states, "idle") end end function love.resize(w, h) return push:resize(w, h) end