Compare commits

...

3 Commits

Author SHA1 Message Date
mars e731fc4c38 Add NineSlice and draw in main 2023-04-20 13:15:38 -04:00
mars 6f4b3b50e4 Add assets/flat-ui.png 2023-04-20 13:11:10 -04:00
mars 7c06d99d27 Remove old Leaf Ranger code from main 2023-04-20 12:42:33 -04:00
4 changed files with 89 additions and 16 deletions

View File

@ -1,5 +1,6 @@
- `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/flat-ui.png` is ilcensed under CC-BY 4.0 and was created by Crusenho Agus Hennihuno (source: https://crusenho.itch.io/complete-gui-essential-pack)
- `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/push.lua` is licensed under the MIT license and was created by Ulysse Ramage (source: https://github.com/Ulydev/push)

BIN
assets/flat-ui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -3,6 +3,7 @@ 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"
@ -30,23 +31,19 @@ function love.load()
BlockyFont = Font(blockyFont, 8, 8, blockFontChars)
local leafRangerSprites = love.graphics.newImage("assets/leaf-ranger.png")
local leafRangerAtlas = Atlas(leafRangerSprites, 288, 128)
local uiAtlas = Atlas(love.graphics.newImage("assets/flat-ui.png"), 32, 32)
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")
Window = NineSlice(uiAtlas, {
tl = 26,
top = 27,
tr = 28,
left = 50,
center = 51,
right = 52,
bl = 74,
bottom = 75,
br = 76,
})
local options = {}
@ -73,6 +70,7 @@ end
function love.draw()
push:start()
Window:draw(100, 100, 5, 5)
BlockyFont:draw("Hello, world!")
ActiveUnit:draw()

74
nine_slice.lua Normal file
View File

@ -0,0 +1,74 @@
local Object = require "lib/classic"
local NineSlice = Object:extend()
function NineSlice:new(atlas, sprites)
self.atlas = atlas
self.sprites = sprites
end
function NineSlice:draw(x, y, width, height)
local function draw(sprite, tx, ty)
local atlas = self.atlas
local sw = atlas.sw
local sh = atlas.sh
local gx = x + tx * sw
local gy = y + ty * sh
if sprite then
love.graphics.draw(atlas.meshes[sprite], gx, gy)
else
love.graphics.rectangle("fill", gx, gy, sw, sh)
end
end
--common variables
local right = width - 1
local bottom = height - 1
local sprites = self.sprites
if width == 1 and height == 1 then
draw(sprites.only_center, 0, 0)
elseif width == 1 then
draw(sprites.vert_top, 0, 0)
draw(sprites.vert_bottom, 0, bottom)
for cy = 1, bottom - 1 do
draw(sprites.vert_center, 0, cy)
end
elseif height == 1 then
draw(sprites.hori_left, 0, 0)
draw(sprites.hori_right, right, 0)
for cx = 1, right - 1 do
draw(sprites.hori_center, cx, 0)
end
else
--draw corners
draw(sprites.tl, 0, 0)
draw(sprites.tr, right, 0)
draw(sprites.bl, 0, bottom)
draw(sprites.br, right, bottom)
--horizontal edges
for cx = 1, right - 1 do
draw(sprites.top, cx, 0)
draw(sprites.bottom, cx, bottom)
end
--vertical edges
for cy = 1, bottom - 1 do
draw(sprites.left, 0, cy)
draw(sprites.right, right, cy)
end
--draw center
for cx = 1, right - 1 do
for cy = 1, bottom - 1 do
draw(sprites.center, cx, cy)
end
end
end
end
return NineSlice