[WIP] Lluita contra jefes. Casi implementat se serebro de la bestia

This commit is contained in:
2026-04-06 01:58:49 +02:00
parent aaf5c0fb47
commit 6ac7a811d9
7 changed files with 498 additions and 115 deletions

View File

@@ -132,7 +132,7 @@ end
function abad_hurt(howmuch) function abad_hurt(howmuch)
-- howmuch = 0 howmuch = 0
if abad.hurting == 0 and abad.respawning==0 then if abad.hurting == 0 and abad.respawning==0 then
sound.play(audio_abad_hit) sound.play(audio_abad_hit)
abad.energia=abad.energia-howmuch abad.energia=abad.energia-howmuch
@@ -250,11 +250,11 @@ function abad_jump()
if abad.jump_in_half_block>0 then if abad.jump_in_half_block>0 then
abad.y=abad.y-vspace abad.y=abad.y-vspace
abad.jump_in_half_block = abad.jump_in_half_block-1 abad.jump_in_half_block = abad.jump_in_half_block-1
abad.jump_in_half_block_used = true
end end
end end
end end
abad.jump_height = abad.jump_height+1 abad.jump_height = abad.jump_height+1
abad.jump_in_half_block_used = true
end end
function abad_land () function abad_land ()

View File

@@ -309,43 +309,49 @@ end
function special_keys() function special_keys()
if key.press(key.N1) then if key.press(key.N1) then
-- abad prev room -- -- abad prev room
local hab = abad.hab-1 -- local hab = abad.hab-1
if hab<0 then hab=0 end -- if hab<0 then hab=0 end
local hab_x = 4 -- local hab_x = 4
local hab_y = 3 -- local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y) -- local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y) -- abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) -- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end end
if key.press(key.N2) then if key.press(key.N2) then
-- abad next room -- -- abad next room
local hab = abad.hab+1 -- local hab = abad.hab+1
if hab<0 then hab=0 end -- if hab<0 then hab=0 end
local hab_x = 4 -- local hab_x = 4
local hab_y = 3 -- local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y) -- local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y) -- abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) -- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N9) then
mapa_restore_backup()
set_actors_enabled_by_room(true, "boss", 44, 55)
viewp:free_move()
end end
if key.press(key.N8) then if key.press(key.N8) then
-- abad go to room -- local abad_x, abad_y = coords.room_to_world ( 31, 8, 3 )
local abad_x, abad_y = coords.room_to_world ( 31, 8, 3 ) -- print(abad_x..", "..abad_y)
print(abad_x..", "..abad_y) -- abad:move(abad_x, abad_y)
abad:move(abad_x, abad_y) -- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) imp.mode="away"
imp.mode_cooldown = 60000
print("away")
end
if key.press(key.N9) then
-- mapa_restore_backup()
-- set_actors_enabled_by_room(true, "boss", 44, 55)
-- viewp:free_move()
imp.mode="chase"
imp.mode_cooldown = 60000
print("chase")
end end
if key.press(key.N0) then if key.press(key.N0) then
-- abad go to room -- abad go to room
local abad_x, abad_y = coords.room_to_world ( 34, 3, 3 ) -- local abad_x, abad_y = coords.room_to_world ( 34, 3, 3 )
print(abad_x..", "..abad_y) -- print(abad_x..", "..abad_y)
abad:move(abad_x, abad_y) -- abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) -- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
imp.init()
end end
end end

View File

@@ -298,7 +298,7 @@ function msg_print(x, y, msg, direct_print )
else else
scr_x, scr_y = viewp:screen_coords(x, y) scr_x, scr_y = viewp:screen_coords(x, y)
end end
draw.rectf(scr_x,scr_y,45,7,16) draw.rectf(scr_x,scr_y,256,20,16)
draw.text(msg,scr_x+1,scr_y+1,2) draw.text(msg,scr_x+1,scr_y+1,2)
end end

View File

