This commit is contained in:
45
inc/sprite/sprite.manager.lua
Normal file
45
inc/sprite/sprite.manager.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
local _sprites = {}
|
||||
|
||||
function Sprite.register(sprite_data)
|
||||
if not sprite_data or not sprite_data.id then
|
||||
trace("Error: Invalid sprite object registered (missing id)!")
|
||||
return
|
||||
end
|
||||
if _sprites[sprite_data.id] then
|
||||
trace("Warning: Overwriting sprite with id: " .. sprite_data.id)
|
||||
end
|
||||
_sprites[sprite_data.id] = sprite_data
|
||||
end
|
||||
|
||||
function Sprite.show(id, x, y, colorkey, scale, flip_x, flip_y, rot)
|
||||
local sprite_data = _sprites[id]
|
||||
if not sprite_data then
|
||||
trace("Error: No sprite found with id: " .. id)
|
||||
return
|
||||
end
|
||||
|
||||
-- Use provided parameters, or fall back to sprite_data, then to defaults
|
||||
colorkey = colorkey or sprite_data.colorkey or 0 -- Default colorkey (transparent)
|
||||
scale = scale or sprite_data.scale or 1 -- Default scale
|
||||
flip_x = flip_x or sprite_data.flip_x or 0 -- Default flip_x (no flip)
|
||||
flip_y = flip_y or sprite_data.flip_y or 0 -- Default flip_y (no flip)
|
||||
rot = rot or sprite_data.rot or 0 -- Default rot (no rotation)
|
||||
|
||||
if sprite_data.sprites then -- Complex sprite
|
||||
for i = 1, #sprite_data.sprites do
|
||||
local sub_sprite = sprite_data.sprites[i]
|
||||
spr(
|
||||
sub_sprite.s,
|
||||
x + (sub_sprite.x_offset or 0),
|
||||
y + (sub_sprite.y_offset or 0),
|
||||
sub_sprite.colorkey or colorkey,
|
||||
sub_sprite.scale or scale,
|
||||
sub_sprite.flip_x or flip_x,
|
||||
sub_sprite.flip_y or flip_y,
|
||||
sub_sprite.rot or rot
|
||||
)
|
||||
end
|
||||
else -- Simple sprite
|
||||
spr(sprite_data.s, x, y, colorkey, scale, flip_x, flip_y, rot)
|
||||
end
|
||||
end
|
||||
17
inc/sprite/sprite.norman.lua
Normal file
17
inc/sprite/sprite.norman.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
Sprite.register({
|
||||
id = "norman",
|
||||
sprites = {
|
||||
-- Body
|
||||
{ s = 0, x_offset = 0, y_offset = 0 },
|
||||
-- Head
|
||||
{ s = 1, x_offset = 0, y_offset = -8 },
|
||||
-- Left Arm
|
||||
{ s = 2, x_offset = -4, y_offset = 4 },
|
||||
-- Right Arm
|
||||
{ s = 3, x_offset = 4, y_offset = 4, flip_x = 1 }, -- Flipped arm
|
||||
-- Left Leg
|
||||
{ s = 4, x_offset = -2, y_offset = 8 },
|
||||
-- Right Leg
|
||||
{ s = 5, x_offset = 2, y_offset = 8, flip_x = 1 } -- Flipped leg
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user