From 8b516a6a261ed62df986244855d09e68fdcd84e5 Mon Sep 17 00:00:00 2001 From: JailGamer Date: Fri, 3 Apr 2026 20:09:30 +0200 Subject: [PATCH] [WIP] Triggers - Algo de neteja de codi --- data/game.lua | 10 ++-------- data/helpers.lua | 15 +++++++++++++++ data/main.lua | 5 +---- data/opcions_input.lua | 42 ------------------------------------------ data/trigger.lua | 18 +++++++++++++++--- 5 files changed, 33 insertions(+), 57 deletions(-) diff --git a/data/game.lua b/data/game.lua index 6970381..9105acc 100644 --- a/data/game.lua +++ b/data/game.lua @@ -13,6 +13,7 @@ require "caco" require "zombie" require "score" require "switches" +require "trigger" local tile_w = arcade_config.tiles_width local tile_h = arcade_config.tiles_height @@ -157,6 +158,7 @@ print("GAME INIT") -- TRIGGERS -- if not menu then table.insert(actors,trigger.new(10,57,32,triggers.escena_abad_inici)) end + table.insert( actors, trigger.new(10,7,3,triggers.escena_abad_inici)) -- table.insert(actors,trigger.new(11,16,32,triggers.escena_abad_corfes)) -- -- table.insert(actors,trigger.new(31,12,32,triggers.escena_abad_portes)) @@ -176,7 +178,6 @@ print("GAME INIT") score.create() local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 ) - -- local abad_x, abad_y = arc_mapa_get_coords ( 77, 3, 2 ) abad:move(abad_x, abad_y) abad_make_safe( true ) @@ -372,11 +373,4 @@ function update_game() -- end end -function collision(a, b) - return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) - and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) - and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y) - and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h) -end - flow:registrar("game", {game_init}) diff --git a/data/helpers.lua b/data/helpers.lua index 3d0db1e..2753183 100644 --- a/data/helpers.lua +++ b/data/helpers.lua @@ -2,6 +2,21 @@ local shine_step = 1 local shine_wait = 0 local shine_pos = 0 +function collision(a, b) + return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) + and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) + and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y) + and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h) +end + +function remove_actor(actor) + for index, value in pairs(actors) do + if value == actor then + table.remove(actors,index) + end + end +end + function draw_shiny_rect(x, y, w, h, color, shine_color) draw.rect(x,y,w,h,color) diff --git a/data/main.lua b/data/main.lua index e6c147e..f6ed1f1 100644 --- a/data/main.lua +++ b/data/main.lua @@ -18,10 +18,7 @@ require "opcions" require "opcions_input" --require "fps" ---require "title" --require "menu" ---require "switches" ---require "trigger" coords.set_config({ @@ -87,7 +84,7 @@ function mini.init() surf.target(0) surf.cls(16) - flow:executar("title") + flow:executar("logo") end function mini.update() diff --git a/data/opcions_input.lua b/data/opcions_input.lua index 3d125f4..725f6f0 100644 --- a/data/opcions_input.lua +++ b/data/opcions_input.lua @@ -99,54 +99,12 @@ end function opcions_input_end() menu_opt = 0 - -- menu_state = update_options_menu; flow:finish() end function config_key(def_key, k) local end_setup=false local valid_key = true - -- if input_type==controller.input.kb then - -- if def_key.name=="up" then - -- keyUp=k - -- elseif def_key.name=="down" then - -- keyDown=k - -- elseif def_key.name=="left" then - -- keyLeft=k - -- elseif def_key.name=="right" then - -- keyRight=k - -- elseif def_key.name=="jump" then - -- keyJump=k - -- elseif def_key.name=="shoot" then - -- keyShoot=k - -- end_setup = true - -- else - -- valid_key = false - -- end - -- elseif input_type==controller.input.pad then - -- if def_key.name=="up" then - -- btnUp=k - -- elseif def_key.name=="down" then - -- btnDown=k - -- elseif def_key.name=="left" then - -- btnLeft=k - -- elseif def_key.name=="right" then - -- btnRight=k - -- elseif def_key.name=="jump" then - -- btnJump=k - -- elseif def_key.name=="shoot" then - -- btnShoot=k - -- elseif def_key.name=="next" then - -- btnCycle1=k - -- elseif def_key.name=="prev" then - -- btnCycle2=k - -- elseif def_key.name=="pause" then - -- btnPause=k - -- end_setup = true - -- else - -- valid_key = false - -- end - -- end if (input_type==controller.input.kb and def_key.name=="shoot") or (input_type==controller.input.pad and def_key.name=="pause") then diff --git a/data/trigger.lua b/data/trigger.lua index 882ae17..1bcebb5 100644 --- a/data/trigger.lua +++ b/data/trigger.lua @@ -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