[NEW] Switchs i triggers dependents enllaçats
[NEW] Visió remota al obrir-se una porta
This commit is contained in:
@@ -17,6 +17,7 @@ require "trigger"
|
||||
require "imp"
|
||||
|
||||
require "stage1"
|
||||
require "remote_view"
|
||||
|
||||
local DEBUG = true
|
||||
|
||||
@@ -106,16 +107,17 @@ function game_init(menu)
|
||||
table.insert(actors,abad)
|
||||
|
||||
score.create()
|
||||
|
||||
-- game_update=update_game
|
||||
flow:next()
|
||||
end
|
||||
|
||||
function render_map( sf_map, sf_tiles, x, y )
|
||||
|
||||
function render_map( sf_map, sf_tiles, x, y, target )
|
||||
target = target or 0
|
||||
map.surf(sf_map)
|
||||
map.cell(16, 16)
|
||||
surf.source(sf_tiles)
|
||||
surf.target(0)
|
||||
surf.target(target)
|
||||
view.origin(-x,-y)
|
||||
map.draw()
|
||||
view.origin(0,0)
|
||||
@@ -196,6 +198,8 @@ function world_draw()
|
||||
end
|
||||
|
||||
cacau:draw()
|
||||
|
||||
remote_view_draw()
|
||||
end
|
||||
|
||||
function update_game()
|
||||
@@ -314,9 +318,16 @@ function special_keys()
|
||||
mapa_restore_backup()
|
||||
viewp:free_move()
|
||||
end
|
||||
if key.press(key.N8) then
|
||||
-- abad go to room
|
||||
local abad_x, abad_y = coords.room_to_world ( 31, 8, 3 )
|
||||
print(abad_x..", "..abad_y)
|
||||
abad:move(abad_x, abad_y)
|
||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||
end
|
||||
if key.press(key.N0) then
|
||||
-- abad go to room
|
||||
local abad_x, abad_y = coords.room_to_world ( 54, 6, 3 )
|
||||
local abad_x, abad_y = coords.room_to_world ( 34, 3, 3 )
|
||||
print(abad_x..", "..abad_y)
|
||||
abad:move(abad_x, abad_y)
|
||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||
@@ -324,6 +335,7 @@ function special_keys()
|
||||
end
|
||||
|
||||
function debug_info()
|
||||
if true then return end
|
||||
font.current(font_default)
|
||||
viewp:print()
|
||||
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true)
|
||||
|
||||
@@ -18,6 +18,31 @@ function remove_actor(actor)
|
||||
end
|
||||
end
|
||||
|
||||
function disable_actor_by_id( remove_set )
|
||||
local id_list = {}
|
||||
local ok = false
|
||||
-- Construir llista per a eliminar
|
||||
if type(remove_set) == "string" then
|
||||
id_list[remove_set] = true
|
||||
ok = true
|
||||
elseif type(remove_set) == "table" then
|
||||
for _, v in ipairs(remove_set) do
|
||||
ok = true
|
||||
id_list[v] = true
|
||||
end
|
||||
end
|
||||
|
||||
-- eliminar
|
||||
if ok then
|
||||
for index, actor in pairs(actors) do
|
||||
if id_list[actor.id] then
|
||||
-- actors[index]=nil
|
||||
actor.enabled=false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function draw_shiny_rect(x, y, w, h, color, shine_color)
|
||||
draw.rect(x,y,w,h,color)
|
||||
|
||||
|
||||
36
data/remote_view.lua
Normal file
36
data/remote_view.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
remote_view_wait = 0
|
||||
remote_view_hab = ""
|
||||
remote_sf_w = mapa_room_cols*arcade_config.tiles_width
|
||||
remote_sf_h = mapa_room_rows*arcade_config.tiles_height
|
||||
|
||||
function remote_view_init ()
|
||||
sf_remote=surf.new(remote_sf_w, remote_sf_h)
|
||||
end
|
||||
|
||||
function remote_view(hab)
|
||||
remote_view_hab = hab
|
||||
remote_view_wait = 200
|
||||
end
|
||||
|
||||
function remote_view_draw()
|
||||
if remote_view_wait>0 then
|
||||
local x,y = coords.room_to_coord ( remote_view_hab )
|
||||
|
||||
local curr_source = surf.source()
|
||||
local curr_target = surf.target()
|
||||
|
||||
surf.target(sf_remote)
|
||||
surf.cls(16)
|
||||
render_map(sf_mapa, tiles, x, y, sf_remote )
|
||||
|
||||
surf.source(curr_source)
|
||||
surf.target(curr_target)
|
||||
|
||||
local curr_source = surf.source()
|
||||
surf.source(sf_remote)
|
||||
draw.surf(0,0,remote_sf_w,remote_sf_h,11,11,(remote_sf_w/2)-2,(remote_sf_h/2)-2)
|
||||
draw.rect(10,10,(remote_sf_w/2),(remote_sf_h/2),2)
|
||||
surf.source(curr_source)
|
||||
remote_view_wait = remote_view_wait-1
|
||||
end
|
||||
end
|
||||
@@ -70,26 +70,26 @@ function stages.stage1_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,"inici"))
|
||||
table.insert( actors, trigger.new(11,2,3,triggers.escena_abad_corfes,"corfes"))
|
||||
table.insert( actors, trigger.new(10,7,3,triggers.escena_abad_inici,"inici","TR01") )
|
||||
table.insert( actors, trigger.new(11,2,3,triggers.escena_abad_corfes,"corfes","TR02") )
|
||||
|
||||
table.insert( actors, trigger.new(31,1,3,triggers.escena_abad_portes,"portes"))
|
||||
table.insert( actors, trigger.new(31,6,3,triggers.escena_abad_portes,"portes"))
|
||||
table.insert( actors, trigger.new(71,7,3,triggers.escena_abad_portes,"portes"))
|
||||
table.insert( actors, trigger.new(31,1,3,triggers.escena_abad_portes,"portes","TR03") )
|
||||
table.insert( actors, trigger.new(31,6,3,triggers.escena_abad_portes,"portes","TR04") )
|
||||
table.insert( actors, trigger.new(71,7,3,triggers.escena_abad_portes,"portes","TR05") )
|
||||
|
||||
table.insert( actors, trigger.new(53,5,3,triggers.escena_abad_porta_casa,"porta casa"))
|
||||
table.insert( actors, trigger.new(56,4,3,triggers.escena_abad_porta_batman,"porta batman"))
|
||||
table.insert( actors, trigger.new(53,5,3,triggers.escena_abad_porta_casa,"porta casa","TR06"))
|
||||
table.insert( actors, trigger.new(56,4,3,triggers.escena_abad_porta_batman,"porta batman","TR07"))
|
||||
|
||||
table.insert( actors, trigger.new(19,32,32,triggers.escena_habitacio_batman,"habitacio batman"))
|
||||
--
|
||||
table.insert( actors, trigger.new(55,1,3,triggers.escena_lluita_imp,"lluita imp"))
|
||||
|
||||
table.insert( actors, trigger.new(10,8,1,triggers.open_door,"","primera porta","switch",{11, 57,45}) )
|
||||
table.insert( actors, trigger.new(34,1,1,triggers.open_door,"","dos portes casa abad","switch",{32, 50,38,26,53,41,29}) )
|
||||
table.insert( actors, trigger.new(52,1,1,triggers.open_door,"","porta casa abad","switch",{72, 42,30}) )
|
||||
table.insert( actors, trigger.new(60,1,1,triggers.open_door,"","altillo","switch",{54, 54,42}) )
|
||||
table.insert( actors, trigger.new(34,1,1,triggers.open_door,"","dos portes casa abad","switch",{32, 50,38,26,53,41,29},{"TR03","TR04"}) )
|
||||
table.insert( actors, trigger.new(52,1,1,triggers.open_door,"","porta casa abad","switch",{72, 42,30},{"TR05"}) )
|
||||
table.insert( actors, trigger.new(60,1,1,triggers.open_door,"","altillo","switch",{54, 54,42},{"TR06"}) )
|
||||
table.insert( actors, trigger.new(75,6,1,triggers.open_door,"","pasillo inf","switch",{77, 50,38,26}) )
|
||||
table.insert( actors, trigger.new(75,9,1,triggers.open_door,"","acces inf casa batman","switch",{57, 53,41}) )
|
||||
table.insert( actors, trigger.new(75,9,1,triggers.open_door,"","acces inf casa batman","switch",{57, 53,41},{"TR07"}) )
|
||||
table.insert( actors, trigger.new(79,5,1,triggers.open_door,"","sotan casa batman","switch",{36, 56,44}) )
|
||||
table.insert( actors, trigger.new(38,2,2,triggers.open_door,"","","switch",{39, 62,63}) )
|
||||
|
||||
@@ -105,6 +105,8 @@ function stages.stage1_init()
|
||||
|
||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||
|
||||
remote_view_init()
|
||||
|
||||
viewp:free_move()
|
||||
end
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
trigger={}
|
||||
|
||||
function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors)
|
||||
function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors,_linked_id)
|
||||
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
|
||||
_bb={x=0,y=0,w=16,h=16} --default
|
||||
if _type=="switch" then _bb={x=0,y=0,w=16,h=17} end
|
||||
-- if _type=="switch" then _bb={x=0,y=0,w=16,h=17} end
|
||||
if _id then print("NEW => ".._id) end
|
||||
_type = _type or "invisible"
|
||||
|
||||
if _linked_id then print("LINKED => ".._id.." -> ".._linked_id[1].." +") end
|
||||
return {
|
||||
name="trigger",
|
||||
type=_type,
|
||||
@@ -20,17 +21,21 @@ function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors)
|
||||
doors=_doors,
|
||||
update=trigger.update,
|
||||
draw=trigger.draw,
|
||||
linked_id=_linked_id,
|
||||
enabled=true,
|
||||
bb=_bb }
|
||||
end
|
||||
|
||||
function trigger:update()
|
||||
|
||||
if not self.enabled then return end
|
||||
if self.hab==abad.hab then
|
||||
if collision(abad,self) then
|
||||
if self.type=="switch" and self.enabled then
|
||||
sound.play(audio_switch)
|
||||
self.enabled=false
|
||||
self.enabled=false
|
||||
if self.linked_id then
|
||||
disable_actor_by_id(self.linked_id)
|
||||
end
|
||||
end
|
||||
self:fun()
|
||||
end
|
||||
@@ -38,6 +43,7 @@ function trigger:update()
|
||||
end
|
||||
|
||||
function trigger:draw()
|
||||
if self.type~="switch" and not self.enabled then return end
|
||||
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
||||
if self.type=="switch" then
|
||||
if self.enabled then
|
||||
@@ -63,6 +69,9 @@ triggers={}
|
||||
|
||||
function triggers:open_door()
|
||||
local hab= self.doors[1]-1
|
||||
if hab~=abad.hab then
|
||||
remote_view(hab)
|
||||
end
|
||||
for i=2,#self.doors do
|
||||
local tile_idx= self.doors[i]+1
|
||||
arc_set_tile_by_index(hab,tile_idx,mapa_empty_tile)
|
||||
|
||||
Reference in New Issue
Block a user