- [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
This commit is contained in:
@@ -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,6 +40,7 @@ animations = {
|
||||
},
|
||||
["hero_shoot"] = {
|
||||
cycle = {1,2,3},
|
||||
loop = false,
|
||||
frames = {
|
||||
{ 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 },
|
||||
@@ -43,12 +49,14 @@ animations = {
|
||||
},
|
||||
["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 },
|
||||
}
|
||||
|
||||
116
data/sprites.lua
116
data/sprites.lua
@@ -57,12 +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}))
|
||||
@@ -82,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]
|
||||
@@ -113,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
|
||||
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
|
||||
@@ -237,7 +304,28 @@ 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"
|
||||
@@ -253,6 +341,18 @@ sprites = {
|
||||
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
|
||||
@@ -315,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
|
||||
@@ -432,8 +534,10 @@ sprites = {
|
||||
print(sprite.current_frame)
|
||||
end
|
||||
local reversed = frame.reversed or false
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user