Compare commits

...

3 Commits

Author SHA1 Message Date
4575ca1316 - [FIX] Ajustat el offset de la llum de l'heroi
- [NEW] Animacions amb o sense loop
- [NEW] L'heroi perd energia al rebre colps i al final es mor
- [NEW] L'heroi cau a l'aigua i es mor directament
- [FIX] Al caure al aigua ja no pasa a l'habitació inexistent de baix
- [NEW] L'heroi parpadeja invulnerable després de rebre un colp
2026-03-04 14:03:48 +01:00
f6b99d7924 - [FIX] Si hi ha que ficar un offset en algun frame de animació, es fà des de la propia animació, no canviant la posició del personatge
- [NEW] rooms.reload()
- [FIX] Al tornar al editor, se recarrega tot de nou
- [NEW] Si se juga des de un mini de debug comença en l'editor. Si se juga des del mini normal comença en el joc.
2026-03-04 11:08:16 +01:00
8e5599506e - [NEW] Jump throttle, per a que no parega una taladradora quan te una paret sobre el cap 2026-03-04 10:20:35 +01:00
7 changed files with 160 additions and 52 deletions

View File

@@ -2,18 +2,21 @@
animations = {
["hero_stand"] = {
cycle = {1},
loop = false,
frames = {
{ frame={x=0,y=0,w=16,h=17}, wait=4 },
}
},
["hero_jump"] = {
cycle = {1},
loop = false,
frames = {
{ frame={x=32,y=0,w=16,h=17}, wait=4 },
}
},
["hero_walk"] = {
cycle = {1,2,1,3},
loop = true,
frames = {
{ frame={x=0,y=0,w=16,h=17}, wait=4 },
{ frame={x=16,y=0,w=16,h=17}, wait=4 },
@@ -22,12 +25,14 @@ animations = {
},
["hero_stairs_idle"] = {
cycle = {1},
loop = false,
frames = {
{ frame={x=48,y=0,w=16,h=17}, wait=4 }
}
},
["hero_stairs"] = {
cycle = {1,2},
loop = true,
frames = {
{ frame={x=48,y=0,w=16,h=17}, wait=4 },
{ frame={x=48,y=0,w=16,h=17}, wait=4, reversed=true }
@@ -35,20 +40,23 @@ animations = {
},
["hero_shoot"] = {
cycle = {1,2,3},
loop = false,
frames = {
{ frame={x=64,y=0,w=24,h=17}, wait=4 },
{ frame={x=88,y=0,w=24,h=17}, wait=2 },
{ frame={x=88,y=0,w=24,h=17}, wait=2 }
{ frame={x=64,y=0,w=24,h=17}, offset={flipped={x=-8,y=0}}, wait=4 },
{ frame={x=88,y=0,w=24,h=17}, offset={flipped={x=-8,y=0}}, wait=2 },
{ frame={x=88,y=0,w=24,h=17}, offset={flipped={x=-8,y=0}}, wait=2 }
}
},
["bullet"] = {
cycle = {1},
loop = false,
frames = {
{ frame={x=156,y=0,w=4,h=3}, wait=4 }
}
},
["mummy_walk"] = {
cycle = {1,2,1,3},
loop = true,
frames = {
{ frame={x=0,y=0,w=16,h=16}, wait=4 },
{ frame={x=16,y=0,w=16,h=16}, wait=4 },
@@ -57,6 +65,7 @@ animations = {
},
["mummy_dying"] = {
cycle = {1,2,3,4,5,6,7,6},
loop = false,
frames = {
{ frame={x=48,y=0,w=16,h=16}, wait=2 },
{ frame={x=64,y=0,w=16,h=16}, wait=2 },
@@ -69,12 +78,14 @@ animations = {
},
["mummy_dead"] = {
cycle = {1},
loop = false,
frames = {
{ 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},
loop = false,
frames = {
{ frame={x=48,y=0,w=16,h=16}, wait=2 },
{ frame={x=64,y=0,w=16,h=16}, wait=2 },
@@ -87,6 +98,7 @@ animations = {
},
["coin"] = {
cycle = {1,2,3,4,3,2},
loop = true,
frames = {
{ frame={x=0,y=0,w=8,h=8}, wait=2 },
{ frame={x=8,y=0,w=8,h=8}, wait=2 },
@@ -96,12 +108,14 @@ animations = {
},
["coin_picked"] = {
cycle = {1},
loop = false,
frames = {
{ frame={x=32,y=0,w=13,h=7}, wait=100 },
}
},
["brick"] = {
cycle = {1},
loop = false,
frames = {
{ frame={x=48,y=0,w=8,h=8}, wait=100 },
}

View File

@@ -63,7 +63,8 @@ game = {
game.apply_light()
if key.press(key.ESCAPE) or key.press(key.F9) then
rooms.retrieve_original_items()
rooms.reload()
sprites.add_from_room(rooms.pos.x, rooms.pos.y)
editor.enable()
elseif key.press(key.GRAVE) then
console.enable()

View File

@@ -21,7 +21,11 @@ function mini.init()
rooms.init()
shader.init("lynx.glsl")
editor.enable()
if sys.debug() then
editor.enable()
else
game.enable()
end
sprites.add_from_room(rooms.pos.x, rooms.pos.y)
end

View File

@@ -20,8 +20,7 @@ rooms = {
return (rooms.pos.x//20) + (rooms.pos.y//12) * 8
end,
init = function()
rooms.pos.x, rooms.pos.y = 0,4*12
reload = function()
if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end
rooms.surf_background = surf.load("rooms_background"..ROOM_FILE_EXT)
--rooms.surf_background = surf.new(20*8,12*8)
@@ -33,27 +32,12 @@ rooms = {
if rooms.surf_items ~= nil then surf.free(rooms.surf_items) end
rooms.surf_items = surf.load("rooms_items"..ROOM_FILE_EXT)
--rooms.surf_items = surf.new(20*8,12*8)
rooms.surf_original_items = surf.new(20*8,12*8)
rooms.update_original_items()
--surf.source(rooms.surf_items)
--surf.target(rooms.surf_original_items)
--draw.surf(0,0,160,96,0,0)
end,
init = function()
rooms.pos.x, rooms.pos.y = 0,4*12
rooms.reload()
sprites.init()
--map.surf(rooms.surf_background)
--for y=0,12*8 do
-- for x=0,20*8 do
-- map.tile(x,y,38)
-- end
--end
--map.surf(rooms.surf_foreground)
--map.tile(10,10,16)
--surf.save(rooms.surf_background, "data/rooms_background.bin")
--surf.save(rooms.surf_foreground, "data/rooms_foreground.bin")
--surf.save(rooms.surf_items, "data/rooms_items.bin")
end,
save = function()
@@ -143,16 +127,4 @@ rooms = {
pal.color(1, 1, 1, 1)
return "HOLA OTHER UNIT"
end,
retrieve_original_items = function()
surf.source(rooms.surf_original_items)
surf.target(rooms.surf_items)
draw.surf(0,0,160,96,0,0)
end,
update_original_items = function()
surf.source(rooms.surf_items)
surf.target(rooms.surf_original_items)
draw.surf(0,0,160,96,0,0)
end
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -57,11 +57,14 @@ sprites = {
surf = surf.load("morcus.gif"),
animation = "hero_stand",
ia = sprites.update_hero,
state = templates.ALIVE,
jumping = 0,
light = 100,
light_ox = 0,
light_oy = 0,
light_ox = 8,
light_oy = 8,
cooldown = 0,
jump_throttle = 0,
lives = 4,
stairs = false
}
--table.insert(sprites.list, templates.create("mummy", {pos={x=100, y=4*12*8+71},flipped=true}))
@@ -81,6 +84,7 @@ sprites = {
set_animation=function(sprite, animation)
if sprite.animation ~= animation then
sprite.animation_finished = nil
sprite.animation = animation
sprite.current_frame = 1
local cycle = animations[sprite.animation].cycle[1]
@@ -112,20 +116,84 @@ sprites = {
end,
update_sprite = function(sprite)
if sprite.animation_finished then return end
sprite.current_wait = sprite.current_wait - 1
if sprite.current_wait == 0 then
if sprite.current_frame < #animations[sprite.animation].cycle then
sprite.current_frame = sprite.current_frame + 1
else
sprite.current_frame = 1
if animations[sprite.animation].loop then
sprite.current_frame = 1
else
sprite.animation_finished = true
end
end
local cycle = animations[sprite.animation].cycle[sprite.current_frame]
sprite.current_wait = animations[sprite.animation].frames[cycle].wait
end
end,
hit_hero = function(live)
live = live or sprites.hero.lives-1
local light_table = {[0]=20, 30, 50, 80, 100}
local red_table = {[0]=0, 0.25, 0.5, 0.75, 1}
tweening.add(1,0,0.25,easing.linear,function(value,n,finished)palfade.fade_red(value)end)
local start_light = light_table[sprites.hero.lives]
local start_red = red_table[sprites.hero.lives]
local end_light = light_table[live]
local end_red = red_table[live]
sprites.hero.lives = live
tweening.add(start_light,end_light,1,easing.linear,function(value,n,finished)sprites.hero.light = value end)
tweening.add(start_red,end_red,1,easing.linear,function(value,n,finished)palfade.fade_reddish(value)end)
if sprites.hero.lives == 0 then
sprites.hero.state = templates.DEAD
sprites.hero.surf = surf.load("mummy.gif")
sprites.set_animation(sprites.hero, "mummy_dying")
sprites.hero.jumping = 0
sprites.hero.cooldown = 120
else
sprites.hero.state = templates.DYING
sprites.hero.cooldown = 60
end
end,
lights_out = function()
for i,spr in ipairs(sprites.list) do
if spr.light then
tweening.add(spr.light,0,0.5,easing.linear,
function(value,n,finished)
spr.light = value
if finished then
spr.light = nil
end
end
)
end
end
tweening.add(sprites.hero.light,0,0.5,easing.linear,
function(value,n,finished)
sprites.hero.light = value
if finished then
sprites.hero.light = nil
end
end
)
end,
update_mummy = function(spr)
if spr.state == templates.ALIVE then
if sprites.hero.state == templates.ALIVE then
local x1,y1,w1,h1 = util.aabb(spr) -- El meu aabb
local x2,y2,w2,h2 = util.aabb(sprites.hero) -- el aabb del heroi
-- Si toca al heroi...
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
sprites.hit_hero()
end
end
if spr.flipped then
local tx, ty = (spr.pos.x+3)>>3, (spr.pos.y+15)>>3
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then
@@ -236,8 +304,29 @@ sprites = {
end,
update_hero = function()
--game.draw_light(sprites.hero.pos.x, sprites.hero.pos.y,100)
if sprites.hero.state == templates.DEAD then
if sprites.hero.cooldown > 0 then
local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y+1)>>3
local tile_under_me1 = map.tile(tx1,ty+2)
local tile_under_me2 = map.tile(tx2,ty+2)
if tile_under_me1 == 0 and tile_under_me2 == 0 then
if rooms.pos.y<84 and ty+2>rooms.pos.y+11 then
game.change_room(0,1)
else
if sprites.hero.cooldown % 2 == 0 then
sprites.hero.pos.y = sprites.hero.pos.y + 1
end
end
end
sprites.hero.cooldown = sprites.hero.cooldown - 1
if sprites.hero.cooldown == 0 then
sprites.lights_out()
end
end
return
end
-- Update hero
local anim = "hero_stand"
local move_anim = "hero_walk"
@@ -247,12 +336,28 @@ sprites = {
sprites.hero.cooldown = sprites.hero.cooldown - 1
end
-- Si estem en jump_throttle desde l'ultim bot, decrementem el contador
if sprites.hero.jump_throttle > 0 then
sprites.hero.jump_throttle = sprites.hero.jump_throttle - 1
end
if sprites.hero.state == templates.DYING then
if (sprites.hero.cooldown//5) % 2 == 0 then
sprites.hero.invisible = true
else
sprites.hero.invisible = nil
end
if sprites.hero.cooldown == 0 then
sprites.hero.state = templates.ALIVE
sprites.hero.invisible = nil
end
end
-- si està en l'animació de disparar, no podem fer res i eixim ja
if sprites.hero.shooting then
-- A no ser que siga l'ultim frame, en tal cas tornem a estar de peu i au
if sprites.hero.current_frame==3 then
sprites.hero.shooting = false
if sprites.hero.flipped then sprites.hero.pos.x=sprites.hero.pos.x+8 end
sprites.set_animation(sprites.hero, "hero_stand")
else
return
@@ -274,6 +379,7 @@ sprites = {
end
else
sprites.hero.jumping = 0
sprites.hero.jump_throttle = 10
end
sprites.hero.jumping = sprites.hero.jumping - 1
else
@@ -309,15 +415,17 @@ sprites = {
else
-- SI NO ESTÀ EN UNES ESCALERES...
local tx1, txm, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+8)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y+1)>>3
--draw.rect(tx1<<3, (ty+2)<<3,8,8,8)
--draw.rect(tx2<<3, (ty+2)<<3,8,8,28)
-- SI ESTÀ CAIGUENT...
local tile_under_me1 = map.tile(tx1,ty+2)
local tile_under_me2 = map.tile(tx2,ty+2)
if tile_under_me1 == 0 and tile_under_me2 == 0 then
if ty+2>rooms.pos.y+11 then
if rooms.pos.y<84 and ty+2>rooms.pos.y+11 then
game.change_room(0,1)
else
if sprites.hero.pos.y >= 742 then
sprites.hit_hero(0)
return
end
sprites.hero.pos.y = sprites.hero.pos.y + 2
end
else
@@ -346,17 +454,15 @@ sprites = {
end
end
-- SI POLSA BOTAR...
if key.down(key.X) or pad.down(pad.A) then
if ( key.down(key.X) or pad.down(pad.A) ) and sprites.hero.jump_throttle == 0 then
sprites.hero.jumping = 17
-- SI POLSA DISPAR...
elseif (sprites.hero.cooldown==0) and (key.down(key.Z) or pad.down(pad.B)) then
sprites.hero.shooting = true
sprites.hero.cooldown = 20
local x = sprites.hero.flipped and sprites.hero.pos.x+8 or sprites.hero.pos.x-8
local bullet = templates.create("bullet", {pos={x=sprites.hero.pos.x, y=sprites.hero.pos.y+7}, flipped=sprites.hero.flipped})
table.insert(sprites.list, bullet)
if sprites.hero.flipped then sprites.hero.pos.x=sprites.hero.pos.x-8 end
anim = "hero_shoot"
end
end
@@ -415,12 +521,23 @@ sprites = {
draw_sprite = function(sprite)
local cycle = animations[sprite.animation].cycle[sprite.current_frame]
local frame = animations[sprite.animation].frames[cycle]
local ox, oy = 0, 0
if frame.offset then
if sprite.flipped then
if frame.offset.flipped then ox,oy = frame.offset.flipped.x,frame.offset.flipped.y end
else
if frame.offset.normal then ox,oy = frame.offset.normal.x,frame.offset.normal.y end
end
end
if not frame then
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))
if not sprite.invisible then
surf.source(sprite.surf)
draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x+ox, sprite.pos.y+oy, frame.frame.w, frame.frame.h, (not reversed) ~= (not sprite.flipped))
end
if cheats.showaabb then
local x,y,w,h = util.aabb(sprite)
draw.rect(x,y,w,h,8)