From 9bb372a70b1ab39c1522cab6d453d6a9e35c2dfb Mon Sep 17 00:00:00 2001 From: JailGamer Date: Sat, 4 Apr 2026 20:45:14 +0200 Subject: [PATCH] [WIP] Lluita contra jefes --- data/coords.lua | 12 +++++ data/game.lua | 101 +++------------------------------- data/helpers.lua | 64 ++++++++++++++++------ data/main.lua | 2 +- data/stage1.lua | 137 +++++++++++++++++++++++++++++++++++++++++++++++ data/trigger.lua | 5 +- 6 files changed, 209 insertions(+), 112 deletions(-) diff --git a/data/coords.lua b/data/coords.lua index 10b6ded..d5795e6 100644 --- a/data/coords.lua +++ b/data/coords.lua @@ -86,6 +86,18 @@ function coords.room_to_coord ( room, center ) return x, y end +function coords.room_to_mini_tile( room, x, y ) + -- room=room-1 + x=x-1 + y=y-1 + local tx = room % coords.ROOMS_PER_FLOOR -- columna de l'habitació + tx = tx * coords.ROOM_COLS+x + local ty = math.floor(room / coords.ROOMS_PER_FLOOR) -- fila de l'habitació + ty = ty * coords.ROOM_ROWS+y + + return tx, ty +end + -- local TILE_W = arcade_config.tiles_width -- local TILE_H = arcade_config.tiles_height -- local ROOM_COLS = mapa_room_cols diff --git a/data/game.lua b/data/game.lua index b7de17f..9ce864a 100644 --- a/data/game.lua +++ b/data/game.lua @@ -18,6 +18,8 @@ require "imp" require "stage1" +local DEBUG = true + local tile_w = arcade_config.tiles_width local tile_h = arcade_config.tiles_height local res_w = arcade_config.resolucion.width @@ -103,95 +105,7 @@ function game_init(menu) abad_init() table.insert(actors,abad) - llibre.init() - table.insert(actors,llibre) - - gorro.init() - table.insert(actors,gorro) - - peu.init() - table.insert(actors,peu) - - premiere.init() - table.insert(actors,premiere) - - elalien.init() - table.insert(actors,elalien) - - imp.init() - table.insert(actors,imp) - - --batman - - bol.init() - table.insert(actors,bol) - - table.insert( actors, gota.new(70,5,1,20) ) - table.insert( actors, gota.new(70,9,1,30) ) - table.insert( actors, gota.new(63,5,1,25,2,-7) ) - table.insert( actors, gota.new(63,9,1,20,0,-8) ) - table.insert( actors, gota.new(64,3,1,10,0,-6) ) - table.insert( actors, gota.new(64,6,1,25,-1,-5) ) - table.insert( actors, gota.new(65,7,1,10,0,-7) ) - table.insert( actors, gota.new(65,8,1,25,0,-7) ) - table.insert( actors, gota.new(66,3,1,10,0,-7) ) - table.insert( actors, gota.new(66,4,1,15,0,-7) ) - table.insert( actors, gota.new(77,2,1,30,-5,-7) ) - table.insert( actors, gota.new(77,9,1,25,-5,-7) ) - - -- FOC? - table.insert(actors,invisible.new(77,5,4)) - table.insert(actors,invisible.new(77,6,4)) - table.insert(actors,invisible.new(58,2,4)) - table.insert(actors,invisible.new(58,3,4)) - - table.insert( actors, caco.new(13,3,2,true ) ) - table.insert( actors, caco.new(17,3,2,false) ) - table.insert( actors, caco.new(20,3,2,false) ) - table.insert( actors, caco.new(26,3,2,false) ) - table.insert( actors, caco.new(37,3,2,false) ) - table.insert( actors, caco.new(41,3,2,false) ) - table.insert( actors, caco.new(50,3,2,false) ) - table.insert( actors, caco.new(57,3,2,false) ) - table.insert( actors, caco.new(61,3,2,false) ) - - table.insert( actors, zombie.new(2, 3, 3,false) ) - table.insert( actors, zombie.new(28, 3, 3,false) ) - table.insert( actors, zombie.new(32, 3, 3,false) ) - table.insert( actors, zombie.new(44, 3, 3,false) ) - table.insert( actors, zombie.new(46, 3, 3,false) ) - table.insert( actors, zombie.new(54, 3, 3,false) ) - table.insert( actors, zombie.new(68, 3, 3,false) ) - table.insert( actors, zombie.new(73, 3, 3,false) ) - - -- 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(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(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(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(14,40,32,triggers.teleport_a)) - -- table.insert(actors,trigger.new(67,8,32,triggers.teleport_b)) - -- table.insert(actors,trigger.new(29,40,32,triggers.teleport_c)) - -- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d)) - score.create() - - local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 ) - -- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 ) - abad:move(abad_x, abad_y) - abad_make_safe( true ) - - local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) -- game_update=update_game flow:next() @@ -219,6 +133,7 @@ function load_stage() end function viewport_update() + -- Moure el viewport local vp_x = viewp.x local vp_y = viewp.y @@ -288,19 +203,19 @@ function update_game() surf.target(0) surf.cls(16) - - -- special_keys() world_update() - -- Moure el viewport viewport_update() world_draw() score.draw() - -- debug_info() + if DEBUG then + special_keys() + debug_info() + end end function pause() @@ -397,7 +312,7 @@ function special_keys() end if key.press(key.N0) then -- abad go to room - local abad_x, abad_y = coords.room_to_world ( 70, 6, 3 ) + local abad_x, abad_y = coords.room_to_world ( 54, 6, 3 ) print(abad_x..", "..abad_y) abad:move(abad_x, abad_y) local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) diff --git a/data/helpers.lua b/data/helpers.lua index 2753183..ca0400c 100644 --- a/data/helpers.lua +++ b/data/helpers.lua @@ -124,31 +124,63 @@ function map_to_editor_tile(map_tile) return result end -function load_tilemap( sf_mapa ) +function load_tilemap( sf_mapa, replace_map ) local mapa_tw, mapa_th = surf.size(sf_mapa) local nrooms = mapa_rooms_per_piso*mapa_pisos local x = 0 local y = 0 local yroom = 0 local xroom = 0 - + map.surf(sf_mapa) - for ty=0,mapa_th-1 do - if y == mapa_room_rows then - yroom = yroom + mapa_rooms_per_piso - y = 0 - end - xroom = yroom - for tx=0,mapa_tw-1 do - local tile=editor_to_map_tile(mapa[1+xroom][1+x+y*mapa_room_cols]) - map.tile(tx, ty, tile) - x = x + 1 - if x == mapa_room_cols then - x = 0 - xroom = xroom + 1 + if replace_map==nil then + for ty=0,mapa_th-1 do + if y == mapa_room_rows then + yroom = yroom + mapa_rooms_per_piso + y = 0 end + xroom = yroom + for tx=0,mapa_tw-1 do + local tile=editor_to_map_tile(mapa[1+xroom][1+x+y*mapa_room_cols]) + map.tile(tx, ty, tile) + x = x + 1 + if x == mapa_room_cols then + x = 0 + xroom = xroom + 1 + end + end + y = y +1 + end + else + local mapa_x0, mapa_y0 = coords.room_to_mini_tile( replace_map.r0.r, replace_map.r0.x, replace_map.r0.y ) + local mapa_x1, mapa_y1 = coords.room_to_mini_tile( replace_map.r1.r, replace_map.r1.x, replace_map.r1.y ) + local replace_rooms_per_piso = ((replace_map.r1.r-replace_map.r0.r)+1)%mapa_rooms_per_piso + -- print(mapa_x0..", "..mapa_y0) + -- print(mapa_x1..", "..mapa_y1) + -- print(mapa_x1-mapa_x0..", "..mapa_y1-mapa_y0) + print(replace_rooms_per_piso) + + y = 0 + for ty=mapa_y0,mapa_y1 do --24 -> 41 = 17 (18) + if y == mapa_room_rows then + yroom = yroom + replace_rooms_per_piso + y = 0 + end + xroom = yroom + 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(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]) + map.tile(tx, ty, tile) + x = x + 1 + if x == mapa_room_cols then + x = 0 + xroom = xroom + 1 + end + end + y = y +1 end - y = y +1 end end diff --git a/data/main.lua b/data/main.lua index 3eade12..857af47 100644 --- a/data/main.lua +++ b/data/main.lua @@ -87,7 +87,7 @@ function mini.init() surf.target(0) surf.cls(16) - flow:executar("logo") + flow:executar("game") end function mini.update() diff --git a/data/stage1.lua b/data/stage1.lua index e9d56b1..f4e4927 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -6,12 +6,104 @@ function stages.stage1_init() mapa.wait=0 mapa.step=0 load_tilemap( sf_mapa ) + + llibre.init() + table.insert(actors,llibre) + + gorro.init() + table.insert(actors,gorro) + + peu.init() + table.insert(actors,peu) + + premiere.init() + table.insert(actors,premiere) + + elalien.init() + table.insert(actors,elalien) + + imp.init() + table.insert(actors,imp) + + --batman + + bol.init() + table.insert(actors,bol) + + table.insert( actors, gota.new(70,5,1,20) ) + table.insert( actors, gota.new(70,9,1,30) ) + table.insert( actors, gota.new(63,5,1,25,2,-7) ) + table.insert( actors, gota.new(63,9,1,20,0,-8) ) + table.insert( actors, gota.new(64,3,1,10,0,-6) ) + table.insert( actors, gota.new(64,6,1,25,-1,-5) ) + table.insert( actors, gota.new(65,7,1,10,0,-7) ) + table.insert( actors, gota.new(65,8,1,25,0,-7) ) + table.insert( actors, gota.new(66,3,1,10,0,-7) ) + table.insert( actors, gota.new(66,4,1,15,0,-7) ) + table.insert( actors, gota.new(77,2,1,30,-5,-7) ) + table.insert( actors, gota.new(77,9,1,25,-5,-7) ) + + -- FOC? + table.insert(actors,invisible.new(77,5,4)) + table.insert(actors,invisible.new(77,6,4)) + table.insert(actors,invisible.new(58,2,4)) + table.insert(actors,invisible.new(58,3,4)) + + table.insert( actors, caco.new(13,3,2,true ) ) + table.insert( actors, caco.new(17,3,2,false) ) + table.insert( actors, caco.new(20,3,2,false) ) + table.insert( actors, caco.new(26,3,2,false) ) + table.insert( actors, caco.new(37,3,2,false) ) + table.insert( actors, caco.new(41,3,2,false) ) + table.insert( actors, caco.new(50,3,2,false) ) + table.insert( actors, caco.new(57,3,2,false) ) + table.insert( actors, caco.new(61,3,2,false) ) + + table.insert( actors, zombie.new(2, 3, 3,false) ) + table.insert( actors, zombie.new(28, 3, 3,false) ) + table.insert( actors, zombie.new(32, 3, 3,false) ) + table.insert( actors, zombie.new(44, 3, 3,false) ) + table.insert( actors, zombie.new(46, 3, 3,false) ) + table.insert( actors, zombie.new(54, 3, 3,false) ) + table.insert( actors, zombie.new(68, 3, 3,false) ) + table.insert( actors, zombie.new(73, 3, 3,false) ) + + -- 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(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(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(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(14,40,32,triggers.teleport_a)) + -- table.insert(actors,trigger.new(67,8,32,triggers.teleport_b)) + -- table.insert(actors,trigger.new(29,40,32,triggers.teleport_c)) + -- 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 ( 54, 8, 3 ) + abad:move(abad_x, abad_y) + abad_make_safe( true ) + + local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) end function stages.stage2_init() print("stage 2 init") end +function stage1_boss() + load_tilemap( sf_mapa, stage1_boss_mapa ) +end + stage1_mapa={ -- 1 { @@ -841,3 +933,48 @@ stage1_mapa={ }, } + +stage1_boss_mapa = { + map = { + -- 44 + { + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + }, + -- 45 + { + 256,256,256,256,256,256,256,256,256,256, 17,256, + 256,256,256,256,256,256,256,256,256,256, 17,256, + 256,256,256,256,256,256,256,256,256,256, 17,256, + 256,256,256,256,256,256,256,256,256,256, 17,256, + 256,256,256,256,256,256,256,256,256,256, 17,256, + 256,256,256,256,256,256,256,256,256,256, 17,256, + }, + -- 54 + { + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 256,256,256, 17,256,256,256,256,256,256,256,256, + 20, 21, 20, 21, 54, 55, 54, 55, 54, 55, 54, 56, + + }, + -- 55 + { + 256,256,256,256,256,256,256,256,256,256,17,256, + 256,256,256,256,256,256,256,256,256,256,17,256, + 256,256,256,256,256,256,256,256,256,256,17,256, + 256,256,256,256,256,256,256,256,256,256,17,256, + 256,256,256,256,256,256,256,256,256,256,17,256, + 54, 55, 54, 56, 56, 55, 54, 56, 54, 56,55, 54, + + } + }, + r0 = {r=44, x=1, y=1}, + r1 = {r=55, x=12, y=6} +} \ No newline at end of file diff --git a/data/trigger.lua b/data/trigger.lua index 80eff43..3469f7f 100644 --- a/data/trigger.lua +++ b/data/trigger.lua @@ -18,8 +18,8 @@ end function trigger:draw() -- do nothing - -- local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) - -- draw.rect(scr_x,scr_y,self.w,self.h,3) + local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) + draw.rect(scr_x,scr_y,self.w,self.h,3) end function trigger:update() @@ -89,6 +89,7 @@ function triggers:escena_habitacio_batman() end function triggers:escena_lluita_imp() + stage1_boss() start_scene(scenes.lluita_imp) remove_actor(self) end