[WIP] Reestructurant codi

[WIP] Stage 2 ja 'arranca'
This commit is contained in:
2026-05-30 22:20:24 +02:00
parent 714ed083d4
commit ef87fd3c25
9 changed files with 214 additions and 203 deletions
+23 -126
View File
@@ -64,6 +64,19 @@ require "sign"
font_default = font.current()
local tile_w = arcade_config.tiles_width
local tile_h = arcade_config.tiles_height
local res_w = arcade_config.resolucion.width
local res_h = arcade_config.resolucion.height
local view_tile_id = false
local view_checking_tile = false
viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height)
viewp:position(0,0)
-- actors={}
function game_load()
surf.target(0)
surf.cls(16)
@@ -88,6 +101,11 @@ function game_init(menu)
states:next()
end
function game_exit()
-- mapa_restore_backup()
actors={}
-- cameras={}
end
--
-- Carregar fonts general del joc
--
@@ -105,120 +123,16 @@ function images_init()
warp.init(tiles)
end
function image_close()
surf.free(tiles)
warp.close()
end
-- function image_close()
-- surf.free(tiles)
-- warp.close()
-- end
function mapa_surface_init()
if (sf_mapa) then surf.free(sf_mapa) end
sf_mapa=surf.new(mapa_room_cols*mapa_rooms_per_piso,mapa_room_rows*mapa_pisos)
end
function audio_init()
-- Càrrega dels audios
audio_text_abad = sound.load(audio_text_abad)
audio_text_premiere = sound.load(audio_text_premiere)
audio_text_elalien = sound.load(audio_text_elalien)
audio_text_batman = sound.load(audio_text_batman)
audio_text_imp = sound.load(audio_text_imp)
audio_abad_jump = sound.load(audio_abad_jump)
audio_abad_fall = sound.load(audio_abad_fall)
audio_abad_hit = sound.load(audio_abad_hit)
audio_abad_shot = sound.load(audio_abad_shot)
audio_abad_step[1] = sound.load(audio_abad_step[1])
audio_abad_step[2] = sound.load(audio_abad_step[2])
audio_abad_step[3] = sound.load(audio_abad_step[3])
audio_abad_step[4] = audio_abad_step[2]
audio_switch = sound.load(audio_switch)
audio_hit = sound.load(audio_hit)
audio_low = sound.load(audio_low)
end
local tile_w = arcade_config.tiles_width
local tile_h = arcade_config.tiles_height
local res_w = arcade_config.resolucion.width
local res_h = arcade_config.resolucion.height
local view_tile_id = false
local view_checking_tile = false
viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height)
viewp:position(0,0)
function foo()
print("foo")
end
function actor_warp_draw(actor)
local shrink_w = actor.w*actor.shrink
local shrink_h = actor.h*actor.shrink
local offset_x = math.floor((actor.w-shrink_w)/2)
local offset_y = math.floor((actor.h-shrink_h)/2)
local scr_x, scr_y = viewp:screen_coords( actor.x+offset_x, actor.y+offset_y )
shrink_w = math.floor(shrink_w)
shrink_h = math.floor(shrink_h)
if shrink_w>0 and shrink_h>0 then
draw.surfrot((actor.frame&7)*cw, (actor.frame>>cxr2)*ch,
cw, ch,
scr_x, scr_y,
actor.angle,
shrink_w, shrink_h,
actor.flip)
end
end
function actor_warp_update(actor)
-- warp, wait, respawn
if actor.warping then
if actor.step<actor.death_time then
actor.shrink=actor.shrink-actor.d_shrink
actor.angle=actor.angle+actor.d_angle
if actor.angle>=360 then actor.angle = actor.angle % 360 end
if actor.shrink<=0 then
actor.shrink=1
actor.d_shrink=1
actor.angle=0
actor.d_angle=1
actor.warping = false
actor.frame = -1
actor.step = 0
if actor.energy~=nil then
actor.energy = actor.max_energy
end
end
end
elseif actor.step<actor.death_time/2 then
actor.frame = -1
elseif actor.step<actor.death_time then
if actor.step%2==0 then
actor.frame=actor.anim[#actor.anim]
else
actor.frame=-1
end
elseif actor.step>=actor.death_time then
actor.frame=actor.anim[1]
actor.step=0
actor.wait=0
if actor.name=="caco" then
actor.update=caco.update_normal
elseif actor.name=="zombie" then
actor.update=zombie.update_normal
end
actor.dying = false
end
end
actors={}
function game_exit()
-- mapa_restore_backup()
actors={}
-- cameras={}
end
function render_map( sf_map, sf_tiles, x, y, target )
target = target or 0
map.surf(sf_map)
@@ -230,23 +144,6 @@ function render_map( sf_map, sf_tiles, x, y, target )
view.origin(0,0)
end
function viewport_update()
-- Moure el viewport
local vp_x = viewp.x
local vp_y = viewp.y
local vp_center_offset_x = (viewp.width // 2)
local vp_center_offset_y = (viewp.height // 2)
vp_x = abad.x+(abad.w/2) - 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()
@@ -327,7 +224,7 @@ function update_game()
world_update()
viewport_update()
stages.stage_viewport_update()
world_draw()