[WIP] Lluita contra jefes

-- El viewport ja es fixa i es solta
-- L'escenari ja se modifica i se restaura
This commit is contained in:
2026-04-04 22:00:51 +02:00
parent 9bb372a70b
commit b2cb8698b4
6 changed files with 117 additions and 78 deletions

View File

@@ -146,7 +146,7 @@ function viewport_update()
vp_y = abad.y - vp_center_offset_y vp_y = abad.y - vp_center_offset_y
if vp_y < 0 then vp_y = 0 end if vp_y < 0 then vp_y = 0 end
viewp:position(vp_x, vp_y) viewp:position(vp_x, vp_y)
end end
function world_update() function world_update()
@@ -310,6 +310,10 @@ function special_keys()
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.N9) then
mapa_restore_backup()
viewp:free_move()
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 ( 54, 6, 3 ) local abad_x, abad_y = coords.room_to_world ( 54, 6, 3 )

View File

@@ -1,6 +1,7 @@
local shine_step = 1 local shine_step = 1
local shine_wait = 0 local shine_wait = 0
local shine_pos = 0 local shine_pos = 0
local map_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)
@@ -124,6 +125,18 @@ function map_to_editor_tile(map_tile)
return result return result
end end
function mapa_backup(tx,ty,tile)
table.insert(map_backup,{x=tx,y=ty,val=tile})
end
function mapa_restore_backup()
for i = 1, #map_backup do
local e = map_backup[i]
map.tile(e.x, e.y, e.val)
end
map_backup = {}
end
function load_tilemap( sf_mapa, replace_map ) function load_tilemap( sf_mapa, replace_map )
local mapa_tw, mapa_th = surf.size(sf_mapa) local mapa_tw, mapa_th = surf.size(sf_mapa)
local nrooms = mapa_rooms_per_piso*mapa_pisos local nrooms = mapa_rooms_per_piso*mapa_pisos
@@ -158,7 +171,7 @@ function load_tilemap( sf_mapa, replace_map )
-- print(mapa_x0..", "..mapa_y0) -- print(mapa_x0..", "..mapa_y0)
-- print(mapa_x1..", "..mapa_y1) -- print(mapa_x1..", "..mapa_y1)
-- print(mapa_x1-mapa_x0..", "..mapa_y1-mapa_y0) -- print(mapa_x1-mapa_x0..", "..mapa_y1-mapa_y0)
print(replace_rooms_per_piso) -- print(replace_rooms_per_piso)
y = 0 y = 0
for ty=mapa_y0,mapa_y1 do --24 -> 41 = 17 (18) for ty=mapa_y0,mapa_y1 do --24 -> 41 = 17 (18)
@@ -168,10 +181,11 @@ function load_tilemap( sf_mapa, replace_map )
end end
xroom = yroom xroom = yroom
for tx=mapa_x0, mapa_x1 do -- 36 -> 59 = 23 (24) for tx=mapa_x0, mapa_x1 do -- 36 -> 59 = 23 (24)
print("ROOM= "..xroom.." ( "..x..", "..y.." ) <= "..(1+xroom)..", "..(1+x+y*mapa_room_cols)) -- print("ROOM= "..xroom.." ( "..x..", "..y.." ) <= "..(1+xroom)..", "..(1+x+y*mapa_room_cols))
-- print(replace_map.map[1+xroom][1+x+y*mapa_room_cols]) -- print(replace_map.map[1+xroom][1+x+y*mapa_room_cols])
local tile=editor_to_map_tile(replace_map.map[1+xroom][1+x+y*mapa_room_cols]) local tile=editor_to_map_tile(replace_map.map[1+xroom][1+x+y*mapa_room_cols])
mapa_backup(tx, ty, map.tile(tx,ty))
map.tile(tx, ty, tile) map.tile(tx, ty, tile)
x = x + 1 x = x + 1
if x == mapa_room_cols then if x == mapa_room_cols then

View File

