local shine_step = 1 local shine_wait = 0 local shine_pos = 0 local map_backup = {} local actors_backup = {} function collision(a, b) return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y) and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h) end function half_collision(a, b) return ((a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) ) or ((a.y+a.bb.y+a.bb.h >= b.y+b.bb.y) and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)) end function v_collision(a, b) return ((a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) ) end function h_collision(a, b) return ((a.y+a.bb.y+a.bb.h >= b.y+b.bb.y) and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)) end function remove_actor(actor) for index, value in pairs(actors) do if value == actor then table.remove(actors,index) end end end function set_actors_enabled_by_room(_enabled, _reason, room0, room1) print("set_actors_enabled_by_room") print(" hab_list") room1 = room1 or room0 local rw=(room1-room0)%mapa_rooms_per_piso local hab_list = {} y = room0 while y<=room1 do for x=y, y+rw do hab_list[x]=true print(" "..x) end y = y+mapa_rooms_per_piso end for index, actor in pairs(actors) do if hab_list[actor.hab] and actor~=abad then if actor.name then print(" "..actor.name) end if actor.disable_reason then print(" "..actor.disable_reason) end if actor.enabled then print("ENABLED") end if not _enabled then print("DISABLE ACTORS") -- disable if actor.enabled then -- Si el actor està actiu -> deshabilitar amb motiu actor.enabled=_enabled actor.disable_reason = _reason print("-> ".._reason) end else -- enable if actor.disable_reason and actor.disable_reason==_reason then -- Si l'actor te un motiu per haver estat deshabilitat -> habilitar i borrar motiu actor.enabled=_enabled actor.disable_reason = "" else -- Habilitar l'actor si no te atribut disable_reason actor.enabled=_enabled end end end end end function disable_actor_by_id( remove_set ) local id_list = {} local ok = false -- Construir llista per a eliminar if type(remove_set) == "string" then id_list[remove_set] = true ok = true elseif type(remove_set) == "table" then for _, v in ipairs(remove_set) do ok = true id_list[v] = true end end -- eliminar if ok then for index, actor in pairs(actors) do if id_list[actor.id] then -- actors[index]=nil actor.enabled=false end end end end function draw_shiny_rect(x, y, w, h, color, shine_color) draw.rect(x,y,w,h,color) local shine_w= 18 -- Convertir el rectangle en una linea en checkpoints local p0 = 0 local p1 = p0+w-1 local p2 = p1+h local p3 = p2+w local p4 = p3+h -- Punt inicial y final de la recta del brillo local s0 = shine_step local s1 = s0+shine_w local y0 = 0 if s0==p4 then shine_step=0 draw.line(x, y, x+shine_w, y, shine_color) elseif s0 41 = 17 (18) if y == mapa_room_rows then yroom = yroom + replace_rooms_per_piso y = 0 end xroom = yroom for tx=mapa_x0, mapa_x1 do -- 36 -> 59 = 23 (24) -- print("ROOM= "..xroom.." ( "..x..", "..y.." ) <= "..(1+xroom)..", "..(1+x+y*mapa_room_cols)) -- print(replace_map.map[1+xroom][1+x+y*mapa_room_cols]) local tile=editor_to_map_tile(replace_map.map[1+xroom][1+x+y*mapa_room_cols]) mapa_backup(tx, ty, map.tile(tx,ty)) map.tile(tx, ty, tile) x = x + 1 if x == mapa_room_cols then x = 0 xroom = xroom + 1 end end y = y +1 end end end -- DEBUG -- Imprime cualquier valor, incluyendo tablas anidadas function dump(value, indent) indent = indent or "" if type(value) ~= "table" then return tostring(value) end local parts = {"{"} for k, v in pairs(value) do local key = (type(k) == "string") and k or "["..tostring(k).."]" table.insert(parts, string.format("%s %s = %s,", indent, key, dump(v, indent.." "))) end table.insert(parts, indent.."}") return table.concat(parts, "\n") end function msg_print(x, y, msg, direct_print ) local scr_x, scr_y direct_print = direct_print or false if direct_print then scr_x = x scr_y = y else scr_x, scr_y = viewp:screen_coords(x, y) end draw.rectf(scr_x,scr_y,256,20,16) draw.text(msg,scr_x+1,scr_y+1,2) end function view_coord(x, y, w, h, color) local scr_x, scr_y = viewp:screen_coords(x, y) draw.rect(scr_x, scr_y, w, h, color) end function debug.write_tile(x, y, yplus, print_type, align ) local scr_x, scr_y = viewp:screen_coords(x, y) local hab, xx, yy = coords.world_to_tile(x, y) yplus = yplus or 0 print_type = print_type or false align = align or "R" local txt_offset = -7 if align=="R" then txt_offset = -14 elseif align=="L" then txt_offset = 0 end draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16) -- local msg = mapa_get_tile(hab,xx,yy) local msg = arc_get_tile(x,y) if print_type then msg = msg.." "..arc_check_tile(x, y) end draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2) end function empty_table(t) for _ in pairs(t) do return false end return true end