Modulized cirno and mouse

This commit is contained in:
MaddoScientisto 2024-04-22 22:14:26 +02:00
commit b23a944c3e
4 changed files with 60 additions and 49 deletions

View file

@ -1,13 +1,10 @@
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-22 19:53:44",revision=324]]
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-22 20:14:15",revision=333]]
--include("/cirnofarm/src/actor.lua")
last_coll=0
mouse_debug = true
w=480
h=300
tile_width = 16
tile_height = 16
asdf = {top=0, side=1}
LAYERS_COUNT=4
@ -123,9 +120,9 @@ function cirno_draw()
foreach(LAYERS, render_layer)
--drawMap()
debug_mouse()
--debug_mouse()
print(string.format("%.4f %dfps",stat(1),stat(7)),2,2,5)
print(string.format("%.4f %dfps",stat(1),stat(7)),2,2,5)
end
function render_layer(layer)
@ -201,39 +198,6 @@ function can_move(x,y)
return is_tile(0,x,y)
end
function debug_mouse()
local mx,my = mouse()
local x_offset = 5
local y_offset = 5
-- tile size
local tw=tile_width
local th=tile_height
-- window width and height
local w=480
local h=270
-- offset if box leaves screen
if mx>w-20 then x_offset=-15 end
if my>h-29 then y_offset=-24 end
-- draw debug text box
local tile_x = mx\tw
local tile_y = my\th
rect((tile_x*tw)+tw,(tile_y*th)+th,tile_x*tw,(tile_y*th),8)
rectfill(mx+x_offset-1,my+y_offset-1,mx+x_offset+14,my+y_offset+23+8,1)
print(string.format("%d (%d)",tile_x,mx),mx+x_offset,my+y_offset,8)
print(string.format("%d (%d)",tile_y,my),mx+x_offset,my+y_offset+8,9)
for i=LAYERS_COUNT,1,-1 do
local sprite = get_layer_tile(tile_x,tile_y,i)
local flag = fget(sprite)
print(sprite,mx+x_offset+(i*16),my+y_offset+8*2,10)
print(flag,mx+x_offset+(i*16),my+y_offset+8+8*2,10)
end
end
function cmap(o)
local ct=false

42
src/mouse_debug.lua Normal file
View file

@ -0,0 +1,42 @@
--[[pod_format="raw",created="2024-04-22 19:55:03",modified="2024-04-22 20:14:14",revision=9]]
M = {}
function debug_mouse(layers_count, tile_width, tile_height)
local mx,my = mouse()
local x_offset = 5
local y_offset = 5
-- tile size
local tw=tile_width
local th=tile_height
-- window width and height
local w=480
local h=270
-- offset if box leaves screen
if mx>w-20 then x_offset=-15 end
if my>h-29 then y_offset=-24 end
-- draw debug text box
local tile_x = mx\tw
local tile_y = my\th
rect((tile_x*tw)+tw,(tile_y*th)+th,tile_x*tw,(tile_y*th),8)
rectfill(mx+x_offset-1,my+y_offset-1,mx+x_offset+14,my+y_offset+23+8,1)
print(string.format("%d (%d)",tile_x,mx),mx+x_offset,my+y_offset,8)
print(string.format("%d (%d)",tile_y,my),mx+x_offset,my+y_offset+8,9)
for i=layers_count,1,-1 do
local sprite = get_layer_tile(tile_x,tile_y,i)
local flag = fget(sprite)
print(sprite,mx+x_offset+(i*16),my+y_offset+8*2,10)
print(flag,mx+x_offset+(i*16),my+y_offset+8+8*2,10)
end
end
function M.draw(layers_count, tile_width, tile_height)
return debug_mouse(layers_count, tile_width, tile_height)
end
return M

View file

@ -1,4 +1,4 @@
--[[pod_format="raw",created="2024-04-22 19:32:54",modified="2024-04-22 19:53:44",revision=3]]
--[[pod_format="raw",created="2024-04-22 19:32:54",modified="2024-04-22 20:14:13",revision=5]]
M = {}
function M.func()