evil-jrpg/main.lua

117 lines
2.8 KiB
Lua
Raw Normal View History

2023-04-20 03:05:25 +00:00
local Animator = require "animator"
2023-04-16 20:30:39 +00:00
local Atlas = require "atlas"
2023-04-16 21:19:45 +00:00
local Font = require "font"
2023-04-19 20:33:18 +00:00
local MultiMenu = require "multimenu"
2023-04-20 17:15:38 +00:00
local NineSlice = require "nine_slice"
2023-04-20 15:52:35 +00:00
local Units = require "units"
2023-04-16 20:39:57 +00:00
local push = require "lib/push"
2023-04-19 21:25:39 +00:00
local gameWidth, gameHeight = 480, 360
2023-04-16 20:39:57 +00:00
local windowWidth, windowHeight = love.window.getDesktopDimensions()
2023-04-16 21:19:45 +00:00
windowWidth, windowHeight = windowWidth * .7, windowHeight * .7 --make the window a bit smaller than the screen itself
2023-04-16 20:39:57 +00:00
local pushOpts = {
fullscreen = false,
resizable = true,
}
push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, pushOpts)
2023-04-16 20:30:39 +00:00
2023-04-11 03:14:24 +00:00
function love.load()
2023-04-16 21:19:45 +00:00
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
}
2023-04-21 01:19:17 +00:00
BlockyFont = Font("assets/small-blocky-font.png", 8, 8, blockFontChars)
2023-04-16 21:56:11 +00:00
2023-04-21 01:19:17 +00:00
local uiAtlas = Atlas("assets/flat-ui.png", 32, 32)
2023-04-20 17:15:38 +00:00
Window = NineSlice(uiAtlas, {
tl = 26,
top = 27,
tr = 28,
left = 50,
center = 51,
right = 52,
bl = 74,
bottom = 75,
br = 76,
})
local options = {}
2023-04-20 15:52:35 +00:00
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] = {
2023-04-20 15:52:35 +00:00
text = unit.name,
callback = function()
StateMenu = MultiMenu(BlockyFont, state_menu, 32, 32, Window)
end,
}
end
UnitMenu = MultiMenu(BlockyFont, options, 16, 16, Window)
2023-04-20 15:52:35 +00:00
ActiveUnit = Animator(Units[1].states, "idle")
2023-04-11 03:14:24 +00:00
end
function love.draw()
2023-04-16 20:39:57 +00:00
push:start()
2023-04-16 21:19:45 +00:00
BlockyFont:draw("Hello, world!")
2023-04-21 01:11:56 +00:00
ActiveUnit:draw(240, 180)
UnitMenu:draw()
2023-04-20 15:52:35 +00:00
if StateMenu then
StateMenu:draw()
end
2023-04-16 21:56:11 +00:00
2023-04-16 20:39:57 +00:00
push:finish()
2023-04-11 03:14:24 +00:00
end
2023-04-16 21:56:11 +00:00
function love.update(dt)
2023-04-20 15:52:35 +00:00
ActiveUnit:update(dt)
2023-04-16 21:56:11 +00:00
end
2023-04-11 03:14:24 +00:00
function love.keypressed(key)
2023-04-20 15:52:35 +00:00
local menu
if StateMenu then
menu = StateMenu
else
menu = UnitMenu
end
local changed = false
2023-04-11 03:14:24 +00:00
if key == "up" then
2023-04-20 15:52:35 +00:00
menu:up()
changed = true
2023-04-11 03:14:24 +00:00
elseif key == "down" then
2023-04-20 15:52:35 +00:00
menu:down()
changed = true
elseif key == "space" then
2023-04-20 15:52:35 +00:00
menu:select()
elseif key == "escape" then
StateMenu = nil
end
if changed and not StateMenu then
ActiveUnit = Animator(Units[UnitMenu.selected].states, "idle")
2023-04-11 03:14:24 +00:00
end
end
2023-04-16 20:39:57 +00:00
function love.resize(w, h)
return push:resize(w, h)
end