Added per-layer collisions

This commit is contained in:
MaddoScientisto 2024-04-18 19:12:05 +02:00
commit 254da24cf1
2 changed files with 64 additions and 34 deletions

View file

@ -1,4 +1,4 @@
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-17 12:50:21",revision=231]]
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-18 17:11:46",revision=281]]
--include("/cirnofarm/src/actor.lua")
last_coll=0
mouse_debug = true
@ -7,6 +7,15 @@ h=300
tile_width = 16
tile_height = 16
asdf = {top=0, side=1}
LAYERS_COUNT=4
LAYERS = {
{index=4, name="background", render=true, render_objects=false, spawn_objects=false},
{index=3, name="solid", render=true, render_objects=false, spawn_objects=false},
{index=2, name="foreground", render=true, render_objects=true, spawn_objects=false},
{index=1, name="objects", render=false, render_objects=false, spawn_objects=true}
}
function _init()
player={}
@ -71,17 +80,28 @@ function _draw()
cls(0)
--camera(x - 240, y - 135)
drawMap()
foreach(LAYERS, render_layer)
--drawMap()
for p in all(player) do
p:draw()
end
debug_mouse()
end
function render_layer(layer)
if (layer.render) then
map(fetch"map/0.map"[layer.index].bmp)
end
if (layer.render_objects) then
-- Render all objects here
for p in all(player) do
p:draw()
end
end
end
function drawMap()
for i=2,1,-1 do
for i=LAYERS_COUNT,1,-1 do
map(fetch"map/0.map"[i].bmp)
end
end
@ -111,8 +131,13 @@ function check_collision(x,y,w,h)
return collide
end
function get_layer_tile(x,y,layer)
return get(fetch"map/0.map"[layer].bmp,x,y)
end
function is_tile(tile_type,x,y)
local tile = mget(x/tile_width,y/tile_height)
--local tile = mget(x/tile_width,y/tile_height)
local tile = get_layer_tile(x/tile_width,y/tile_height,3)
local has_flag = fget(tile,tile_type)
--last_coll = fget(tile)
return has_flag
@ -146,14 +171,18 @@ function debug_mouse()
-- draw debug text box
local tile_x = mx\tw
local tile_y = my\th
local sprite = mget(tile_x,tile_y)
local flag = fget(sprite)
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)
print(sprite,mx+x_offset,my+y_offset+8*2,10)
print(flag,mx+x_offset,my+y_offset+8+8*2,10)
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)