[WIP] Lluita contra jefe.

This commit is contained in:
2026-04-08 23:04:23 +02:00
parent cbf265fe4d
commit 0a682b2440
8 changed files with 168 additions and 82 deletions

View File

@@ -29,6 +29,7 @@ end
function abad_init() function abad_init()
abad={ name="abad", abad={ name="abad",
id="abad",
x=40, y=24, x=40, y=24,
w=32, h=32, w=32, h=32,
flip=false, flip=false,

View File

@@ -199,18 +199,6 @@ function world_draw()
-- Pintar la finestra del mon -- Pintar la finestra del mon
render_map(sf_mapa, tiles, viewp.x, viewp.y) render_map(sf_mapa, tiles, viewp.x, viewp.y)
if #stages.boss_hot_points>0 then
for _, p in pairs(stages.boss_hot_points) do
p:draw()
end
-- local world_x, world_y = coords.room_to_world(45,2,1)
-- local scr_x, scr_y = viewp:screen_coords( world_x, world_y )
-- draw.line(scr_x, scr_y, scr_x, scr_y+25, 12)
-- draw.line(scr_x, scr_y+25, scr_x+15, scr_y+25, 12)
-- draw.line(scr_x+15, scr_y+25, scr_x+15, scr_y+35, 12)
-- draw.line(scr_x+15, scr_y+35, scr_x+45, scr_y+35, 12)
end
-- pintar warps -- pintar warps
for key,warp in pairs(warp.warp_list) do for key,warp in pairs(warp.warp_list) do
if viewp:inside(warp.x, warp.y, warp.w, warp.h) then if viewp:inside(warp.x, warp.y, warp.w, warp.h) then

View File

@@ -11,6 +11,13 @@ function collision(a, b)
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h) and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)
end end
function half_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) )
or ((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) function remove_actor(actor)
for index, value in pairs(actors) do for index, value in pairs(actors) do
if value == actor then if value == actor then

View File

@@ -50,7 +50,7 @@ function imp.new(_hab, _x, _y)
step=0, step=0,
hurting=0, hurting=0,
jumpfwd=false, jumpfwd=false,
step_length=0.7, step_length=1,
vmove_space=1, vmove_space=1,
max_jump_height=24, max_jump_height=24,
jump_height=0, jump_height=0,
@@ -66,16 +66,21 @@ function imp.new(_hab, _x, _y)
scene_object=false, scene_object=false,
fight_modes=_fight_modes, fight_modes=_fight_modes,
mode="stop", mode="stop",
mode_cooldown=100, mode_cooldown=1000,
super_cooldown=2000, super_cooldown=2000,
shot_cooldown=500, shot_cooldown=500,
action="", action="",
movement="",
enabled=true, enabled=true,
disable_reason="", disable_reason="",
can_warp=false, can_warp=false,
fight=imp.fight, fight=imp.fight,
draw=imp.draw, draw=imp.draw,
hit=imp.hit, hit=imp.hit,
hot_points={},
target={},
old_target={},
invencible=false,
-- direccio=imp.direccio, -- direccio=imp.direccio,
do_jump=imp.do_jump, do_jump=imp.do_jump,
jump=imp.jump, jump=imp.jump,
@@ -92,6 +97,9 @@ function imp.new(_hab, _x, _y)
movement=imp.movement, movement=imp.movement,
advance=imp.advance, advance=imp.advance,
reduce_cooldown=imp.reduce_cooldown, reduce_cooldown=imp.reduce_cooldown,
set_fight_mode=imp.set_fight_mode,
think=imp.think,
controller_input=imp.controller_input,
-- imp.enabled=false -- imp.enabled=false
-- imp.counter=500 -- imp.counter=500
} }
@@ -99,13 +107,31 @@ end
function imp:fight() function imp:fight()
print("FIGHTING MODE") print("FIGHTING MODE")
self.mode="away" table.insert(self.hot_points, point.new(54,5,4,12,8,"P1"))
table.insert(self.hot_points, point.new(44,5,3,12,8,"P2"))
table.insert(self.hot_points, point.new(55,7,4,12,8,"P3"))
table.insert(self.hot_points, point.new(45,7,3,12,8,"P4"))
table.insert(self.hot_points, point.new(44,12,5,12,8,"P5"))
table.insert(self.hot_points, point.new(54,12,4,12,8,"P6"))
table.insert(self.hot_points, abad);
self.mode="chase"
self.target = self.hot_points[3]
end end
function imp:draw() function imp:draw()
local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
draw.surf((self.frame&7)*self.w, (self.frame>>cxr2)*self.h, self.w, self.h, scr_x, scr_y, self.w, self.h, self.flip) draw.surf((self.frame&7)*self.w, (self.frame>>cxr2)*self.h, self.w, self.h, scr_x, scr_y, self.w, self.h, self.flip)
draw.rect(scr_x+self.bb.x,scr_y+self.bb.y,self.bb.w,self.bb.h,3) draw.rect(scr_x+self.bb.x,scr_y+self.bb.y,self.bb.w,self.bb.h,3)
if #self.hot_points>0 then
for _, p in pairs(self.hot_points) do
if self.target==p then
p:draw(true)
else
p:draw()
end
end
end
end end
function imp:hit() function imp:hit()
@@ -120,6 +146,7 @@ function imp:do_jump ( jumpfwd )
self.update=imp.state_jumping self.update=imp.state_jumping
self.step=0 self.step=0
self.jumpfwd=jumpfwd self.jumpfwd=jumpfwd
self.action=""
end end
function imp:state_jumping() function imp:state_jumping()
@@ -142,8 +169,8 @@ function imp:state_jumping()
-- cap endavant? -- cap endavant?
if self.jumpfwd then self:advance() end if self.jumpfwd then self:advance() end
self:set_fight_mode() -- self:set_fight_mode()
self.think() -- self:think()
self:controller_input() self:controller_input()
end end
@@ -194,7 +221,7 @@ function imp:jump()
end end
function imp:state_walking() function imp:state_walking()
-- msg_print(0,0,"state_walking",true) msg_print(16,48,"state_walking",true)
self:reduce_cooldown() self:reduce_cooldown()
-- Limitar la velocitat de moviment -- Limitar la velocitat de moviment
@@ -223,12 +250,12 @@ function imp:state_walking()
self:advance() self:advance()
self:set_fight_mode() self:set_fight_mode()
self.think() self:think()
self:controller_input() self:controller_input()
end end
function imp:state_falling() function imp:state_falling()
-- msg_print(0,0,"state_falling",true) msg_print(16,16,"state_falling",true)
self:reduce_cooldown() self:reduce_cooldown()
self.frame=30 self.frame=30
@@ -236,6 +263,7 @@ function imp:state_falling()
-- Si toca terra canviar el mode -- Si toca terra canviar el mode
if self:land() then if self:land() then
print("landing")
self.update=imp.state_normal self.update=imp.state_normal
return return
end end
@@ -248,13 +276,13 @@ function imp:state_falling()
-- Caiguent cap endavant? -- Caiguent cap endavant?
if self.jumpfwd then self:advance() end if self.jumpfwd then self:advance() end
self:set_fight_mode() -- self:set_fight_mode()
self.think() -- self:think()
self:controller_input() self:controller_input()
end end
function imp:land () function imp:land ()
-- msg_print(0,0,"land",true) msg_print(16,32,"land",true)
-- Els dos punts de baix de l'abad -- Els dos punts de baix de l'abad
local x1_check = self.x+self.bb.x local x1_check = self.x+self.bb.x
local x2_check = self.x+self.bb.x+self.bb.w local x2_check = self.x+self.bb.x+self.bb.w
@@ -281,7 +309,7 @@ end
function imp:advance() function imp:advance()
-- msg_print(0,0,"advance",true) -- msg_print(0,0,"advance",true)
local step_length=self.step_length; --lo que avança l'abad cada pas local step_length=self.step_length; --lo que avança el imp cada pas
local limit=tiletype.block local limit=tiletype.block
if self.update~=imp.state_walking then limit=tiletype.half end if self.update~=imp.state_walking then limit=tiletype.half end
@@ -293,7 +321,8 @@ function imp:advance()
-- end -- end
-- self.action=="right" -- self.action=="right"
if self.action=="left" then -- if self.action=="left" then
if self.movement=="left" then
step_length = -step_length step_length = -step_length
x_check = self.x+self.bb.x+step_length x_check = self.x+self.bb.x+step_length
end end
@@ -306,6 +335,7 @@ function imp:advance()
local hab,xx, yy = coords.world_to_tile(self.x, self.y) local hab,xx, yy = coords.world_to_tile(self.x, self.y)
self.hab = hab self.hab = hab
self.movement = ""
end end
-- Controlador principal del personatge -- Controlador principal del personatge
@@ -319,7 +349,7 @@ function imp:state_normal()
self.jumpfwd=false self.jumpfwd=false
self.jump_height = 0 self.jump_height = 0
self:set_fight_mode() self:set_fight_mode()
self.think() self:think()
self:controller_input() self:controller_input()
end end
@@ -333,11 +363,12 @@ function imp:away()
self.mode_cooldown = 150+math.random(50)-1 self.mode_cooldown = 150+math.random(50)-1
end end
function imp:super() function imp:state_super()
self.mode = self.fight_modes["super"] self.mode = self.fight_modes["super"]
self.mode_cooldown=1 self.mode_cooldown=1
print("SUPER POWER") print("SUPER POWER")
self.super_cooldown=2000 self.super_cooldown=2000
self.update=imp.state_normal
end end
function imp:shot(actor) function imp:shot(actor)
@@ -356,12 +387,12 @@ end
-- --
-- Traduir a una entrada de pad -- Traduir a una entrada de pad
------------------------------- -------------------------------
function imp:controller_input(abad) function imp:controller_input()
-- msg_print(0,0,"move",true) -- msg_print(0,0,"move",true)
-- self.action = self:movement(abad) -- self.action = self:movement(abad)
if self.action == "right" or self.action == "left" then if self.action == "right" or self.action == "left" then
-- To Do: Si esta caiguent no se pot canviar self.movement = self.action
self.update=imp.state_walking self.update=imp.state_walking
-- abad.flip=false -- abad.flip=false
elseif self.action == "jump" then elseif self.action == "jump" then
@@ -372,8 +403,9 @@ function imp:controller_input(abad)
-- abad_shot_cacau() -- abad_shot_cacau()
self:shot() self:shot()
elseif self.action == "super" then elseif self.action == "super" then
self:super() self.update=imp.state_super
end end
self.action = ""
end end
------------------------------- -------------------------------
@@ -383,40 +415,89 @@ end
-- a triar l'acció a fer i -- a triar l'acció a fer i
-- traduir a acció de pad -- traduir a acció de pad
------------------------------- -------------------------------
function imp:think( actor ) function imp:think( )
local scr_x, scr_y = viewp:screen_coords( self.x+self.bb.x, self.y )
-- local check_x =
-- local check_y =
local action = "stay" local action = "stay"
if self.mode=="stop" then return action end if self.mode=="stop" then return action end
if self.fight_modes[self.mode]=="away" or self.fight_modes[self.mode]=="chase" then if self.target.x+self.target.bb.x>=self.x+self.bb.x then
if self.y>abad.y action="right"
and arc_check_tile(self.x+(self.bb.x+(self.bb.w/2)),(self.y+(self.h/2)))~=tiletype.void then elseif self.target.x+self.target.bb.x<self.x+self.bb.x then
action = "jump" action="left"
elseif self.y==abad.y and math.abs(self.x-abad.x)<=8 then
action = "jumpfwd"
else
if self.fight_modes[self.mode]=="away" then
if abad.x<self.x then
action="right"
else
action="left"
end
elseif self.fight_modes[self.mode]=="chase" then
if abad.x>self.x then
action="right"
else
action="left"
end
end
end
elseif self.fight_modes[self.mode]=="super" then
action="super"
elseif self.fight_modes[self.mode]=="shot" then
action="shot"
end end
self.action = action -- Els dos punts de baix de l'abad
local x1_check = self.x+self.bb.x
local x2_check = self.x+self.bb.x+self.bb.w
local y_check = self.y+self.bb.h-2
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
draw.rect(scr_x+self.bb.x,scr_y+self.bb.h-1,16,16,2)
if collision(self, self.target) then
print("Next target "..tile_type1.." "..tile_code1)
self.mode_cooldown = 0
elseif half_collision(self, self.target) and tile_type1==tiletype.void and tile_type2==tiletype.void then -- and (self.y>self.target.y or self.y<self.target.y) ) then -- afegir que no hi haja tile per a escalar
print("Next Target 2 "..tile_type1.." "..tile_code1)
self.mode_cooldown = 0
-- self:set_fight_mode()
elseif tile_type1~=tiletype.void or tile_type2~=tiletype.void then
print("jump "..tile_type1..", "..tile_type2)
action="jump"
end
-- local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
-- draw.line(0,scr_y,256,scr_y,2)
-- draw.line(scr_x,0,scr_x,192,2)
-- if self.y+self.bb.y>=self.target.y+self.target.bb.y then
-- local tile_type, tile_code = arc_check_tile(self.x+self.bb.x,self.y+self.bb.h, true)
-- local tile_type2, tile_code2 = arc_check_tile(self.x+self.bb.x+self.bb.w,self.y+self.bb.h, true)
-- msg_print(50, 50, tile_type..", "..tile_code, true )
-- if tile_type ~=tiletype.void or tile_type2 ~=tiletype.void then
-- print("JUMP")
-- action = "jump"
-- else
-- if self.target.x+self.target.bb.x>=self.x+self.bb.x then
-- print("sense eixida")
-- -- self.mode_cooldown = 0
-- -- self:set_fight_mode()
-- end
-- end
-- -- elseif self.y==self.target.y and math.abs(self.x-self.target.x)<=8 then
-- -- action = "jumpfwd"
-- end
-- local ix, iy = viewp:screen_coords( self.x, self.y )
-- draw.rect(ix+(self.bb.x+(self.bb.w/2)), iy+(self.h/2), 2,2, 2)
-- if self.fight_modes[self.mode]=="away" or self.fight_modes[self.mode]=="chase" then
-- if self.y>=self.target.y
-- and arc_check_tile(self.x+(self.bb.x+(self.bb.w/2)),(self.y+(self.h/2)))~=tiletype.void then
-- action = "jump"
-- elseif self.y==self.target.y and math.abs(self.x-self.target.x)<=8 then
-- action = "jumpfwd"
-- else
-- if self.fight_modes[self.mode]=="away" then
-- if self.target.x<=self.x then
-- action="right"
-- else
-- action="left"
-- end
-- elseif self.fight_modes[self.mode]=="chase" then
-- if self.target.x>=self.x then
-- action="right"
-- else
-- action="left"
-- end
-- end
-- end
-- elseif self.fight_modes[self.mode]=="super" then
-- action="super"
-- elseif self.fight_modes[self.mode]=="shot" then
-- action="shot"
-- end
self.action = action
print(self.action)
return action return action
end end
@@ -440,13 +521,22 @@ function imp:set_fight_mode()
if self.mode_cooldown <= 0 then if self.mode_cooldown <= 0 then
-- seleccionar mode d'acció -- seleccionar mode d'acció
local last_mode=self.mode local last_mode=self.mode
self.mode_cooldown = 150+math.random(50)-1 -- self.mode_cooldown = 150+math.random(50)-1
self.mode=math.random(#self.fight_modes) self.mode_cooldown = 1000
-- self.mode=math.random(#self.fight_modes)
if self.mode==self.fight_modes["super"] and self.super_cooldown>0 then self.mode=self.fight_modes["shot"] end --
if self.mode==self.fight_modes["shot"] and self.shot_cooldown>0 then self.mode=self.fight_modes["chase"] end -- if self.mode==self.fight_modes["super"] and self.super_cooldown>0 then self.mode=self.fight_modes["shot"] end
-- if self.mode==self.fight_modes["shot"] and self.shot_cooldown>0 then self.mode=self.fight_modes["chase"] end
print("cambiar modo => "..self.fight_modes[self.mode]) self.mode=self.fight_modes["chase"]
-- print("cambiar modo => "..self.fight_modes[self.mode])
local new_point = math.random(#self.hot_points)
if self.target == self.hot_points[new_point] then new_point = ((new_point+1)%#self.hot_points)+1 end
self.old_target = self.target
self.target=self.hot_points[new_point]
print("target => "..self.target.id)
end end
-- -- if self.mode==last_mode then self.mode=((last_mode+1)%#self.fight_modes)+1 end -- -- if self.mode==last_mode then self.mode=((last_mode+1)%#self.fight_modes)+1 end
-- elseif self.mode_cooldown == 0 then -- elseif self.mode_cooldown == 0 then

View File

@@ -138,28 +138,29 @@ function arc_set_tile_by_index(hab,index,tile)
arc_set_tile(world_x, world_y, tile) arc_set_tile(world_x, world_y, tile)
end end
function arc_get_tile(world_x,world_y) function arc_get_tile(world_x,world_y, debug)
local map_x, map_y = coords.world_to_mini_tile(world_x,world_y) local map_x, map_y = coords.world_to_mini_tile(world_x,world_y)
if debug then print(map_x..", "..map_y) end
return map.tile(map_x,map_y) return map.tile(map_x,map_y)
end end
function arc_check_tile(world_x,world_y) function arc_check_tile(world_x,world_y,debug)
-- tiletype => void=0 / nonpc=1 / stair=2 / -- tiletype => void=0 / nonpc=1 / stair=2 /
-- switch=3 / half=4 / block=5 -- switch=3 / half=4 / block=5
local tile=map_to_editor_tile(arc_get_tile(world_x, world_y)) local tile=map_to_editor_tile(arc_get_tile(world_x, world_y, debug))
if tile<8 then if tile<8 then
return tiletype.half return tiletype.half, tile
elseif tile<15 then elseif tile<15 then
return tiletype.stair return tiletype.stair, tile
elseif tile==15 then elseif tile==15 then
return tiletype.switch return tiletype.switch, tile
elseif tile<64 then elseif tile<64 then
return tiletype.block return tiletype.block, tile
elseif tile==111 then elseif tile==111 then
return tiletype.nonpc return tiletype.nonpc, tile
else else
return tiletype.void return tiletype.void, tile
end end
end end

View File

@@ -12,13 +12,18 @@ function point.new(_hab,_x,_y,_x_offset,_y_offset,_id)
w=8, w=8,
h=8, h=8,
draw=point.draw, draw=point.draw,
bb={x=0,y=0,w=1,h=1},
} }
end end
function point:draw() function point:draw(fill)
local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
-- debug rect -- debug rect
draw.rect(scr_x,scr_y,self.w,self.h,3) if not fill then
draw.rect(scr_x,scr_y,self.w,self.h,3)
else
draw.rectf(scr_x,scr_y,self.w,self.h,3)
end
end end
function point:update() function point:update()

View File

@@ -128,7 +128,6 @@ end
function stages.stage1_boss() function stages.stage1_boss()
if not scene.running and not stages.boss_loaded then if not scene.running and not stages.boss_loaded then
set_actors_enabled_by_room(false, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
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) -- actors_in_room_backup_and_remove(stage1_boss_mapa.r0.r,stage1_boss_mapa.r1.r)
-- viewp:fixed({l=8,r=44,u=48,d=0}, viewp.x, viewp.y-48) -- viewp:fixed({l=8,r=44,u=48,d=0}, viewp.x, viewp.y-48)
@@ -137,12 +136,6 @@ function stages.stage1_boss()
boss.reason="" boss.reason=""
boss.enabled=true boss.enabled=true
boss:fight() boss:fight()
table.insert(stages.boss_hot_points, point.new(54,5,4,12,8,"P1"))
table.insert(stages.boss_hot_points, point.new(44,5,3,12,8,"P2"))
table.insert(stages.boss_hot_points, point.new(55,7,4,12,8,"P3"))
table.insert(stages.boss_hot_points, point.new(45,7,3,12,8,"P4"))
table.insert(stages.boss_hot_points, point.new(44,12,5,12,8,"P5"))
table.insert(stages.boss_hot_points, point.new(54,12,4,12,8,"P6"))
end end
end end

View File

@@ -131,8 +131,9 @@ function triggers:escena_habitacio_batman()
end end
function triggers:escena_lluita_imp() function triggers:escena_lluita_imp()
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.x, viewp.y-48) viewp:fixed({l=8,r=44,u=0,d=0}, viewp.x, viewp.y-48)
start_scene(scenes.lluita_imp, nil, false) -- start_scene(scenes.lluita_imp, nil, false)
remove_actor(self) remove_actor(self)
stages.stage1_boss_ready() stages.stage1_boss_ready()
end end