[WIP] Afegint codi per a múltiples fases

This commit is contained in:
2026-04-04 16:54:44 +02:00
parent d5896466cf
commit d02a9c06a3
7 changed files with 146 additions and 114 deletions

View File

@@ -207,49 +207,37 @@ function render_map( sf_map, sf_tiles, x, y )
view.origin(0,0)
end
function update_game()
if stage~=stage_loaded then
local stage_init = stages["stage"..stage.."_init"]
if stage_init then
stage_init()
stage_loaded = stage
print("Stage "..stage.." loaded")
else
print("No se ha cargado la fase "..stage)
end
function load_stage()
local stage_init = stages["stage"..stage.."_init"]
if stage_init then
stage_init()
stage_loaded = stage
print("Stage "..stage.." loaded")
else
print("No se ha cargado la fase "..stage)
end
end
surf.target(0)
surf.cls(16)
if key.press(key.N1) then
local hab = abad.hab-1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N2) then
local hab = abad.hab+1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N0) then
local abad_x, abad_y = coords.room_to_world ( 41, 3, 3 )
print(abad_x..", "..abad_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
function viewport_update()
local vp_x = viewp.x
local vp_y = viewp.y
local vp_center_offset_x = (viewp.width >> 1)
local vp_center_offset_y = (viewp.height >> 1)
vp_x = abad.x - vp_center_offset_x
if vp_x < 0 then vp_x = 0 end
vp_y = abad.y - vp_center_offset_y
if vp_y < 0 then vp_y = 0 end
viewp:position(vp_x, vp_y)
end
function world_update()
-- Actualitzar moviment del mapa (ex: tiles animats)
arc_mapa_update()
-- Moure a tots
for key,actor in pairs(actors) do
actor:update()
@@ -268,35 +256,24 @@ function update_game()
end
end
-- Actualizar el que queda
cacau.update()
switches.update()
warp.update_all()
end
-- Moure el viewport
local vp_x = viewp.x
local vp_y = viewp.y
--viewp:position(vp_x, vp_y)
local vp_center_offset_x = (viewp.width >> 1)
local vp_center_offset_y = (viewp.height >> 1)
vp_x = abad.x - vp_center_offset_x
if vp_x < 0 then vp_x = 0 end
vp_y = abad.y - vp_center_offset_y
if vp_y < 0 then vp_y = 0 end
viewp:position(vp_x, vp_y)
function world_draw()
-- Pintar la finestra del mon
render_map(sf_mapa, tiles, vp_x, vp_y)
render_map(sf_mapa, tiles, viewp.x, viewp.y)
-- pintar warps
for key,warp in pairs(warp.warp_list) do
if viewp:inside(warp.x, warp.y, warp.w, warp.h) then
warp:draw()
end
end
--pintar actors
for key,actor in pairs(actors) do
if viewp:inside(actor.x, actor.y, actor.w, actor.h) then
actor:draw()
@@ -304,59 +281,28 @@ function update_game()
end
cacau:draw()
end
function update_game()
if stage~=stage_loaded then load_stage() end
surf.target(0)
surf.cls(16)
-- special_keys()
world_update()
-- Moure el viewport
viewport_update()
world_draw()
score.draw()
font.current(font_default)
viewp:print()
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true)
msg_print(0,21,"VIEW= "..vp_x..", "..vp_y, true)
local hab, xx, yy = coords.world_to_tile(abad.x, abad.y)
msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true)
-- msg_print(0,42," JH= "..abad.jump_height,true)
-- view_coord(abad.x+8, abad.y+0, 16, 32, 6)
-- view_coord(abad.x+abad.bb.x, abad.y+abad.bb.h, 2, 2, 4)
-- view_coord(abad.x+abad.bb.x+abad.bb.w, abad.y+abad.bb.h, 2, 2, 2)
-- view_coord(abad.x, abad.y, 2, 2, 3)
-- if key.press(key.T) then
-- view_tile_id = not view_tile_id
-- view_checking_tile = false
-- end
-- if key.press(key.C) then
-- view_checking_tile = not view_checking_tile
-- view_tile_id = false
-- end
--
-- if view_tile_id then
-- write_tile(abad.x, abad.y, 0, true, "R")
-- write_tile(abad.x, abad.y+16, 0, true, "R")
-- write_tile(abad.x, abad.y+32, 0, true, "R")
--
-- write_tile(abad.x+16, abad.y+32, 0, true, "C")
--
-- write_tile(abad.x+32, abad.y, 0, true, "L")
-- write_tile(abad.x+32, abad.y+16, 0, true, "L")
-- write_tile(abad.x+32, abad.y+32, 0, true, "L")
-- end
--
-- if view_checking_tile then
-- local msg = "FLIP= true"
-- if not abad.flip then
-- msg ="FLIP= false"
-- view_coord(abad.x+abad.bb.w+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
-- else
-- view_coord(abad.x+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
-- end
-- msg_print(abad.x, abad.y-8,msg)
-- end
font.current(font_sf)
-- debug_info()
end
function pause()
print("pause()")
-- surf.source(0)
@@ -428,6 +374,83 @@ function update_pause()
end
end
function special_keys()
if key.press(key.N1) then
-- abad prev room
local hab = abad.hab-1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N2) then
-- abad next room
local hab = abad.hab+1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N0) then
-- abad go to room
local abad_x, abad_y = coords.room_to_world ( 70, 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)
end
end
function debug_info()
font.current(font_default)
viewp:print()
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true)
msg_print(0,21,"VIEW= "..viewp.x..", "..viewp.y, true)
local hab, xx, yy = coords.world_to_tile(abad.x, abad.y)
msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true)
-- msg_print(0,42," JH= "..abad.jump_height,true)
-- view_coord(abad.x+8, abad.y+0, 16, 32, 6)
-- view_coord(abad.x+abad.bb.x, abad.y+abad.bb.h, 2, 2, 4)
-- view_coord(abad.x+abad.bb.x+abad.bb.w, abad.y+abad.bb.h, 2, 2, 2)
-- view_coord(abad.x, abad.y, 2, 2, 3)
-- if key.press(key.T) then
-- view_tile_id = not view_tile_id
-- view_checking_tile = false
-- end
-- if key.press(key.C) then
-- view_checking_tile = not view_checking_tile
-- view_tile_id = false
-- end
--
-- if view_tile_id then
-- write_tile(abad.x, abad.y, 0, true, "R")
-- write_tile(abad.x, abad.y+16, 0, true, "R")
-- write_tile(abad.x, abad.y+32, 0, true, "R")
--
-- write_tile(abad.x+16, abad.y+32, 0, true, "C")
--
-- write_tile(abad.x+32, abad.y, 0, true, "L")
-- write_tile(abad.x+32, abad.y+16, 0, true, "L")
-- write_tile(abad.x+32, abad.y+32, 0, true, "L")
-- end
--
-- if view_checking_tile then
-- local msg = "FLIP= true"
-- if not abad.flip then
-- msg ="FLIP= false"
-- view_coord(abad.x+abad.bb.w+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
-- else
-- view_coord(abad.x+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
-- end
-- msg_print(abad.x, abad.y-8,msg)
-- end
font.current(font_sf)
end
flow:registrar("game", {game_init, update_game} )