Files
YataiDON14/Scripts/global/jy_chara.lua
T
2026-10-02 14:07:44 +08:00

39 lines
1.3 KiB
Lua

local JyChara = {}
JyChara.__index = JyChara
JyChara.FRAMES = { idle = 8, combo = 1, gogo = 16, spin = 8, clear = 2, fail = 2, misc = 2 }
local SPEED = { idle = 0.25, combo = 1, gogo = 0.5, spin = 1, clear = 1, fail = 1, misc = 1 }
JyChara.SIZE = 384
function JyChara.new(screen)
local self = setmetatable({}, JyChara)
pcall(tex.load_folder, screen, "jy_chara")
self.t = {}
for st in pairs(JyChara.FRAMES) do
self.t[st] = tex.get_texture(screen .. "/jy_chara/" .. st)
end
return self
end
function JyChara.frame_at(state, beat)
local n = JyChara.FRAMES[state]
return math.floor(math.max(0, beat) * n * SPEED[state]) % n
end
-- one frame with the 384 px frame's top-left at (x, y), scaled by s; clip_y (optional) = the screen y
-- below which nothing is drawn
function JyChara:draw(state, frame, x, y, s, fade, clip_y)
local t = self.t[state]
if not t then return end
s = s or 1
local N = JyChara.SIZE
local h = N
if clip_y then h = math.min(N, (clip_y - y) / s) end
if h <= 0 then return end
tex.draw_texture(t, { frame = frame % JyChara.FRAMES[state], x = x, y = y,
src = { x = 0, y = 0, width = N, height = h },
x2 = N * s - N, y2 = h * s - N, fade = fade or 1.0 })
end
return JyChara