diff --git a/data/editor.lua b/data/editor.lua index 89479c8..77be13f 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -23,6 +23,7 @@ editor = { end, update = function() + tweening.update(sys.delta()) if sys.beat() then editor.ants = (editor.ants<<12) | (editor.ants>>4) end @@ -38,10 +39,6 @@ editor = { end end - -- Pintar el menú (el marcador serà en el modul game.lua) - --score.draw() - menu.draw() - -- Pintar el mapa i sprites rooms.draw() @@ -50,7 +47,7 @@ editor = { local tx, ty = (mx>>3), (my>>3) mx, my = tx<<3, ty<<3 - if my>=0 then + if menu.hidden then if editor.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then if editor.selection then local rx1,ry1,rx2,ry2=editor.selection.x1<<3,editor.selection.y1<<3,editor.selection.x2<<3,editor.selection.y2<<3 @@ -132,10 +129,11 @@ editor = { view.origin(0,0) draw.text(rooms.pos.x//20,1,96,28) - draw.text(rooms.pos.y//12,5,96,28) + draw.text(rooms.pos.y//13,5,96,28) if key.press(key.ESCAPE) then - editor.quit() + --editor.quit() + menu.toggle() elseif key.press(key.RIGHT) and rooms.pos.x < 20*7 then rooms.pos.x = rooms.pos.x + 20 sprites.remove_out_of_room() @@ -144,12 +142,12 @@ editor = { rooms.pos.x = rooms.pos.x - 20 sprites.remove_out_of_room() sprites.add_from_room(rooms.pos.x, rooms.pos.y) - elseif key.press(key.DOWN) and rooms.pos.y < 12*7 then - rooms.pos.y = rooms.pos.y + 12 + elseif key.press(key.DOWN) and rooms.pos.y < 13*7 then + rooms.pos.y = rooms.pos.y + 13 sprites.remove_out_of_room() sprites.add_from_room(rooms.pos.x, rooms.pos.y) elseif key.press(key.UP) and rooms.pos.y > 0 then - rooms.pos.y = rooms.pos.y - 12 + rooms.pos.y = rooms.pos.y - 13 sprites.remove_out_of_room() sprites.add_from_room(rooms.pos.x, rooms.pos.y) elseif key.press(key.TAB) or key.press(key.ESCAPE) then @@ -188,6 +186,11 @@ editor = { sprites.remove(sprite) end end + + -- Pintar el menú (el marcador serà en el modul game.lua) + --score.draw() + menu.draw() + end, create_stamp=function() @@ -224,7 +227,7 @@ editor = { for y=1,h do for x=1,w do local fx, fy = tx+x-1, ty+y-1 - if fx < rooms.pos.x+20 and fy < rooms.pos.y+12 then + if fx < rooms.pos.x+20 and fy < rooms.pos.y+13 then map.tile(fx,fy,editor.brush.tiles[p]) end p=p+1 diff --git a/data/game.lua b/data/game.lua index 2760c01..285e6cf 100644 --- a/data/game.lua +++ b/data/game.lua @@ -124,12 +124,12 @@ game = { apply_water = function() view.origin(0,0) - if rooms.pos.y == 84 then + if rooms.pos.y == 91 then surf.target(game.back_buf) surf.source(game.back_buf) for x=0,159 do local water_level = math.sin(game.water_counter)*2 - for y=96+water_level,103 do + for y=88+water_level,103 do local pixel = surf.pixel(x,y) surf.pixel(x,y,game.water_pal[pixel+1]) end diff --git a/data/menu.lua b/data/menu.lua index 4049f1e..72e4135 100644 --- a/data/menu.lua +++ b/data/menu.lua @@ -1,56 +1,140 @@ require "popup" menu = { - current_x = 0, - - init = function() - end, + hidden = true, + pos_y = 0, draw = function() - view.origin(0,0) + view.origin(0,menu.pos_y) view.clip() - draw.rectf(0,0,160,7,23) - draw.hline(0,7,160,16) - menu.current_x = 1 + local y = menu.pos_y + draw.rrectf(1,0,8,8,1,21) + draw.rrectf(1,-1,8,8,1,6) + draw.hline(3,1,6,21) + draw.hline(3,3,6,21) + draw.hline(3,5,6,21) + draw.rectf(6,0,2,2,8) - menu.option("FILE") - popup.create("FILE", 1, 8) - popup.addOption("FILE", "Play", editor.play) - popup.addOption("FILE", "Save", function() rooms.save() editor.modified=false end) - popup.addOption("FILE", "Quit", editor.quit) + if y<=0 then return end - menu.option("VIEW") - popup.create("VIEW", 1, 8) - popup.addOption("VIEW", "Background", function() rooms.toggle_visibility(LAYER_BACKGROUND) end) - popup.addOption("VIEW", "Shadows", function() rooms.toggle_visibility(LAYER_SHADOWS) end) - popup.addOption("VIEW", "Foreground", function() rooms.toggle_visibility(LAYER_FOREGROUND) end) - popup.addOption("VIEW", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end) + view.origin(0,menu.pos_y-24) + draw.rectf(0,0,160,24,6) - menu.option("EDIT") - popup.create("EDIT", 1, 8) - popup.addOption("EDIT", "Background", function() editor.layer=LAYER_BACKGROUND end) - popup.addOption("EDIT", "Foreground", function() editor.layer=LAYER_FOREGROUND end) - popup.addOption("EDIT", "Items", function() editor.layer=LAYER_ITEMS end) - --popup.addOption("EDIT", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end) + menu.pushbutton("PLAY",1,3,16,13,10,editor.play) + menu.pushbutton("SAVE",22,3,7,22,21,function() rooms.save() editor.modified=false end) + menu.pushbutton("QUIT",22,12,7,12,5,editor.quit) - menu.option("TOOLS") - if editor.modified then - draw.text("*",160-5,1,8) - end + draw.rrect(44,6,29,14,3,21) + draw.rectf(48,6,17,1,6) + draw.text("EDIT",49,3,21) + menu.togglebutton("F",44+3,6+3,7,14,9,15,7,editor.layer==LAYER_FOREGROUND,function() editor.layer=LAYER_FOREGROUND end) + menu.togglebutton("B",52+3,6+3,7,14,9,15,7,editor.layer==LAYER_BACKGROUND,function() editor.layer=LAYER_BACKGROUND end) + menu.togglebutton("I",60+3,6+3,7,14,9,15,7,editor.layer==LAYER_ITEMS,function() editor.layer=LAYER_ITEMS end) + + draw.rrect(75,6,37,14,3,21) + draw.rectf(79,6,17,1,6) + draw.text("SHOW",80,3,21) + + menu.togglebutton("F",75+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_FOREGROUND),function() rooms.toggle_visibility(LAYER_FOREGROUND) end) + menu.togglebutton("B",83+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_BACKGROUND),function() rooms.toggle_visibility(LAYER_BACKGROUND) end) + menu.togglebutton("S",91+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_SHADOWS),function() rooms.toggle_visibility(LAYER_SHADOWS) end) + menu.togglebutton("I",99+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_ITEMS),function() rooms.toggle_visibility(LAYER_ITEMS) end) end, - option = function(label) - local next_x = menu.current_x + (#label + 2)*4 - local mx, my = mouse.pos() - if my < 8 and mx >= menu.current_x and mx < next_x then - draw.rectf(menu.current_x, 0, next_x-menu.current_x, 7, 21) - if mouse.down(mouse.LEFT) then - mouse.discard() - popup.show(label) - end + toggle = function() + if menu.hidden then + menu.hidden = false + tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) + else + menu.hidden = true + tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) end - draw.text(label,menu.current_x+4,1,28) - menu.current_x = next_x - end + end, + + pushbutton = function(label,x,y,h,col1,col2,callback) + local size = (#label*4)-1+4 + local text_y = (h-5)//2 + local button_h=0 + local mx, my = mouse.pos() + if mx>=x and mx=y and my=x and mx=y and my-1 then bh=bh-1 end + end + draw.rrectf(x,y+1,size,h,1,col2) + draw.rrectf(x,y-bh,size,h,1,col1) + draw.text(label,x+2,y+text_y-bh,col2) + end, + +-- current_x = 0, +-- +-- init = function() +-- end, +-- +-- draw = function() +-- view.origin(0,0) +-- view.clip() +-- draw.rectf(0,0,160,7,23) +-- draw.hline(0,7,160,16) +-- menu.current_x = 1 +-- +-- menu.option("FILE") +-- popup.create("FILE", 1, 8) +-- popup.addOption("FILE", "Play", editor.play) +-- popup.addOption("FILE", "Save", function() rooms.save() editor.modified=false end) +-- popup.addOption("FILE", "Quit", editor.quit) +-- +-- menu.option("VIEW") +-- popup.create("VIEW", 1, 8) +-- popup.addOption("VIEW", "Background", function() rooms.toggle_visibility(LAYER_BACKGROUND) end) +-- popup.addOption("VIEW", "Shadows", function() rooms.toggle_visibility(LAYER_SHADOWS) end) +-- popup.addOption("VIEW", "Foreground", function() rooms.toggle_visibility(LAYER_FOREGROUND) end) +-- popup.addOption("VIEW", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end) +-- +-- menu.option("EDIT") +-- popup.create("EDIT", 1, 8) +-- popup.addOption("EDIT", "Background", function() editor.layer=LAYER_BACKGROUND end) +-- popup.addOption("EDIT", "Foreground", function() editor.layer=LAYER_FOREGROUND end) +-- popup.addOption("EDIT", "Items", function() editor.layer=LAYER_ITEMS end) +-- --popup.addOption("EDIT", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end) +-- +-- menu.option("TOOLS") +-- if editor.modified then +-- draw.text("*",160-5,1,8) +-- end +-- +-- end, +-- +-- option = function(label) +-- local next_x = menu.current_x + (#label + 2)*4 +-- local mx, my = mouse.pos() +-- if my < 8 and mx >= menu.current_x and mx < next_x then +-- draw.rectf(menu.current_x, 0, next_x-menu.current_x, 7, 21) +-- if mouse.down(mouse.LEFT) then +-- mouse.discard() +-- popup.show(label) +-- end +-- end +-- draw.text(label,menu.current_x+4,1,28) +-- menu.current_x = next_x +-- end } \ No newline at end of file diff --git a/data/rooms.lua b/data/rooms.lua index 76adf58..b45b290 100644 --- a/data/rooms.lua +++ b/data/rooms.lua @@ -14,28 +14,48 @@ rooms = { surf_items = nil, surf_original_items = nil, visibility = LAYER_ALL, - pos = {x=0, y=4*12}, + pos = {x=0, y=4*13}, current = function() - return (rooms.pos.x//20) + (rooms.pos.y//12) * 8 + return (rooms.pos.x//20) + (rooms.pos.y//13) * 8 + end, + + convert = function(src) + local dst = surf.new(20*8,13*8) + surf.source(src) + surf.target(dst) + + for ry=0,7 do + for rx=0,7 do + for ty=0,11 do + for tx=0,19 do + surf.pixel(rx*20+tx, ry*13+ty, surf.pixel(rx*20+tx, ry*12+ty)) + end + end + end + end + return dst end, 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) + --rooms.surf_background = surf.new(20*8,13*8) + --rooms.surf_background = rooms.convert(surf.load("rooms_background"..ROOM_FILE_EXT)) if rooms.surf_foreground ~= nil then surf.free(rooms.surf_foreground) end rooms.surf_foreground = surf.load("rooms_foreground"..ROOM_FILE_EXT) --rooms.surf_foreground = surf.new(20*8,12*8) + --rooms.surf_foreground = rooms.convert(surf.load("rooms_foreground"..ROOM_FILE_EXT)) 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_items = rooms.convert(surf.load("rooms_items"..ROOM_FILE_EXT)) end, init = function() - rooms.pos.x, rooms.pos.y = 0,4*12 + rooms.pos.x, rooms.pos.y = 0,4*13 rooms.reload() sprites.init() end, @@ -50,15 +70,15 @@ rooms = { end, is_outside = function(x, y) - return x < rooms.pos.x or y < rooms.pos.y or x > rooms.pos.x + 20 or y > rooms.pos.y + 12 + return x < rooms.pos.x or y < rooms.pos.y or x > rooms.pos.x + 20 or y > rooms.pos.y + 13 end, draw = function() -- Retallem la pantalla a la zona de joc - view.clip(0,8,160,96) + --view.clip(0,8,160,96) -- Movem la càmara a l'habitació on estem - view.origin(-rooms.pos.x*8,-rooms.pos.y*8+8) + view.origin(-rooms.pos.x*8,-rooms.pos.y*8) -- Pintem el background surf.source(surf_tiles) @@ -70,7 +90,7 @@ rooms = { end -- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground - view.origin(-rooms.pos.x*8+4,-rooms.pos.y*8+12) + view.origin(-rooms.pos.x*8+4,-rooms.pos.y*8+4) -- Pintem el foreground de negre map.surf(rooms.surf_foreground) @@ -78,13 +98,13 @@ rooms = { if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end -- Pintem els sprites de negre - if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then + if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then sprites.draw(true) --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) end -- Movem la càmara al lloc que toca de nou, i tornem la paleta normal - view.origin(-rooms.pos.x*8,-rooms.pos.y*8+8) + view.origin(-rooms.pos.x*8,-rooms.pos.y*8) pal.subpal() -- Pintem el foreground diff --git a/data/rooms_background.gif b/data/rooms_background.gif index 8d97e8f..b962bd1 100644 Binary files a/data/rooms_background.gif and b/data/rooms_background.gif differ diff --git a/data/rooms_foreground.gif b/data/rooms_foreground.gif index c1b734b..0d21bba 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 db76d1e..f630ba0 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 2e720e2..62970ba 100644 --- a/data/sprites.lua +++ b/data/sprites.lua @@ -48,7 +48,7 @@ sprites = { init = function() sprites.hero = { type = "hero", - pos = { x=28, y=4*12*8+71 }, + pos = { x=28, y=4*13*8+71 }, size= { w=16, h=17 }, bbo = { left=3, top=2, right=3, bottom=0 }, current_frame = 1, @@ -380,7 +380,7 @@ sprites = { 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 + if sprites.hero.cooldown % 4 == 0 then sprites.hero.pos.y = sprites.hero.pos.y + 1 end end @@ -488,7 +488,7 @@ sprites = { 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 + if sprites.hero.pos.y >= 808 then sprites.hero_hit(0) return end