- [NEW] Redimensionades les habitacions per a ocupar tota la pantalla

- [FIX] Ajustada posició inici segons nou tamany de habitacions
- [FIX] Ajustat nivell de l'aigua segons nou tamany de habitacions
- [WIP] Treballant en el nou menú
This commit is contained in:
2026-03-11 07:42:24 +01:00
parent 9dcaaa0882
commit de873a7a25
8 changed files with 174 additions and 67 deletions

View File

@@ -23,6 +23,7 @@ editor = {
end, end,
update = function() update = function()
tweening.update(sys.delta())
if sys.beat() then if sys.beat() then
editor.ants = (editor.ants<<12) | (editor.ants>>4) editor.ants = (editor.ants<<12) | (editor.ants>>4)
end end
@@ -38,10 +39,6 @@ editor = {
end end
end end
-- Pintar el menú (el marcador serà en el modul game.lua)
--score.draw()
menu.draw()
-- Pintar el mapa i sprites -- Pintar el mapa i sprites
rooms.draw() rooms.draw()
@@ -50,7 +47,7 @@ editor = {
local tx, ty = (mx>>3), (my>>3) local tx, ty = (mx>>3), (my>>3)
mx, my = tx<<3, ty<<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.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then
if editor.selection 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 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) view.origin(0,0)
draw.text(rooms.pos.x//20,1,96,28) 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 if key.press(key.ESCAPE) then
editor.quit() --editor.quit()
menu.toggle()
elseif key.press(key.RIGHT) and rooms.pos.x < 20*7 then elseif key.press(key.RIGHT) and rooms.pos.x < 20*7 then
rooms.pos.x = rooms.pos.x + 20 rooms.pos.x = rooms.pos.x + 20
sprites.remove_out_of_room() sprites.remove_out_of_room()
@@ -144,12 +142,12 @@ editor = {
rooms.pos.x = rooms.pos.x - 20 rooms.pos.x = rooms.pos.x - 20
sprites.remove_out_of_room() sprites.remove_out_of_room()
sprites.add_from_room(rooms.pos.x, rooms.pos.y) sprites.add_from_room(rooms.pos.x, rooms.pos.y)
elseif key.press(key.DOWN) and rooms.pos.y < 12*7 then elseif key.press(key.DOWN) and rooms.pos.y < 13*7 then
rooms.pos.y = rooms.pos.y + 12 rooms.pos.y = rooms.pos.y + 13
sprites.remove_out_of_room() sprites.remove_out_of_room()
sprites.add_from_room(rooms.pos.x, rooms.pos.y) sprites.add_from_room(rooms.pos.x, rooms.pos.y)
elseif key.press(key.UP) and rooms.pos.y > 0 then 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.remove_out_of_room()
sprites.add_from_room(rooms.pos.x, rooms.pos.y) sprites.add_from_room(rooms.pos.x, rooms.pos.y)
elseif key.press(key.TAB) or key.press(key.ESCAPE) then elseif key.press(key.TAB) or key.press(key.ESCAPE) then
@@ -188,6 +186,11 @@ editor = {
sprites.remove(sprite) sprites.remove(sprite)
end end
end end
-- Pintar el menú (el marcador serà en el modul game.lua)
--score.draw()
menu.draw()
end, end,
create_stamp=function() create_stamp=function()
@@ -224,7 +227,7 @@ editor = {
for y=1,h do for y=1,h do
for x=1,w do for x=1,w do
local fx, fy = tx+x-1, ty+y-1 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]) map.tile(fx,fy,editor.brush.tiles[p])
end end
p=p+1 p=p+1

View File

@@ -124,12 +124,12 @@ game = {
apply_water = function() apply_water = function()
view.origin(0,0) view.origin(0,0)
if rooms.pos.y == 84 then if rooms.pos.y == 91 then
surf.target(game.back_buf) surf.target(game.back_buf)
surf.source(game.back_buf) surf.source(game.back_buf)
for x=0,159 do for x=0,159 do
local water_level = math.sin(game.water_counter)*2 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) local pixel = surf.pixel(x,y)
surf.pixel(x,y,game.water_pal[pixel+1]) surf.pixel(x,y,game.water_pal[pixel+1])
end end

View File

@@ -1,56 +1,140 @@
require "popup" require "popup"
menu = { menu = {
current_x = 0, hidden = true,
pos_y = 0,
init = function()
end,
draw = function() draw = function()
view.origin(0,0) view.origin(0,menu.pos_y)
view.clip() view.clip()
draw.rectf(0,0,160,7,23) local y = menu.pos_y
draw.hline(0,7,160,16) draw.rrectf(1,0,8,8,1,21)
menu.current_x = 1 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") if y<=0 then return end
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") view.origin(0,menu.pos_y-24)
popup.create("VIEW", 1, 8) draw.rectf(0,0,160,24,6)
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") menu.pushbutton("PLAY",1,3,16,13,10,editor.play)
popup.create("EDIT", 1, 8) menu.pushbutton("SAVE",22,3,7,22,21,function() rooms.save() editor.modified=false end)
popup.addOption("EDIT", "Background", function() editor.layer=LAYER_BACKGROUND end) menu.pushbutton("QUIT",22,12,7,12,5,editor.quit)
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") draw.rrect(44,6,29,14,3,21)
if editor.modified then draw.rectf(48,6,17,1,6)
draw.text("*",160-5,1,8) draw.text("EDIT",49,3,21)
end 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, end,
option = function(label) toggle = function()
local next_x = menu.current_x + (#label + 2)*4 if menu.hidden then
local mx, my = mouse.pos() menu.hidden = false
if my < 8 and mx >= menu.current_x and mx < next_x then tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end)
draw.rectf(menu.current_x, 0, next_x-menu.current_x, 7, 21) else
if mouse.down(mouse.LEFT) then menu.hidden = true
mouse.discard() tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end)
popup.show(label)
end
end end
draw.text(label,menu.current_x+4,1,28) end,
menu.current_x = next_x
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<x+size and my>=y and my<y+h then
button_h = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
draw.rrectf(x,y+1,size,h,1,col2)
draw.rrectf(x,y-button_h,size,h,1,col1)
draw.text(label,x+2,y+text_y-button_h,col2)
end,
togglebutton = function(label,x,y,h,col1,col2,dis1,dis2,state,callback)
local size = (#label*4)-1+4
local text_y = (h-5)//2
local bh=0
local mx, my = mouse.pos()
if mx>=x and mx<x+size and my>=y and my<y+h then
bh = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
if not state then
col1,col2 = dis1,dis2
else
if bh>-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
} }

View File

@@ -14,28 +14,48 @@ rooms = {
surf_items = nil, surf_items = nil,
surf_original_items = nil, surf_original_items = nil,
visibility = LAYER_ALL, visibility = LAYER_ALL,
pos = {x=0, y=4*12}, pos = {x=0, y=4*13},
current = function() 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, end,
reload = function() reload = function()
if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end 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.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 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.load("rooms_foreground"..ROOM_FILE_EXT)
--rooms.surf_foreground = surf.new(20*8,12*8) --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 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.load("rooms_items"..ROOM_FILE_EXT)
--rooms.surf_items = surf.new(20*8,12*8) --rooms.surf_items = surf.new(20*8,12*8)
--rooms.surf_items = rooms.convert(surf.load("rooms_items"..ROOM_FILE_EXT))
end, end,
init = function() init = function()
rooms.pos.x, rooms.pos.y = 0,4*12 rooms.pos.x, rooms.pos.y = 0,4*13
rooms.reload() rooms.reload()
sprites.init() sprites.init()
end, end,
@@ -50,15 +70,15 @@ rooms = {
end, end,
is_outside = function(x, y) 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, end,
draw = function() draw = function()
-- Retallem la pantalla a la zona de joc -- 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 -- 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 -- Pintem el background
surf.source(surf_tiles) surf.source(surf_tiles)
@@ -70,7 +90,7 @@ rooms = {
end end
-- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground -- 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 -- Pintem el foreground de negre
map.surf(rooms.surf_foreground) map.surf(rooms.surf_foreground)
@@ -78,13 +98,13 @@ rooms = {
if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end
-- Pintem els sprites de negre -- 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) sprites.draw(true)
--draw.surf(0, 0, 16, 17, 20, 15, 16, 17) --draw.surf(0, 0, 16, 17, 20, 15, 16, 17)
end end
-- Movem la càmara al lloc que toca de nou, i tornem la paleta normal -- 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() pal.subpal()
-- Pintem el foreground -- Pintem el foreground

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

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

@@ -48,7 +48,7 @@ sprites = {
init = function() init = function()
sprites.hero = { sprites.hero = {
type = "hero", type = "hero",
pos = { x=28, y=4*12*8+71 }, pos = { x=28, y=4*13*8+71 },
size= { w=16, h=17 }, size= { w=16, h=17 },
bbo = { left=3, top=2, right=3, bottom=0 }, bbo = { left=3, top=2, right=3, bottom=0 },
current_frame = 1, current_frame = 1,
@@ -380,7 +380,7 @@ sprites = {
if rooms.pos.y<84 and 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) game.change_room(0,1)
else else
if sprites.hero.cooldown % 2 == 0 then if sprites.hero.cooldown % 4 == 0 then
sprites.hero.pos.y = sprites.hero.pos.y + 1 sprites.hero.pos.y = sprites.hero.pos.y + 1
end end
end end
@@ -488,7 +488,7 @@ sprites = {
if rooms.pos.y<84 and 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) game.change_room(0,1)
else else
if sprites.hero.pos.y >= 742 then if sprites.hero.pos.y >= 808 then
sprites.hero_hit(0) sprites.hero_hit(0)
return return
end end