Compare commits
2 Commits
9dc81e02e3
...
999d1b41c1
Author | SHA1 | Date |
---|---|---|
mars | 999d1b41c1 | |
mars | 80310a942c |
|
@ -1,4 +1,5 @@
|
||||||
- `assets/leaf-ranger.png` is licensed under CC-BY 4.0 and was created by chierit (source: https://chierit.itch.io/elementals-leaf-ranger)
|
- `assets/leaf-ranger.png` is licensed under CC-BY 4.0 and was created by chierit (source: https://chierit.itch.io/elementals-leaf-ranger)
|
||||||
|
- `assets/bringer-of-death.png` was created by clembed (source: https://clembod.itch.io/bringer-of-death-free)
|
||||||
- `assets/small-blocky-font.png` is licensed under CC-BY 3.0 and was created by Jerom (source: https://opengameart.org/content/small-blocky-font)
|
- `assets/small-blocky-font.png` is licensed under CC-BY 3.0 and was created by Jerom (source: https://opengameart.org/content/small-blocky-font)
|
||||||
- `lib/classic.lua` is licensed under the MIT license and was created by rxi (source: https://raw.githubusercontent.com/rxi/classic/master/classic.lua)
|
- `lib/classic.lua` is licensed under the MIT license and was created by rxi (source: https://raw.githubusercontent.com/rxi/classic/master/classic.lua)
|
||||||
- `lib/push.lua` is licensed under the MIT license and was created by Ulysse Ramage (source: https://github.com/Ulydev/push)
|
- `lib/push.lua` is licensed under the MIT license and was created by Ulysse Ramage (source: https://github.com/Ulydev/push)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
53
main.lua
53
main.lua
|
@ -3,6 +3,7 @@ local Animator = require "animator"
|
||||||
local Atlas = require "atlas"
|
local Atlas = require "atlas"
|
||||||
local Font = require "font"
|
local Font = require "font"
|
||||||
local MultiMenu = require "multimenu"
|
local MultiMenu = require "multimenu"
|
||||||
|
local Units = require "units"
|
||||||
local push = require "lib/push"
|
local push = require "lib/push"
|
||||||
|
|
||||||
local gameWidth, gameHeight = 480, 360
|
local gameWidth, gameHeight = 480, 360
|
||||||
|
@ -49,37 +50,69 @@ function love.load()
|
||||||
|
|
||||||
local options = {}
|
local options = {}
|
||||||
|
|
||||||
for name, state in pairs(states) do
|
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] = {
|
options[#options + 1] = {
|
||||||
text = name,
|
text = unit.name,
|
||||||
callback = function() LeafRanger:setState(name) end,
|
callback = function() StateMenu = MultiMenu(BlockyFont, state_menu) end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
Menu = MultiMenu(BlockyFont, options)
|
UnitMenu = MultiMenu(BlockyFont, options)
|
||||||
|
ActiveUnit = Animator(Units[1].states, "idle")
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
push:start()
|
push:start()
|
||||||
|
|
||||||
Menu:draw()
|
|
||||||
BlockyFont:draw("Hello, world!")
|
BlockyFont:draw("Hello, world!")
|
||||||
LeafRanger:draw(0, 0)
|
ActiveUnit:draw()
|
||||||
|
|
||||||
|
if StateMenu then
|
||||||
|
StateMenu:draw()
|
||||||
|
else
|
||||||
|
UnitMenu:draw()
|
||||||
|
end
|
||||||
|
|
||||||
push:finish()
|
push:finish()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
LeafRanger:update(dt)
|
ActiveUnit:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
|
local menu
|
||||||
|
|
||||||
|
if StateMenu then
|
||||||
|
menu = StateMenu
|
||||||
|
else
|
||||||
|
menu = UnitMenu
|
||||||
|
end
|
||||||
|
|
||||||
|
local changed = false
|
||||||
if key == "up" then
|
if key == "up" then
|
||||||
Menu:up()
|
menu:up()
|
||||||
|
changed = true
|
||||||
elseif key == "down" then
|
elseif key == "down" then
|
||||||
Menu:down()
|
menu:down()
|
||||||
|
changed = true
|
||||||
elseif key == "space" then
|
elseif key == "space" then
|
||||||
Menu:select()
|
menu:select()
|
||||||
|
elseif key == "escape" then
|
||||||
|
StateMenu = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if changed and not StateMenu then
|
||||||
|
ActiveUnit = Animator(Units[UnitMenu.selected].states, "idle")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
local Animation = require "animation"
|
||||||
|
local Atlas = require "atlas"
|
||||||
|
|
||||||
|
local function spannedState(atlas, start, len, on_finish, next)
|
||||||
|
local animation = Animation:new_spanned(atlas, start, start + len - 1)
|
||||||
|
return { animation = animation, on_finish = on_finish, next = next }
|
||||||
|
end
|
||||||
|
|
||||||
|
local function rowState(atlas, row, len, on_finish, next)
|
||||||
|
local start = (row - 1) * atlas.w + 1
|
||||||
|
return spannedState(atlas, start, len, on_finish, next)
|
||||||
|
end
|
||||||
|
|
||||||
|
local leafRanger = Atlas(love.graphics.newImage("assets/leaf-ranger.png"), 288, 128)
|
||||||
|
local bringerOfDeath = Atlas(love.graphics.newImage("assets/bringer-of-death.png"), 140, 93)
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
name = "Leaf Ranger",
|
||||||
|
states = {
|
||||||
|
idle = rowState(leafRanger, 1, 12),
|
||||||
|
run = rowState(leafRanger, 2, 10),
|
||||||
|
hurt = rowState(leafRanger, 16, 6, "goto", "idle"),
|
||||||
|
death = rowState(leafRanger, 17, 19, "stop"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "Bringer of Death",
|
||||||
|
states = {
|
||||||
|
idle = rowState(bringerOfDeath, 1, 8),
|
||||||
|
walk = rowState(bringerOfDeath, 2, 8),
|
||||||
|
attack = rowState(bringerOfDeath, 3, 10, "goto", "idle"),
|
||||||
|
hurt = spannedState(bringerOfDeath, 27, 3, "goto", "idle"),
|
||||||
|
death = spannedState(bringerOfDeath, 30, 10, "stop"),
|
||||||
|
cast = spannedState(bringerOfDeath, 40, 9, "goto", "idle"),
|
||||||
|
spell = spannedState(bringerOfDeath, 49, 16, "stop"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue