[WIP] Triggers
- Algo de neteja de codi
This commit is contained in:
@@ -13,6 +13,7 @@ require "caco"
|
|||||||
require "zombie"
|
require "zombie"
|
||||||
require "score"
|
require "score"
|
||||||
require "switches"
|
require "switches"
|
||||||
|
require "trigger"
|
||||||
|
|
||||||
local tile_w = arcade_config.tiles_width
|
local tile_w = arcade_config.tiles_width
|
||||||
local tile_h = arcade_config.tiles_height
|
local tile_h = arcade_config.tiles_height
|
||||||
@@ -157,6 +158,7 @@ print("GAME INIT")
|
|||||||
|
|
||||||
-- TRIGGERS
|
-- TRIGGERS
|
||||||
-- if not menu then table.insert(actors,trigger.new(10,57,32,triggers.escena_abad_inici)) end
|
-- 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(11,16,32,triggers.escena_abad_corfes))
|
||||||
--
|
--
|
||||||
-- table.insert(actors,trigger.new(31,12,32,triggers.escena_abad_portes))
|
-- table.insert(actors,trigger.new(31,12,32,triggers.escena_abad_portes))
|
||||||
@@ -176,7 +178,6 @@ print("GAME INIT")
|
|||||||
score.create()
|
score.create()
|
||||||
|
|
||||||
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
|
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:move(abad_x, abad_y)
|
||||||
abad_make_safe( true )
|
abad_make_safe( true )
|
||||||
|
|
||||||
@@ -372,11 +373,4 @@ function update_game()
|
|||||||
-- end
|
-- end
|
||||||
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})
|
flow:registrar("game", {game_init})
|
||||||
|
|||||||
@@ -2,6 +2,21 @@ local shine_step = 1
|
|||||||
local shine_wait = 0
|
local shine_wait = 0
|
||||||
local shine_pos = 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)
|
function draw_shiny_rect(x, y, w, h, color, shine_color)
|
||||||
draw.rect(x,y,w,h,color)
|
draw.rect(x,y,w,h,color)
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ require "opcions"
|
|||||||
require "opcions_input"
|
require "opcions_input"
|
||||||
|
|
||||||
--require "fps"
|
--require "fps"
|
||||||
--require "title"
|
|
||||||
--require "menu"
|
--require "menu"
|
||||||
--require "switches"
|
|
||||||
--require "trigger"
|
|
||||||
|
|
||||||
|
|
||||||
coords.set_config({
|
coords.set_config({
|
||||||
@@ -87,7 +84,7 @@ function mini.init()
|
|||||||
surf.target(0)
|
surf.target(0)
|
||||||
surf.cls(16)
|
surf.cls(16)
|
||||||
|
|
||||||
flow:executar("title")
|
flow:executar("logo")
|
||||||
end
|
end
|
||||||
|
|
||||||
function mini.update()
|
function mini.update()
|
||||||
|
|||||||
@@ -99,54 +99,12 @@ end
|
|||||||
|
|
||||||
function opcions_input_end()
|
function opcions_input_end()
|
||||||
menu_opt = 0
|
menu_opt = 0
|
||||||
-- menu_state = update_options_menu;
|
|
||||||
flow:finish()
|
flow:finish()
|
||||||
end
|
end
|
||||||
|
|
||||||
function config_key(def_key, k)
|
function config_key(def_key, k)
|
||||||
local end_setup=false
|
local end_setup=false
|
||||||
local valid_key = true
|
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")
|
if (input_type==controller.input.kb and def_key.name=="shoot")
|
||||||
or (input_type==controller.input.pad and def_key.name=="pause") then
|
or (input_type==controller.input.pad and def_key.name=="pause") then
|
||||||
|
|||||||
@@ -1,17 +1,29 @@
|
|||||||
trigger={}
|
trigger={}
|
||||||
|
|
||||||
function trigger.new(_hab,_x,_y,_fun)
|
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
|
end
|
||||||
|
|
||||||
function trigger:draw()
|
function trigger:draw()
|
||||||
-- do nothing
|
-- 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
|
end
|
||||||
|
|
||||||
function trigger:update()
|
function trigger:update()
|
||||||
if self.hab==abad.hab then
|
if self.hab==abad.hab then
|
||||||
if aabb(abad,self) then
|
if collision(abad,self) then
|
||||||
self:fun()
|
self:fun()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user