require "sprites" LAYER_FOREGROUND = 1 LAYER_BACKGROUND = 2 LAYER_ITEMS = 4 LAYER_SPRITES = 8 LAYER_SHADOWS = 16 LAYER_ALL = 31 rooms = { surf_background = nil, surf_foreground = nil, surf_items = nil, surf_original_items = nil, visibility = LAYER_ALL, pos = {x=0, y=4*12}, current = function() return (rooms.pos.x//20) + (rooms.pos.y//12) * 8 end, init = function() rooms.pos.x, rooms.pos.y = 0,4*12 if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end rooms.surf_background = surf.load("rooms_background.bin") --rooms.surf_background = surf.new(20*8,12*8) if rooms.surf_foreground ~= nil then surf.free(rooms.surf_foreground) end rooms.surf_foreground = surf.load("rooms_foreground.bin") --rooms.surf_foreground = surf.new(20*8,12*8) if rooms.surf_items ~= nil then surf.free(rooms.surf_items) end rooms.surf_items = surf.load("rooms_items.bin") --rooms.surf_items = surf.new(20*8,12*8) rooms.surf_original_items = surf.new(20*8,12*8) surf.source(rooms.surf_items) surf.target(rooms.surf_original_items) draw.surf(0,0,160,96,0,0) 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() 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") editor.modified = false 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 end, draw = function() -- Retallem la pantalla a la zona de joc 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) -- Pintem el background surf.source(surf_tiles) map.surf(rooms.surf_background) if rooms.is_visible(LAYER_BACKGROUND) then map.draw() else draw.rectf(0,0,160,96,1) 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) -- Pintem el foreground de negre map.surf(rooms.surf_foreground) pal.subpal(0,32,1) 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 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) pal.subpal() -- Pintem el foreground surf.source(surf_tiles) map.surf(rooms.surf_foreground) if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end -- Pintem els sprites if rooms.is_visible(LAYER_SPRITES) then sprites.draw() --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) end -- Pintem la rejilla --for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end --for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end end, is_visible = function(layer) return rooms.visibility & layer == layer end, set_visibility = function(layer, visibility) if visibility then rooms.visibility = rooms.visibility | layer else rooms.visibility = rooms.visibility & ~layer end end, toggle_visibility = function(layer) if rooms.visibility & layer == layer then rooms.visibility = rooms.visibility & ~layer else rooms.visibility = rooms.visibility | layer end end, peiv = function() pal.color(1, 1, 1, 1) return "HOLA OTHER UNIT" end }