120 lines
2.9 KiB
Lua
120 lines
2.9 KiB
Lua
local Animation = require "animation"
|
||
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 blockyFont = love.graphics.newImage("assets/small-blocky-font.png")
|
||
|
||
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(blockyFont, 8, 8, blockFontChars)
|
||
|
||
local uiAtlas = Atlas(love.graphics.newImage("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) end,
|
||
}
|
||
end
|
||
|
||
UnitMenu = MultiMenu(BlockyFont, options)
|
||
ActiveUnit = Animator(Units[1].states, "idle")
|
||
end
|
||
|
||
function love.draw()
|
||
push:start()
|
||
|
||
Window:draw(100, 100, 5, 5)
|
||
BlockyFont:draw("Hello, world!")
|
||
ActiveUnit:draw()
|
||
|
||
if StateMenu then
|
||
StateMenu:draw()
|
||
else
|
||
UnitMenu: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
|