[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

@@ -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})

View File

@@ -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)

View File

@@ -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()

View File

@@ -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

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