- [NEW] Cada sprite pot usar el seu propi gif

- [NEW] Monedes
This commit is contained in:
2025-11-16 16:51:47 +01:00
parent b263d989d0
commit e366209f46
11 changed files with 65 additions and 23 deletions

View File

@@ -44,45 +44,54 @@ animations = {
["bullet"] = {
cycle = {1},
frames = {
{ frame={x=0,y=19,w=4,h=3}, wait=4 }
{ frame={x=156,y=0,w=4,h=3}, wait=4 }
}
},
["mummy_walk"] = {
cycle = {1,2,1,3},
frames = {
{ frame={x=0,y=24,w=16,h=16}, wait=4 },
{ frame={x=16,y=24,w=16,h=16}, wait=4 },
{ frame={x=32,y=24,w=16,h=16}, wait=4 }
{ frame={x=0,y=0,w=16,h=16}, wait=4 },
{ frame={x=16,y=0,w=16,h=16}, wait=4 },
{ frame={x=32,y=0,w=16,h=16}, wait=4 }
}
},
["mummy_dying"] = {
cycle = {1,2,3,4,5,6,7,6},
frames = {
{ frame={x=48,y=24,w=16,h=16}, wait=2 },
{ frame={x=64,y=24,w=16,h=16}, wait=2 },
{ frame={x=80,y=24,w=16,h=16}, wait=2 },
{ frame={x=96,y=24,w=16,h=16}, wait=2 },
{ frame={x=112,y=24,w=16,h=16}, wait=2 },
{ frame={x=128,y=24,w=16,h=16}, wait=4 },
{ frame={x=144,y=24,w=16,h=16}, wait=2 }
{ frame={x=48,y=0,w=16,h=16}, wait=2 },
{ frame={x=64,y=0,w=16,h=16}, wait=2 },
{ frame={x=80,y=0,w=16,h=16}, wait=2 },
{ frame={x=96,y=0,w=16,h=16}, wait=2 },
{ frame={x=112,y=0,w=16,h=16}, wait=2 },
{ frame={x=128,y=0,w=16,h=16}, wait=4 },
{ frame={x=144,y=0,w=16,h=16}, wait=2 }
}
},
["mummy_dead"] = {
cycle = {1},
frames = {
{ frame={x=128,y=24,w=16,h=16}, wait=100 },
{ frame={x=128,y=0,w=16,h=16}, wait=100 },
}
},
["mummy_undying"] = {
cycle = {7,6,7,6,7,6,7,6,5,4,3,2,1},
frames = {
{ frame={x=48,y=24,w=16,h=16}, wait=2 },
{ frame={x=64,y=24,w=16,h=16}, wait=2 },
{ frame={x=80,y=24,w=16,h=16}, wait=2 },
{ frame={x=96,y=24,w=16,h=16}, wait=2 },
{ frame={x=112,y=24,w=16,h=16}, wait=2 },
{ frame={x=128,y=24,w=16,h=16}, wait=1 },
{ frame={x=128,y=40,w=16,h=16}, wait=1 }
{ frame={x=48,y=0,w=16,h=16}, wait=2 },
{ frame={x=64,y=0,w=16,h=16}, wait=2 },
{ frame={x=80,y=0,w=16,h=16}, wait=2 },
{ frame={x=96,y=0,w=16,h=16}, wait=2 },
{ frame={x=112,y=0,w=16,h=16}, wait=2 },
{ frame={x=128,y=0,w=16,h=16}, wait=1 },
{ frame={x=160,y=0,w=16,h=16}, wait=1 }
}
},
["coin"] = {
cycle = {1,2,3,4,3,2},
frames = {
{ frame={x=0,y=0,w=8,h=8}, wait=2 },
{ frame={x=8,y=0,w=8,h=8}, wait=2 },
{ frame={x=16,y=0,w=8,h=8}, wait=2 },
{ frame={x=24,y=0,w=8,h=8}, wait=2 }
}
},
}

View File

@@ -4,7 +4,7 @@ items = {
visual = {x=0,y=24,w=16,h=16}
},
[2] = {
name="mummy2",
visual = {x=16,y=24,w=16,h=16}
name="coin",
visual = {x=0,y=40,w=8,h=8}
}
}

BIN
data/misc.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B

BIN
data/morcus.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 B

BIN
data/mummy.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1001 B

After

Width:  |  Height:  |  Size: 1004 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -54,6 +54,7 @@ sprites = {
current_frame = 1,
current_wait = 1,
flipped = false,
surf = surf.load("morcus.gif"),
animation = "hero_stand",
ia = sprites.update_hero,
jumping = 0,
@@ -185,6 +186,22 @@ sprites = {
end
end,
update_coin = function(spr)
local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3
local x1,y1,w1,h1 = util.aabb(spr)
for i,v in ipairs(sprites.list) do
if v.enemy and v.state ~= templates.DEAD then
local x2,y2,w2,h2 = util.aabb(v)
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
if v.state == templates.ALIVE then v.state = templates.DYING end
sprites.remove(spr)
return
end
end
end
end,
update_hero = function()
-- Update hero
local anim = "hero_stand"
@@ -319,7 +336,6 @@ sprites = {
draw = function(ignore_selected)
editor.item_hovered = nil
local mx,my = mouse.pos()
surf.source(surf_sprites)
if editor.item_selected or editor.layer~=LAYER_ITEMS then ignore_selected = true end
for i,v in ipairs(sprites.list) do
if not ignore_selected and app.update == editor.update and mx>=v.pos.x and mx<=v.pos.x+v.size.w and my>=v.pos.y and my<=v.pos.y+v.size.h then
@@ -339,6 +355,7 @@ sprites = {
print(sprite.current_frame)
end
local reversed = frame.reversed or false
surf.source(sprite.surf)
draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, frame.frame.w, frame.frame.h, (not reversed) ~= (not sprite.flipped))
local x,y,w,h = util.aabb(sprite)
--draw.rect(x,y,w,h,8)
@@ -351,6 +368,7 @@ sprites = {
local frame = animations[sprite.animation].frames[cycle]
local reversed = frame.reversed or false
local x, y, w, h, sx, sy, f = sprite.pos.x, sprite.pos.y, frame.frame.w, frame.frame.h, frame.frame.x, frame.frame.y, (not reversed) ~= (not sprite.flipped)
surf.source(sprite.surf)
draw.surf(sx, sy, w, h, x-1, y-1, w, h, f)
draw.surf(sx, sy, w, h, x, y-1, w, h, f)
draw.surf(sx, sy, w, h, x+1, y-1, w, h, f)

View File

@@ -10,11 +10,12 @@ templates = {
sprite = {
type = type,
pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=16,h=17 },
size = { w=16,h=16 },
bbo = { left=3, top=2, right=3, bottom=0 },
current_frame = 1,
current_wait = 1,
flipped = options.flipped,
surf = surf.load("mummy.gif"),
animation = "mummy_walk",
state = templates.ALIVE,
enemy = true,
@@ -30,9 +31,23 @@ templates = {
current_frame = 1,
current_wait = 1,
flipped = options.flipped,
surf = surf.load("morcus.gif"),
animation = "bullet",
ia = sprites.update_bullet
}
elseif type == "coin" then
sprite = {
type = type,
pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=8,h=8 },
bbo = { left=0, top=0, right=0, bottom=0 },
current_frame = 1,
current_wait = 1,
flipped = options.flipped,
surf = surf.load("misc.gif"),
animation = "coin",
ia = sprites.update_coin
}
else
error("Template not recognized")
end