u/Constant_Ad_35

Interpreter help

Interpreter help

I've been working on this interpreter for a few days and now I wanted to add functions, statement grouping and conditions, and I realized I had no idea how I would do that, so Im asking here for advice on how that should/could be done, thanks!

here's the repo(sorry if it's messy, Im gonna lean on that later) : https://github.com/KeefChief/Reload

u/Constant_Ad_35 — 5 days ago
▲ 2 r/love2d

Ok so I got this (pretty bad) collision system prototype I made and I was wondering, how should I transform it to make it more malleable, making it able to handle multiple collision types (like one way) and to behave differently depending on entities and maybe more. here's the code :

function resolve_entity_map_collisions_x(entity)
local collider = get_collider(entity)

local left = entity.x + collider.xoff
local right = entity.x + collider.xoff + collider.width
local top = entity.y + collider.yoff
local bottom = entity.y + collider.yoff + collider.height

local x1 = math.floor(math.min(left, right) / tile_size)
local y1 = math.floor(math.min(top, bottom) / tile_size)
local x2 = math.floor(math.max(left, right - 1e-6) / tile_size)
local y2 = math.floor(math.max(top, bottom - 1e-6) / tile_size)

for i = y1, y2 do
if entity.velx > 0 then
if tile_at(x2, i) > 0 then
if entity.solid then
entity.x = x2 * 8 - collider.xoff - collider.width
entity.velx = 0
end
return 1
end
elseif entity.velx < 0 then
if tile_at(x1, i) > 0 then
if entity.solid then 
entity.x = (x1 + 1) * 8 - collider.xoff
entity.velx = 0
end
return - 1
end
end
end
return 0
end

function resolve_entity_map_collisions_y(entity)
local collider = get_collider(entity)

local left = entity.x + collider.xoff
local right = entity.x + collider.xoff + collider.width
local top = entity.y + collider.yoff
local bottom = entity.y + collider.yoff + collider.height

local x1 = math.floor(math.min(left, right) / tile_size)
local y1 = math.floor(math.min(top, bottom) / tile_size)
local x2 = math.floor(math.max(left, right - 1e-6) / tile_size)
local y2 = math.floor(math.max(top, bottom - 1e-6) / tile_size)

for j = x1, x2 do
if entity.vely > 0 then
if tile_at(j, y2) > 0 then
if entity.solid then
entity.y = y2 * 8 - collider.yoff - collider.height
entity.vely = 0
end
return 1
end
elseif entity.vely < 0 then
if tile_at(j, y1) > 0 then
if entity.solid then
entity.y = (y1 + 1) * 8 - collider.yoff
entity.vely = 0
end
return -1
end
end
end
return 0
end

if you got any question to be able to help me better, please ask them

PS: I dont know why the see the tabs, they disappeared when I pasted the code

reddit.com
u/Constant_Ad_35 — 19 days ago