diff --git a/data/animations.lua b/data/animations.lua index 7ff85c7..a3aa65a 100644 --- a/data/animations.lua +++ b/data/animations.lua @@ -130,4 +130,39 @@ animations = { { frame={x=24,y=0,w=8,h=16}, wait=2 } } }, + ["clau"] = { + cycle = {1}, + loop = false, + frames = { + { frame={x=0,y=0,w=16,h=8}, wait=100 }, + } + }, + ["porta"] = { + cycle = {1}, + loop = false, + frames = { + { frame={x=16,y=0,w=8,h=16}, wait=100 }, + } + }, + ["porta_obrint"] = { + cycle = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, + loop = false, + frames = { + { frame={x=16,y=1,w=8,h=15}, wait=1 }, + { frame={x=16,y=2,w=8,h=14}, wait=1 }, + { frame={x=16,y=3,w=8,h=13}, wait=1 }, + { frame={x=16,y=4,w=8,h=12}, wait=1 }, + { frame={x=16,y=5,w=8,h=11}, wait=1 }, + { frame={x=16,y=6,w=8,h=10}, wait=1 }, + { frame={x=16,y=7,w=8,h=9}, wait=1 }, + { frame={x=16,y=8,w=8,h=8}, wait=1 }, + { frame={x=16,y=9,w=8,h=7}, wait=1 }, + { frame={x=16,y=10,w=8,h=6}, wait=1 }, + { frame={x=16,y=11,w=8,h=5}, wait=1 }, + { frame={x=16,y=12,w=8,h=4}, wait=1 }, + { frame={x=16,y=13,w=8,h=3}, wait=1 }, + { frame={x=16,y=14,w=8,h=2}, wait=1 }, + { frame={x=16,y=15,w=8,h=1}, wait=1 }, + } + }, } \ No newline at end of file diff --git a/data/blava.gif b/data/blava.gif new file mode 100644 index 0000000..b0af606 Binary files /dev/null and b/data/blava.gif differ diff --git a/data/editor.lua b/data/editor.lua index f95ba55..6d3e04d 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -299,9 +299,13 @@ editor = { local mx, my = mouse.pos() local x,y = 0,0 for i,k in pairs(items) do - local w = math.max(k.visual.w, #k.name*4) + local w = math.max(k.visual.w, #k.label*4) + if x+w > 160 then + y=y+32 + x=0 + end local ox = (w-k.visual.w)/2 - draw.text(k.name, x, y, 15) + draw.text(k.label, x, y, 15) draw.surf(k.visual.x, k.visual.y, k.visual.w, k.visual.h, x+ox, y+7) if mx>x and mxy and my>3, (spr.pos.y)>>3 - map.surf(rooms.surf_items) - map.tile(tx,ty,0) + local x2,y2,w2,h2 = util.aabb(sprites.hero) + if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then + local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3 + map.surf(rooms.surf_items) + map.tile(tx,ty,0) - spr.state = templates.DYING - sprites.set_animation(spr, "coin_picked") - spr.pos.y=spr.pos.y-16 - spr.pos.x=spr.pos.x-4 - spr.timer = 0 - score.inc(10) - return - end - --end - --end + spr.state = templates.DYING + sprites.set_animation(spr, "coin_picked") + spr.pos.y=spr.pos.y-16 + spr.pos.x=spr.pos.x-4 + spr.timer = 0 + score.inc(10) + return + end elseif spr.state == templates.DYING then spr.pos.y = spr.pos.y - 0.5 spr.timer = spr.timer + 1 @@ -299,7 +303,7 @@ sprites = { local x1,y1,w1,h1 = util.aabb(spr) local x2,y2,w2,h2 = util.aabb(sprites.hero) if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then - sprites.hit_hero(4) + sprites.hero_hit(4) spr.state = templates.DYING spr.timer = 0 return @@ -307,7 +311,46 @@ sprites = { elseif spr.state == templates.DYING then spr.timer = spr.timer + 1 if spr.timer == 32 then - spr.state = templates.DYING + spr.state = templates.ALIVE + end + end + end, + + update_clau = function(spr) + if spr.state == templates.ALIVE then + local x1,y1,w1,h1 = util.aabb(spr) + local x2,y2,w2,h2 = util.aabb(sprites.hero) + if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then + if sprites.hero_give_key(spr.color) then + local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3 + map.surf(rooms.surf_items) + map.tile(tx,ty,0) + sprites.remove(spr) + end + end + end + end, + + update_porta = function(spr) + if spr.state == templates.ALIVE then + local x1,y1,w1,h1 = util.aabb(spr) + local x2,y2,w2,h2 = util.aabb(sprites.hero) + if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then + if sprites.hero.keys[spr.color] then + sprites.hero.keys[spr.color] = nil + sprites.set_animation(spr, "porta_obrint") + spr.state = templates.DYING + end + end + elseif spr.state == templates.DYING then + if spr.current_frame == 15 then + local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3 + map.surf(rooms.surf_items) + map.tile(tx,ty,0) + map.surf(rooms.surf_foreground) + map.tile(tx,ty,0) + map.tile(tx,ty+1,0) + sprites.remove(spr) end end end, @@ -446,7 +489,7 @@ sprites = { game.change_room(0,1) else if sprites.hero.pos.y >= 742 then - sprites.hit_hero(0) + sprites.hero_hit(0) return end sprites.hero.pos.y = sprites.hero.pos.y + 2 diff --git a/data/templates.lua b/data/templates.lua index f4117ca..20a8a35 100644 --- a/data/templates.lua +++ b/data/templates.lua @@ -6,9 +6,11 @@ templates = { create = function(type, options) local sprite - if type == "mummy" then + local key, value = type:match("^(%S+)%s*(.*)$") + + if key == "mummy" then sprite = { - type = type, + type = key, pos = options.pos,--{ x=100, y=4*12*8+71 }, size = { w=16,h=16 }, bbo = { left=3, top=2, right=3, bottom=0 }, @@ -22,9 +24,9 @@ templates = { room = options.room, ia = sprites.update_mummy } - elseif type == "bullet" then + elseif key == "bullet" then sprite = { - type = type, + type = key, pos = options.pos,--{ x=100, y=4*12*8+71 }, size = { w=4,h=3 }, bbo = { left=0, top=0, right=0, bottom=0 }, @@ -35,9 +37,9 @@ templates = { animation = "bullet", ia = sprites.update_bullet } - elseif type == "coin" then + elseif key == "coin" then sprite = { - type = type, + type = key, pos = options.pos,--{ x=100, y=4*12*8+71 }, size = { w=8,h=8 }, bbo = { left=0, top=0, right=0, bottom=0 }, @@ -52,9 +54,9 @@ templates = { light_oy = 4, ia = sprites.update_coin } - elseif type == "brick" then + elseif key == "brick" then sprite = { - type = type, + type = key, pos = options.pos,--{ x=100, y=4*12*8+71 }, size = { w=8,h=8 }, bbo = { left=0, top=0, right=0, bottom=0 }, @@ -67,9 +69,9 @@ templates = { timeout = 10, ia = sprites.update_brick } - elseif type == "torxa" then + elseif key == "torxa" then sprite = { - type = type, + type = key, pos = options.pos,--{ x=100, y=4*12*8+71 }, size = { w=8,h=16 }, bbo = { left=0, top=0, right=0, bottom=0 }, @@ -85,6 +87,39 @@ templates = { no_shadow = true, ia = sprites.update_torxa } + elseif key == "clau" then + sprite = { + type = key, + color = value, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=16,h=8 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load(value..".gif"), + animation = "clau", + state = templates.ALIVE, + light = 15, + light_ox = 7, + light_oy = 4, + ia = sprites.update_clau + } + elseif key == "porta" then + sprite = { + type = key, + color = value, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=8,h=16 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load(value..".gif"), + animation = "porta", + state = templates.ALIVE, + ia = sprites.update_porta + } else error("Template not recognized") end diff --git a/data/verda.gif b/data/verda.gif new file mode 100644 index 0000000..4a28926 Binary files /dev/null and b/data/verda.gif differ