Files
cacaus-arcade/data/helpers.lua
JailGamer 2564c54b3e - [NEW] draw_shiny_rect()
- [WIP] Menú d'opcions
2026-04-03 01:08:20 +02:00

199 lines
5.2 KiB
Lua

local shine_step = 1
local shine_wait = 0
local shine_pos = 0
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<p1 then
if s1<p1 then
draw.line(x+s0, y, x+s1, y, shine_color)
elseif s1<p2 then
segment = s1-p1
draw.line(x+s0, y, x+w-1, y, shine_color)
draw.line(x+w-1, y, x+w-1, y+segment, shine_color)
end
elseif s0<p2 then
if s1<p2 then
segment = shine_w
x0 = x+w-1
y0= y+(s0-p1)-1
draw.line(x0, y0, x0, y0+segment, shine_color)
elseif s1<p3 then
segment = s1-p2
x0= x+w-1-segment
y0= y+h-1
draw.line(x0, y0, x0+segment, y0, shine_color)
segment = p2-s0-1
x0= x+w-1
y0= y+(s0-p1)
draw.line(x0, y0, x0, y0+segment, shine_color)
end
elseif s0<p3 then
if s1<p3 then
segment=shine_w
x0 = x+w-1-(s1-p2)
y0 = y+h-1
draw.line(x0, y0, x0+shine_w, y0, shine_color)
elseif s1<p4 then
segment = s1-p3
y0 = y+h-1
draw.line(x,y0,x,y0-segment,shine_color)
segment = p3-s0
y0 = y+h-1
draw.line(x,y0,x+segment,y0,shine_color)
end
elseif s0<p4 then
if s1<p4 then
segment = shine_w
y0 = y+p4-s1
draw.line(x,y0,x,y0+segment,shine_color)
else
segment = s1-p4
draw.line(x,y,x+segment,y,shine_color)
segment = p4-s0
draw.line(x,y,x,y+segment,shine_color)
end
end
shine_step = shine_step+1
end
function arc_text(str, x, y, col)
font.current(font_sf)
draw.text(str,x,y,col)
end
function arc_textB(str, x, y, col)
font.current(font_sf)
-- Crear el borde negre
draw.text(str, x-1, y-1, 16)
draw.text(str, x , y-1, 16)
draw.text(str, x+1, y-1, 16)
draw.text(str, x-1, y, 16)
draw.text(str, x+1, y, 16)
draw.text(str, x-1, y+1, 16)
draw.text(str, x , y+1, 16)
draw.text(str, x+1, y+1, 16)
-- Escriure la cadena
draw.text(str,x,y,col)
end
function editor_to_map_tile(editor_tile)
local result = 0
if editor_tile<256 then result = editor_tile + arcade_config.tiles_offset end
return result
end
function map_to_editor_tile(map_tile)
local result = map_tile - arcade_config.tiles_offset
if map_tile==0 then result = 256 end
return result
end
function load_tilemap( sf_mapa )
local mapa_tw, mapa_th = surf.size(sf_mapa)
local nrooms = mapa_rooms_per_piso*mapa_pisos
local x = 0
local y = 0
local yroom = 0
local xroom = 0
map.surf(sf_mapa)
for ty=0,mapa_th-1 do
if y == mapa_room_rows then
yroom = yroom + mapa_rooms_per_piso
y = 0
end
xroom = yroom
for tx=0,mapa_tw-1 do
local tile=editor_to_map_tile(mapa[1+xroom][1+x+y*mapa_room_cols])
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
-- 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,45,7,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