89 lines
2.5 KiB
Lua
89 lines
2.5 KiB
Lua
local Animation = require "animation"
|
||
local Animator = require "animator"
|
||
local Atlas = require "atlas"
|
||
local Font = require "font"
|
||
local MultiMenu = require "multimenu"
|
||
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 leafRangerSprites = love.graphics.newImage("assets/leaf-ranger.png")
|
||
local leafRangerAtlas = Atlas(leafRangerSprites, 288, 128)
|
||
|
||
local function sprites(row, len, on_finish, next)
|
||
local start = (row - 1) * 22 + 1
|
||
local anim = Animation:new_spanned(leafRangerAtlas, start, start + len - 1)
|
||
return { animation = anim, on_finish = on_finish, next = next }
|
||
end
|
||
|
||
local states = {
|
||
idle = sprites(1, 12),
|
||
run = sprites(2, 10),
|
||
hurt = sprites(16, 6, "goto", "idle"),
|
||
death = sprites(17, 19, "stop"),
|
||
}
|
||
|
||
LeafRanger = Animator(states, "idle")
|
||
|
||
local options = {}
|
||
|
||
for name, state in pairs(states) do
|
||
options[#options + 1] = {
|
||
text = name,
|
||
callback = function() LeafRanger:setState(name) end,
|
||
}
|
||
end
|
||
|
||
Menu = MultiMenu(BlockyFont, options)
|
||
end
|
||
|
||
function love.draw()
|
||
push:start()
|
||
|
||
Menu:draw()
|
||
BlockyFont:draw("Hello, world!")
|
||
LeafRanger:draw(0, 0)
|
||
|
||
push:finish()
|
||
end
|
||
|
||
function love.update(dt)
|
||
LeafRanger:update(dt)
|
||
end
|
||
|
||
function love.keypressed(key)
|
||
if key == "up" then
|
||
Menu:up()
|
||
elseif key == "down" then
|
||
Menu:down()
|
||
elseif key == "space" then
|
||
Menu:select()
|
||
end
|
||
end
|
||
|
||
function love.resize(w, h)
|
||
return push:resize(w, h)
|
||
end
|