[WIP] Triggers

- Algo de neteja de codi
This commit is contained in:
2026-04-03 20:09:30 +02:00
parent de395abb06
commit 8b516a6a26
5 changed files with 33 additions and 57 deletions

View File

@@ -1,17 +1,29 @@
trigger={}
function trigger.new(_hab,_x,_y,_fun)
return {hab=_hab,x=_x,y=_y,fun=_fun,update=trigger.update,draw=trigger.draw,bb={x=0,y=0,w=8,h=8}}
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {
name="trigger",
hab=_hab,
x=world_x,
y=world_y,
w=16,
h=16,
fun=_fun,
update=trigger.update,
draw=trigger.draw,
bb={x=0,y=0,w=16,h=16} }
end
function trigger:draw()
-- do nothing
--rectfill(self.x,self.y,self.x+8,self.y+8,3)
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
draw.rectf(scr_x,scr_y,self.w,self.h,3)
end
function trigger:update()
if self.hab==abad.hab then
if aabb(abad,self) then
if collision(abad,self) then
self:fun()
end
end