@@ -15,23 +15,23 @@ function mapa_is_half_block_tile (ntile)
return half_block_set[ntile]==true return half_block_set[ntile]==true
end end
function mapa_do_backup() -- function mapa_do_backup()
mapa_backup={} -- mapa_backup={}
for i=1,#mapa do -- for i=1,#mapa do
mapa_backup[i]={} -- mapa_backup[i]={}
for j=1,#mapa[i] do -- for j=1,#mapa[i] do
mapa_backup[i][j]=mapa[i][j] -- mapa_backup[i][j]=mapa[i][j]
end -- end
end -- end
end -- end
--
function mapa_restore_backup() -- function mapa_restore_backup()
for i=1,#mapa do -- for i=1,#mapa do
for j=1,#mapa[i] do -- for j=1,#mapa[i] do
mapa[i][j]=mapa_backup[i][j] -- mapa[i][j]=mapa_backup[i][j]
end -- end
end -- end
end -- end
function mapa_new() function mapa_new()
for my=0,7 do for my=0,7 do

View File

@@ -22,11 +22,11 @@ scenes={
lluita_imp= { lluita_imp= {
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Eh!?","...","Tu qui eres?"},die=20}, {x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Eh!?","...","Tu qui eres?"},die=20},
{x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","Aaaarrrrgghhh",""},die=20,musica=audio_song_imp}, {x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","Aaaarrrrgghhh",""},die=20,musica=audio_song_imp},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Who are you?","Comment tu t'appel?","Quod nomen tibi est?"},die=20}, {x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"What is your name?","Come ti chiami?","Quod nomen tibi est?"},die=20},
{x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","Grwuuuunnnn",""},die=20}, {x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","Grwuuuunnnn",""},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Eeeerrrrggggg","Prruuuuuuummm","Uooooorrrr"},die=20}, {x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Eeeerrrrggggg","Prruuuuuuummm","Uooooorrrr"},die=20},
{x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","GROOOOAAAARRR",""},die=20}, {x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","GROOOOAAAARRR",""},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"MERDA!!","S'HA ENFADAT!!!","CACAUS A MI!!!!"},die=20}, {x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"A saber que li he dit!","TRANQUIL! TRANQUIL!!!"," CACAUS A MI!!!!"},die=20},
}, },
llibre_trobat={ llibre_trobat={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Este llibre...","Es el de les tècniques","especials dels abad..."}}, {x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Este llibre...","Es el de les tècniques","especials dels abad..."}},

View File

