[WIP] Lluita contra jefes. Eliminats actors de la zona de combat

This commit is contained in:
2026-04-05 17:32:08 +02:00
parent 4c2c8dc84f
commit 5aa9dd5051
6 changed files with 66 additions and 7 deletions

View File

@@ -29,10 +29,13 @@ function caco.new(_hab,_x,_y,_flip)
dying=false, dying=false,
death_time=40, death_time=40,
anim={19,19,20,21}, anim={19,19,20,21},
bb={x=4,y=4,w=24,h=16} } bb={x=4,y=4,w=24,h=16},
enabled= true,
disable_reason="" }
end end
function caco:draw() function caco:draw()
if not self.enabled then return end
-- if self.frame>0 then draw.surf((self.frame&7)*16,(self.frame>>3)*16,16,16,self.x,self.y,16,16,self.flip) end -- if self.frame>0 then draw.surf((self.frame&7)*16,(self.frame>>3)*16,16,16,self.x,self.y,16,16,self.flip) end
if self.warping then if self.warping then
@@ -62,6 +65,7 @@ function caco:draw()
end end
function caco:update_normal() function caco:update_normal()
if not self.enabled then return end
self.wait=self.wait+1 self.wait=self.wait+1
if self.wait==6 then if self.wait==6 then
@@ -116,6 +120,7 @@ function caco:update_normal()
end end
function caco:update_hit() function caco:update_hit()
if not self.enabled then return end
local step_time = self.death_time local step_time = self.death_time
if self.can_warp then if self.can_warp then
step_time = self.death_time/3; -- warp, wait, appear step_time = self.death_time/3; -- warp, wait, appear
@@ -181,6 +186,7 @@ function caco:update_hit()
end end
function caco:hit() function caco:hit()
if not self.enabled then return end
self.update=caco.update_hit self.update=caco.update_hit
if self.can_warp then self.warping=true end if self.can_warp then self.warping=true end

View File

@@ -316,6 +316,7 @@ function special_keys()
end end
if key.press(key.N9) then if key.press(key.N9) then
mapa_restore_backup() mapa_restore_backup()
set_actors_enabled_by_room(true, "boss", 44, 55)
viewp:free_move() viewp:free_move()
end end
if key.press(key.N8) then if key.press(key.N8) then

View File

@@ -2,6 +2,7 @@ local shine_step = 1
local shine_wait = 0 local shine_wait = 0
local shine_pos = 0 local shine_pos = 0
local map_backup = {} local map_backup = {}
local actors_backup = {}
function collision(a, b) function collision(a, b)
return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
@@ -18,6 +19,51 @@ function remove_actor(actor)
end end
end end
function set_actors_enabled_by_room(_enabled, _reason, room0, room1)
print("set_actors_enabled_by_room")
print(" hab_list")
room1 = room1 or room0
local rw=(room1-room0)%mapa_rooms_per_piso
local hab_list = {}
y = room0
while y<=room1 do
for x=y, y+rw do
hab_list[x]=true
print(" "..x)
end
y = y+mapa_rooms_per_piso
end
for index, actor in pairs(actors) do
if hab_list[actor.hab] and actor~=abad then
if actor.name then print(" "..actor.name) end
if actor.disable_reason then print(" "..actor.disable_reason) end
if actor.enabled then print("ENABLED") end
if not _enabled then
print("DISABLE ACTORS")
-- disable
if actor.enabled then
-- Si el actor està actiu -> deshabilitar amb motiu
actor.enabled=_enabled
actor.disable_reason = _reason
print("-> ".._reason)
end
else
-- enable
if actor.disable_reason and actor.disable_reason==_reason then
-- Si l'actor te un motiu per haver estat deshabilitat -> habilitar i borrar motiu
actor.enabled=_enabled
actor.disable_reason = ""
else
-- Habilitar l'actor si no te atribut disable_reason
actor.enabled=_enabled
end
end
end
end
end
function disable_actor_by_id( remove_set ) function disable_actor_by_id( remove_set )
local id_list = {} local id_list = {}
local ok = false local ok = false

View File

@@ -99,7 +99,7 @@ function stages.stage1_init()
-- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d)) -- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d))
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 = coords.room_to_world ( 54, 8, 3 ) local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
abad:move(abad_x, abad_y) abad:move(abad_x, abad_y)
abad_make_safe( true ) abad_make_safe( true )
@@ -116,6 +116,8 @@ end
function stage1_boss() function stage1_boss()
load_tilemap( sf_mapa, stage1_boss_mapa ) load_tilemap( sf_mapa, stage1_boss_mapa )
-- actors_in_room_backup_and_remove(stage1_boss_mapa.r0.r,stage1_boss_mapa.r1.r)
set_actors_enabled_by_room(false, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
viewp:fixed({l=8,r=44,u=0,d=0}) viewp:fixed({l=8,r=44,u=0,d=0})
end end

View File

@@ -6,7 +6,6 @@ function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors,_linked_id)
-- 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 if _id then print("NEW => ".._id) end
_type = _type or "invisible" _type = _type or "invisible"
if _linked_id then print("LINKED => ".._id.." -> ".._linked_id[1].." +") end
return { return {
name="trigger", name="trigger",
type=_type, type=_type,
@@ -23,6 +22,7 @@ if _linked_id then print("LINKED => ".._id.." -> ".._linked_id[1].." +") end
draw=trigger.draw, draw=trigger.draw,
linked_id=_linked_id, linked_id=_linked_id,
enabled=true, enabled=true,
disable_reason="",
bb=_bb } bb=_bb }
end end

View File

@@ -29,10 +29,13 @@ function zombie.new(_hab,_x,_y,_flip)
angle=0, angle=0,
d_angle=15, d_angle=15,
dying=false, dying=false,
death_time=40} death_time=40,
enabled=true,
disable_reason=""}
end end
function zombie:draw() function zombie:draw()
if not self.enabled then return end
-- if self.frame>0 then draw.surf((self.frame&7)*16,(self.frame>>3)*16,16,16,self.x,self.y,16,16,self.flip) end -- if self.frame>0 then draw.surf((self.frame&7)*16,(self.frame>>3)*16,16,16,self.x,self.y,16,16,self.flip) end
-- if self.frame>0 then draw.surf((self.frame&7)*cw,(self.frame>>cxr2)*ch,cw,ch,self.x*o2aX,self.y*o2aX,cw,ch,self.flip) end -- if self.frame>0 then draw.surf((self.frame&7)*cw,(self.frame>>cxr2)*ch,cw,ch,self.x*o2aX,self.y*o2aX,cw,ch,self.flip) end
if self.warping then if self.warping then
@@ -46,6 +49,7 @@ function zombie:draw()
end end
function zombie:update_normal() function zombie:update_normal()
if not self.enabled then return end
self.wait=self.wait+1 self.wait=self.wait+1
if self.wait==18 then if self.wait==18 then
@@ -92,6 +96,7 @@ function zombie:update_normal()
end end
function zombie:update_hit() function zombie:update_hit()
if not self.enabled then return end
self.wait=self.wait+1 self.wait=self.wait+1
if self.wait>=6 then if self.wait>=6 then
@@ -116,11 +121,10 @@ function zombie:update_hit()
end end
end end
end end
end end
function zombie:hit() function zombie:hit()
if not self.enabled then return end
self.update=zombie.update_hit self.update=zombie.update_hit
if self.can_warp then self.warping=true end if self.can_warp then self.warping=true end