@@ -1,28 +1,27 @@
local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala
cxr = arcade_config.character_per_row-1
cxr2 = arcade_config.character_per_row_base2 cxr2 = arcade_config.character_per_row_base2
cw = arcade_config.character_width
ch = arcade_config.character_height
-- 4, 3 -- 4, 3
imp={hab=75, -- imp={hab=75,
x=24, -- x=24,
y=24, -- y=24,
w=32, -- w=32,
h=32, -- h=32,
flip=true, -- flip=true,
enabled=false, -- enabled=false,
counter=500, -- counter=500,
frame=28, -- frame=28,
wait=0, -- wait=0,
step=0, -- step=0,
anim={28,29,28,30}, -- anim={28,29,28,30},
bb={x=4,y=0,w=16,h=32}, -- bb={x=4,y=0,w=16,h=32},
scene_intro=false, -- scene_intro=false,
scene_object=false, -- scene_object=false,
mode="stop"} -- fight_modes={"chase","away","super","shot"},
-- mode="stop",
-- mode_cooldown=100}
imp = {}
function imp.reset() function imp.reset()
imp.hit=imp.hit imp.hit=imp.hit
@@ -33,67 +32,441 @@ function imp.reset()
imp.counter=500 imp.counter=500
end end
function imp.init() function imp.new(_hab, _x, _y)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
_fight_modes={"chase","away","super","shot"}
for i,v in ipairs(_fight_modes) do _fight_modes[v] = i end
return { name="imp",
hab=_hab,
x=world_x, y=world_y,
w=32, h=32,
flip=true,
frame=28,
wait=0,
vides=1,
energia=6,
max_energia=6,
falling=0,
step=0,
hurting=0,
jumpfwd=false,
step_length=1,
vmove_space=1,
max_jump_height=24,
jump_height=0,
jump_in_half_block=0,
jump_in_half_block_used = false,
max_shoot_cooldown=24,
shot_power=1,
shot_num_shots=1,
shoot_cooldown=25,
anim={28,29,28,30},
bb={x=8,y=0,w=16,h=32},
scene_intro=false,
scene_object=false,
fight_modes=_fight_modes,
mode="stop",
mode_cooldown=100,
super_cooldown=2000,
shot_cooldown=500,
action="",
fight=imp.fight,
draw=imp.draw,
hit=imp.hit,
direccio=imp.direccio,
do_jump=imp.do_jump,
jump=imp.jump,
state_jumping=imp.state_jumping,
chase=imp.chase,
away=imp.away,
move=imp.move,
super=imp.super,
shot=imp.shot,
do_flip=imp.do_flip,
update=imp.state_normal,
land=imp.land,
mode_controller=imp.mode_controller,
movement=imp.movement,
advance=imp.advance,
reduce_cooldown=imp.reduce_cooldown,
-- imp.enabled=false -- imp.enabled=false
-- imp.hit=imp.hit -- imp.counter=500
-- imp.update=imp.update }
-- imp.draw=imp.draw
-- imp.hab=abad.hab
-- if abad.x<40 then
-- if check_tile(imp.hab,92,38)<tiletype.half and
-- check_tile(imp.hab,84,38)<tiletype.half and
-- check_tile(imp.hab,92,30)<tiletype.half and
-- check_tile(imp.hab,84,30)<tiletype.half and
-- check_tile(imp.hab,92,46)>=tiletype.half then
-- imp.enabled=true
-- imp.flip=true
-- imp.x=92
-- else
-- imp.reset()
-- end
-- else
-- if check_tile(imp.hab,0,38)<tiletype.half and
-- check_tile(imp.hab,8,38)<tiletype.half and
-- check_tile(imp.hab,0,30)<tiletype.half and
-- check_tile(imp.hab,0,30)<tiletype.half and
-- check_tile(imp.hab,0,46)>=tiletype.half then
-- imp.enabled=true
-- imp.flip=false
-- imp.x=-12
-- else
-- imp.reset()
-- end
-- end
imp.hab=55
local world_x, world_y = coords.room_to_world(55,4,3)
imp.x=world_x
imp.y=world_y
imp.flip = true
end end
function imp.draw() function imp:fight()
-- if imp.enabled then print("FIGHTING MODE")
-- -- draw.surf((imp.frame&7)*16,(imp.frame>>3)*16,16,16,imp.x,imp.y,16,16,imp.flip) self.mode="away"
-- draw.surf((imp.frame&7)*cw,(imp.frame>>cxr2)*ch,cw,ch,imp.x*o2aX,imp.y*o2aX,cw,ch,imp.flip)
-- end
local scr_x, scr_y = viewp:screen_coords( imp.x, imp.y )
draw.surf((imp.frame&7)*imp.w, (imp.frame>>cxr2)*imp.h, imp.w, imp.h, scr_x, scr_y, imp.w, imp.h, imp.flip)
end end
function imp.hit() function imp:draw()
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.rect(scr_x+self.bb.x,scr_y+self.bb.y,self.bb.w,self.bb.h,3)
end end
function imp.update() function imp:hit()
if mode=="chase" then
if abad.x<imp.x then
imp.x=imp.x-1
elseif abad.x>imp.x then
imp.x=imp.x+1
end
end
-- imp.wait=imp.wait+1
-- --
-- if imp.wait==6 then end
function imp:direccio( actor )
msg_print(0,0,"direccio",true)
local check_side = "L"
-- definir el punts per a comprobar en el mapa
if self.fight_modes[self.mode]=="away" then
if actor.x>self.x then
-- caminar cap "enrere", check costat esq
check_side = "L"
else
-- caminar cap "endavant", check costat dret
check_side = "R"
end
elseif self.fight_modes[self.mode]=="chase" then
if actor.x>self.x then
-- caminar cap "endavant", check costat dret
check_side = "R"
else
-- caminar cap "enrere", check costat esq
check_side = "L"
end
end
local step = 1
if check_side=="L" then step = -step end
return step
end
function imp:do_jump ( jumpfwd )
msg_print(0,0,"do_jump",true)
-- Inicialització de fer el salt
jumpfwd = jumpfwd or false
self.jump_height = 0
self.update=imp.state_jumping
self.step=0
self.jumpfwd=jumpfwd
end
function imp:state_jumping()
msg_print(0,0,"state_jumping",true)
self:reduce_cooldown()
-- ??
self.wait=self.wait+1
self.wait=0
-- Pujar o caure
if self.jump_height<self.max_jump_height then
-- Comprovar que pasa en l'aire
self:jump()
else
-- Canviar a mode caure
self.update=imp.state_falling
end
self.step=self.step+1
-- cap endavant?
if self.jumpfwd then self:advance() end
end
function imp:jump()
msg_print(0,0,"jump",true)
local vspace = self.vmove_space
-- Els dos punts de dalt del personatge
local x1_check = self.x+self.bb.x
local x2_check = self.x+self.bb.x+self.bb.w
local y_check = self.y-vspace; -- posicio de dalt
-- Comprovar on està pegant
local tile1_hit_type= arc_check_tile(x1_check, y_check )
local tile2_hit_type= arc_check_tile(x2_check, y_check)
local not_block_tile = tile1_hit_type ~= tiletype.block and tile2_hit_type ~= tiletype.block
-- Fer l'acció que correspon
if not_block_tile then
-- Ascendir
self.y=self.y-vspace
else
-- Si es un bloc permetre gastar l'espai no pintat
local tile1_hit = arc_get_tile(x1_check, y_check )
local tile2_hit = arc_get_tile(x2_check, y_check)
local half_block1 = mapa_is_half_block_tile(map_to_editor_tile(tile1_hit))
local half_block2 = mapa_is_half_block_tile(map_to_editor_tile(tile2_hit))
local full_block1 = tile1_hit_type == tiletype.block and not half_block1
local full_block2 = tile2_hit_type == tiletype.block and not half_block2
local full_block = full_block1 and full_block2
local half_block = half_block1 or half_block2
-- Si ninguno dels tiles tocats es un block complet
-- i almenys un dels tiles tocats es mig tile
-- permetre continuar en el salt
if not full_block and half_block then
if self.jump_in_half_block==0 and not self.jump_in_half_block_used then
self.jump_in_half_block = arcade_config.tiles_height / 2
end
if self.jump_in_half_block>0 then
self.y=self.y-vspace
self.jump_in_half_block = self.jump_in_half_block-1
self.jump_in_half_block_used = true
end
end
end
-- Registrar el desplaçament
self.jump_height = self.jump_height+1
end
function imp:state_walking()
msg_print(0,0,"state_walking",true)
self:reduce_cooldown()
-- Limitar la velocitat de moviment
self.wait=self.wait+1
-- representació del moviment
-- if self.wait==6 then
-- self.wait=0
-- self.step=(self.step+1)%2
-- self.frame=self.anim[self.step+1]
-- end
-- Selecció de frame
if self.wait==6 then
self.wait=0
self.step=(self.step+1)%4
self.frame=self.anim[self.step+1]
end
-- Comprovar dos punts de contacte del personatge en el piso a vore si cau
local x1_check = self.x+self.bb.x
local x2_check = x1_check+self.bb.w
local y_check = self.y+self.bb.h; -- base del personatge
local tile1 = arc_check_tile(x1_check,y_check)
local tile2 = arc_check_tile(x2_check,y_check)
if tile1==tiletype.void and tile2==tiletype.void then
-- si no hi ha piso, caure
self.update=imp.state_falling
return
end
self:advance()
self:move()
end
function imp:state_falling()
msg_print(0,0,"state_falling",true)
self:reduce_cooldown()
-- print("state_falling")
self.frame=30
self.wait=self.wait+1
-- Si toca terra canviar el mode
if self:land() then
self.update=imp.state_normal
return
end
-- Seguir caiguent
self.y=self.y+1
self.jump_height = self.jump_height-1
self.falling=self.falling+1
-- Caiguent cap endavant?
if self.jumpfwd then self:advance() end
end
function imp:land ()
msg_print(0,0,"land",true)
-- 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
-- Comprovar on està aterrant
local tile1_hit= arc_check_tile(x1_check, y_check )
local tile2_hit= arc_check_tile(x2_check, y_check)
local floor_tile = tile1_hit>=tiletype.half or tile2_hit>=tiletype.half
-- Encara que siga un tile de piso s'ha de comprovar que
-- la y es un múltiple de l'alt dels tiles
local over_tile = (y_check & 0xF) == 0
local can_land = floor_tile and over_tile
if can_land then
self.jump_in_half_block_used = false
self.jump_height = 0
end
return can_land
end
function imp:advance()
msg_print(0,0,"advance",true)
local step_length=self.step_length; --lo que avança l'abad cada pas
local limit=tiletype.block
if self.update~=imp.state_walking then limit=tiletype.half end
local x_check = self.x+self.bb.x+self.bb.w+step_length
-- if self.flip then
-- step_length = -step_length
-- x_check = self.x+self.bb.x+step_length
-- end
-- self.action=="right"
if self.action=="left" then
step_length = -step_length
x_check = self.x+self.bb.x+step_length
end
local y_check = self.y+self.bb.h-4
if arc_check_tile(x_check, y_check)<limit then
self.x=self.x+step_length
end
local hab,xx, yy = coords.world_to_tile(self.x, self.y)
self.hab = hab
end
-- Controlador principal del personatge
function imp:state_normal()
msg_print(0,0,"state_normal",true)
self:reduce_cooldown()
self.frame=28
self.wait=0
self.step=0
self.jumpfwd=false
self.jump_height = 0
self:move()
end
function imp:chase()
self.mode = self.fight_modes["chase"]
self.mode_cooldown = 150+math.random(50)-1
end
function imp:away()
self.mode = self.fight_modes["away"]
self.mode_cooldown = 150+math.random(50)-1
end
function imp:super()
self.mode = self.fight_modes["super"]
self.mode_cooldown=1
print("SUPER POWER")
self.super_cooldown=2000
end
function imp:shot(actor)
self.mode = self.fight_modes["shot"]
self.mode_cooldown=1
print("FIREBALL!!")
self.shot_cooldown = 500
end
function imp:do_flip(actor)
if actor.x<self.x then self.flip=true else self.flip=false end
end
function imp:move(abad)
msg_print(0,0,"move",true)
self:mode_controller()
self.action = self:movement(abad)
-- print(action)
if self.action == "right" or self.action == "left" then
self.update=imp.state_walking
-- abad.flip=false
elseif self.action == "jump" then
self:do_jump()
elseif self.action == "jumpfwd" then
self:do_jump(true)
elseif self.action == "shot" then
-- abad_shot_cacau()
self:shot()
elseif self.action == "super" then
self:super()
end
end
function imp:movement( actor )
local action = "stay"
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.y>abad.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==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
return action
end
function imp:reduce_cooldown()
if self.mode=="stop" then return end
self.mode_cooldown = self.mode_cooldown -1
self.super_cooldown = self.super_cooldown -1
self.shoot_cooldown = self.shoot_cooldown -1
end
function imp:mode_controller()
if self.mode=="stop" then return end
if self.mode_cooldown <= 0 then
-- seleccionar mode d'acció
local last_mode=self.mode
self.mode_cooldown = 150+math.random(50)-1
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
print("cambiar modo => "..self.fight_modes[self.mode])
end
-- -- if self.mode==last_mode then self.mode=((last_mode+1)%#self.fight_modes)+1 end
-- elseif self.mode_cooldown == 0 then
-- if self.shot_cooldown<=0 then self.mode=self.fight_modes["shot"] end;
-- end
self:do_flip(abad)
-- self:movement(abad)
-- comprovar colisio en l'abad
if viewp:inside(self.x, self.y, self.w, self.h) then
if collision(abad,self) then
abad_hurt(1)
end
end
--if imp.wait==6 then
-- imp.wait=0 -- imp.wait=0
-- if not imp.enabled then -- if not imp.enabled then
-- imp.counter=imp.counter-1 -- imp.counter=imp.counter-1
@@ -128,6 +501,6 @@ function imp.update()
-- end -- end
-- end -- end
-- --
-- end --end
end end

View File

@@ -2,6 +2,7 @@ stages = {}
stages.boss_ready = false stages.boss_ready = false
stages.boss_loaded = false stages.boss_loaded = false
boss = nil
function stages.stage1_init() function stages.stage1_init()
mapa = stage1_mapa mapa = stage1_mapa
@@ -25,8 +26,8 @@ function stages.stage1_init()
elalien.init() elalien.init()
table.insert(actors,elalien) table.insert(actors,elalien)
imp.init() boss = imp.new(55,4,3)
table.insert(actors,imp) table.insert( actors, boss )
--batman --batman
@@ -131,6 +132,7 @@ function stages.stage1_boss()
-- 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:fixed({l=8,r=44,u=48,d=0})
stages.boss_loaded = true stages.boss_loaded = true
boss:fight()
end end
end end

View File

@@ -4,7 +4,7 @@ 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) local world_x, world_y = coords.room_to_world(_hab,_x,_y)
_bb={x=0,y=0,w=16,h=16} --default _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 -- if _id then print("NEW => ".._id) end
_type = _type or "invisible" _type = _type or "invisible"
return { return {
name="trigger", name="trigger",

View File

@@ -84,6 +84,8 @@ function zombie:update_normal()
end end
end end
self.hab = coords.world_to_room(self.x, self.y)
-- if self.hab==abad.hab then -- if self.hab==abad.hab then
-- if aabb(abad,self) then -- if aabb(abad,self) then
-- abad_hurt(1) -- abad_hurt(1)