@@ -93,7 +93,9 @@ function stages.stage1_init()
abad:move(abad_x, abad_y) abad:move(abad_x, abad_y)
abad_make_safe( true ) abad_make_safe( true )
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
viewp:free_move()
end end
function stages.stage2_init() function stages.stage2_init()
@@ -102,6 +104,7 @@ end
function stage1_boss() function stage1_boss()
load_tilemap( sf_mapa, stage1_boss_mapa ) load_tilemap( sf_mapa, stage1_boss_mapa )
viewp:fixed({l=8,r=44,u=0,d=0})
end end
stage1_mapa={ stage1_mapa={

View File

@@ -14,7 +14,25 @@ function viewport.new(_width, _height)
tile= viewport.tile, tile= viewport.tile,
last_tile= viewport.last_tile, last_tile= viewport.last_tile,
screen_coords = viewport.screen_coords, screen_coords = viewport.screen_coords,
inside = viewport.inside } inside = viewport.inside,
fixed = viewport.fixed,
free_move = viewport.free_move,
range = nil, -- rang de moviment quan està fixat {r= , l=, u=, d= }
fixed_coord = nil, -- coordenades fixades
smooth_adjust = nil,
adjust_speed = 2
}
end
function viewport:fixed(range)
self.range = range
self.fixed_coord = {x=self.x, y=self.y}
end
function viewport:free_move()
self.range = nil
self.smooth_adjust = self.fixed_coord
self.fixed_coord = nil
end end
function viewport:get() function viewport:get()
@@ -33,30 +51,6 @@ function viewport:inside( x, y, w, h )
return result return result
end end
-- function viewport:coord2tile (x, y)
-- local tw = arcade_config.tiles_width
-- local th = arcade_config.tiles_height
-- local cols = mapa_room_cols
-- local rows = mapa_room_rows
-- local rooms_per_floor = mapa_rooms_per_piso
-- local xx = x or self.x
-- local yy = y or self.y
--
-- local calc_col = math.floor(xx / tw) % cols
-- local calc_row = math.floor(yy / th) % rows
-- local calc_room = math.floor(yy / (th * rows))*rooms_per_floor+math.floor(xx / (tw * cols))
-- -- print("X= "..self.x.." / W="..tw.." / C= "..cols.." > "..calc_col)
-- -- print("Y= "..self.y.." / H="..th.." / R= "..rows.." > "..calc_row)
-- -- print("CR= "..calc_row.." / RF= "..rooms_per_floor.." / CC= "..calc_col)
-- -- local tile_offset_x = self.x - (calc_col * tw * cols)
-- -- local tile_offset_y = self.y - (calc_row * th * rows)
-- local tile_offset_x = xx - (calc_col * tw) - ((calc_room%rooms_per_floor)*cols*tw)
-- local tile_offset_y = yy - (calc_row * th) - ( math.floor(calc_room/10)*rows*th)
-- -- print(self.x.." C"..calc_col.." W"..tw.." R"..calc_room.." c"..cols.." > "..tile_offset_x)
-- -- room, x, y, offset x, offset y
-- return calc_room, calc_col, calc_row, tile_offset_x, tile_offset_y
-- end
function viewport:tile () function viewport:tile ()
return coords.world_to_tile(self.x, self.y) return coords.world_to_tile(self.x, self.y)
end end
@@ -67,42 +61,66 @@ end
function viewport:coord2room () function viewport:coord2room ()
return coords.world_to_room(self.x, self.y) return coords.world_to_room(self.x, self.y)
-- local tw = arcade_config.tiles_width
-- local th = arcade_config.tiles_height
-- local cols = mapa_room_cols
-- local rows = mapa_room_rows
-- local rooms_per_floor = mapa_rooms_per_piso
--
-- local calc_col = math.floor(self.x / (tw * cols))
-- local calc_row = math.floor(self.y / (th * rows))
--
-- local calc_room = calc_row*rooms_per_floor+calc_col
-- return calc_room
end end
-- function viewport:room2coord ( room )
-- local tw = arcade_config.tiles_width
-- local th = arcade_config.tiles_height
-- local cols = mapa_room_cols
-- local rows = mapa_room_rows
-- local rooms_per_floor = mapa_rooms_per_piso
--
-- local x = (room % rooms_per_floor) * cols * tw
-- local y = math.floor(room/rooms_per_floor) * rows * th
--
-- local room_center_x_offset = (cols * tw) >> 1
-- local room_center_y_offset = (rows * th) >> 1
--
-- -- return x+room_center_x_offset, y+room_center_y_offset
-- return x, y
-- end
function viewport:position(x, y) function viewport:position(x, y)
local nx = (x ~= nil) and x or self.x local nx = (x ~= nil) and x or self.x
local ny = (y ~= nil) and y or self.y local ny = (y ~= nil) and y or self.y
self.x = nx if self.range==nil then
self.y = ny if self.smooth_adjust == nil then
self.x = nx
self.y = ny
else
-- viewport lliure després de fixar-lo -> Ajustar suau
self.x = nx
if self.smooth_adjust.x~=nil then
if nx<self.smooth_adjust.x-self.adjust_speed then
self.x=self.smooth_adjust.x-self.adjust_speed
self.smooth_adjust.x=self.smooth_adjust.x-self.adjust_speed
elseif nx>self.smooth_adjust.x+self.adjust_speed then
self.x=self.smooth_adjust.x+self.adjust_speed
self.smooth_adjust.x=self.smooth_adjust.x+self.adjust_speed
elseif math.abs(nx-self.smooth_adjust.x)<self.adjust_speed then
self.smooth_adjust.x = nil
end
end
self.y = ny
if self.smooth_adjust.y~=nil then
if ny<self.smooth_adjust.y-self.adjust_speed then
self.y=self.smooth_adjust.y-self.adjust_speed
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed
elseif ny>self.smooth_adjust.y+self.adjust_speed then
self.y=self.smooth_adjust.y+self.adjust_speed
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed
elseif math.abs(ny-self.smooth_adjust.y)<self.adjust_speed then
self.smooth_adjust.y = nil
end
end
if self.smooth_adjust.x == nil and self.smooth_adjust.y == nil then
self.smooth_adjust = nil
end
end
else
-- viewport fixe
self.x = nx
-- moure viewport left - right
if nx<self.fixed_coord.x-self.range.l then
self.x = self.fixed_coord.x-self.range.l
elseif nx>self.fixed_coord.x+self.range.r then
self.x = self.fixed_coord.x+self.range.r
end
self.y = ny
-- moure viewport up - down
if ny<self.fixed_coord.y-self.range.u then
self.y = self.fixed_coord.y-self.range.u
elseif ny>self.fixed_coord.y+self.range.d then
self.y = self.fixed_coord.y+self.range.d
end
end
return self.x, self.y return self.x, self.y
end end