diff --git a/data/animations.lua b/data/animations.lua index 519ef14..53e9fa6 100644 --- a/data/animations.lua +++ b/data/animations.lua @@ -36,9 +36,9 @@ animations = { ["hero_shoot"] = { cycle = {1,2,3}, 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"] = { diff --git a/data/game.lua b/data/game.lua index 4e2bff8..2760c01 100644 --- a/data/game.lua +++ b/data/game.lua @@ -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() diff --git a/data/main.lua b/data/main.lua index 0966ab5..2b26f65 100644 --- a/data/main.lua +++ b/data/main.lua @@ -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 diff --git a/data/rooms.lua b/data/rooms.lua index 712f708..4748b83 100644 --- a/data/rooms.lua +++ b/data/rooms.lua @@ -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 } diff --git a/data/rooms_foreground.gif b/data/rooms_foreground.gif index 65e7901..649bcee 100644 Binary files a/data/rooms_foreground.gif and b/data/rooms_foreground.gif differ diff --git a/data/rooms_items.gif b/data/rooms_items.gif index 867a07f..d3fe521 100644 Binary files a/data/rooms_items.gif and b/data/rooms_items.gif differ diff --git a/data/sprites.lua b/data/sprites.lua index 0dffd10..a25dafb 100644 --- a/data/sprites.lua +++ b/data/sprites.lua @@ -258,7 +258,6 @@ sprites = { -- 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 @@ -360,10 +359,8 @@ sprites = { 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 @@ -422,12 +419,21 @@ 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)) + 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)) if cheats.showaabb then local x,y,w,h = util.aabb(sprite) draw.rect(x,y,w,h,8)