[WIP] Reestructurant codi abans de posar-me en el nivell 2

[NEW] Afegit music_player
[NEW] Música de fons des de l'inici
This commit is contained in:
2026-05-29 23:28:51 +02:00
parent 2eb4bc82eb
commit e0825e5bbb
20 changed files with 437 additions and 304 deletions
+2 -1
View File
@@ -169,7 +169,8 @@ function abad_hurt(howmuch)
-- dead.start()
-- music.play(audio_game_over,0)
else
music.play(audio_life_lost,0)
-- music.play(audio_life_lost,0)
music_player:play(audio_life_lost,0,true)
abad.energia=abad.max_energia
-- abad.hab=abad.safe.hab
-- abad.x=abad.safe.x
+105 -13
View File
@@ -1,3 +1,32 @@
require "controller"
require "audio"
arcade_config = require("arcade_config")
require "states"
require "requirements"
require "logo"
require "intro"
require "title"
require "opcions"
require "opcions_input"
require "pause"
require "game_over"
require "scenes"
coords = require "coords"
require "helpers"
require "music_player"
-- require "map"
require "mapa"
require "warp"
require "fade"
require "point"
require "fps"
--require "menu"
viewport= require("viewport")
require "stage_mgr"
require "abad"
@@ -33,6 +62,80 @@ require "batvio"
require "copter"
require "sign"
font_default = font.current()
function game_load()
surf.target(0)
surf.cls(16)
math.randomseed(os.time())
mapa_surface_init()
states:executar("check-reqs")
controller:init()
fonts_init()
images_init()
fade.init()
audio_init()
logo_config(font_sf)
end
function game_init(menu)
actors={}
abad_init()
table.insert(actors,abad)
score.create()
stages.load_stage(true)
states:next()
end
--
-- Carregar fonts general del joc
--
function fonts_init()
font_sf=font.load("X2_font.fnt")
end
function images_init()
tiles=surf.load("tiles.gif")
surf.source(tiles)
local paleta=pal.load("tiles.gif")
pal.set(paleta)
tiles2=surf.load("tiles2.gif")
-- Crear el warp
warp.init(tiles)
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
@@ -116,19 +219,6 @@ function game_exit()
-- cameras={}
end
function game_init(menu)
-- print("GAME INIT")
actors={}
abad_init()
table.insert(actors,abad)
score.create()
stages.load_stage(true)
states:next()
end
function render_map( sf_map, sf_tiles, x, y, target )
target = target or 0
map.surf(sf_map)
@@ -232,6 +322,8 @@ end
function update_game()
surf.target(0)
surf.cls(16)
music_player:update()
world_update()
+2 -1
View File
@@ -9,7 +9,8 @@ function game_over_init()
dead.vel[i]=(200+math.random(0,399))/400
end
-- game_update=dead.update
music.play(audio_game_over,0)
-- music.play(audio_game_over,0)
music_player:play(audio_game_over,0)
states:next()
end
+82 -51
View File
@@ -1,73 +1,75 @@
local abad={x=0,y=0,w=32,h=32,dx=88,dy=48,dw=32,dh=32}
local batman={x=0,y=96,w=32,h=32,dx=164,dy=48,dw=32,dh=32}
local cacaus={x=224,y=176,w=32,h=16,dx=152,dy=64,dw=32,dh=16}
local cacaus_trans={x=192,y=176,w=16,h=8,dx=65,dy=56,dw=16,dh=8}
local marc={x=30,y=6,w=198,h=102,color=2}
local pas_porta={x=146,y=48,w=14,h=32,color=16}
local abad ={ x=0, y= 0, w=32, h=32, dx= 88, dy=48, dw=32, dh=32 }
local batman={ x=0, y= 96, w=32, h=32, dx=164, dy=48, dw=32, dh=32 }
local cacaus={ x=224, y=176, w=32, h=16, dx=152, dy=64, dw=32, dh=16 }
local cacaus_trans={ x=192, y=176, w=16, h=8, dx=65, dy=56, dw=16, dh=8 }
local marc={ x=30, y=6, w=198, h=102, color=2 }
local pas_porta={ x=146, y=48, w=14, h=32, color=16 }
local scene_x_offset = 32
local scene_y_offset = 8
intro_wait=40
intro_step=0
local tiles_file = "tiles.gif"
local next_state = "title"
function draw_escenari ()
surf.cls(16)
draw_item_intro("marc",false)
view.origin(scene_x_offset, scene_y_offset)
mapa_draw(10)
-- Borrar la porta del mapa
draw_item_intro("pas porta")
end
local intro_wait=40
local intro_step=0
function draw_item_intro( name, flip, mood )
if ( name == "abad" ) then
-- abad.mood = mood or "normal"
draw.surf(abad.x, abad.y, abad.w, abad.h, abad.dx, abad.dy, abad.dw, abad.dh, flip)
abad_add_mood(abad.dx,0,abad.dy,0,flip,mood)
elseif (name == "batman" ) then
draw.surf(batman.x, batman.y, batman.w, batman.h, batman.dx, batman.dy, batman.dw, batman.dh, flip)
elseif (name == "cacaus" ) then
draw.surf(cacaus.x, cacaus.y, cacaus.w, cacaus.h, cacaus.dx, cacaus.dy, cacaus.dw, cacaus.dh, flip)
elseif (name == "cacaus trans" ) then
draw.surf(cacaus_trans.x, cacaus_trans.y, cacaus_trans.w, cacaus_trans.h, cacaus_trans.dx, cacaus_trans.dy, cacaus_trans.dw, cacaus_trans.dh, flip)
elseif (name == "marc" ) then
draw.rect(marc.x, marc.y, marc.w, marc.h, marc.color)
elseif (name == "pas porta" ) then
draw.rectf(pas_porta.x, pas_porta.y, pas_porta.w, pas_porta.h, pas_porta.color)
end
end
local intro_mapa_room_cols = 12; -- en quantitat de tiles
local intro_mapa_room_rows = 6; -- en quantitat de tiles
local intro_mapa_rooms_per_piso = 1
local intro_mapa_pisos = 1
local intro_mapa_empty_tile = 256
local intro_mapa={
-- 1
{
256, 66, 26, 27, 28, 29, 28, 29, 26, 27, 28, 29,
256,256,256, 24,256,256,256,256,256, 25,256,256,
64, 68,256,256,256,256,256,256,256, 25,256,256,
256,256, 66, 24,256,121,256,256,256, 38,256,256,
256, 66,256, 24,101,102,103,256,256, 38,256,256,
66,256,256, 24, 28, 29, 28, 29, 28, 29, 28, 29,
},
}
function intro_init()
print("INTRO_INIT")
-- game_update = intro_intro
mapa = stage1_mapa
-- print("INTRO_INIT")
mapa = intro_mapa
mapa_room_cols = intro_mapa_room_cols
mapa_room_rows = intro_mapa_room_rows
mapa_rooms_per_piso = intro_mapa_rooms_per_piso
mapa_pisos = intro_mapa_pisos
mapa_empty_tile = intro_mapa_empty_tile
mapa_surface_init()
load_tilemap( sf_mapa )
tiles=surf.load(tiles_file)
surf.source(tiles)
local paleta=pal.load(tiles_file)
pal.set(paleta)
intro_wait=400
surf.source(tiles)
surf.target(0)
surf.cls(16)
fade.fadein()
font.current(font_sf)
-- flow:add_path({intro_intro, intro_update})
states:next()
end
function intro_intro()
-- print("INTRO_INTRO")
intro_wait=1
-- game_update = intro_update
states:next()
fade.fadeoutin()
end
function intro_update()
-- print("INTRO_UPDATE")
if key.press(key.ESCAPE) or pad.press(btnPause) then
-- game_init(true)
print("INTRO_UPDATE")
-- game_update = menu_init
-- game_init(true)
intro_end()
states:next()
elseif key.press(key.SPACE) then
intro_wait=1
end
@@ -124,21 +126,50 @@ function intro_update()
elseif intro_step==7 then
start_scene(scenes.intro_04,58)
intro_step=intro_step+1
-- STEP 8
elseif intro_step==8 then
-- game_init(true)
-- game_update = menu_init
intro_end()
states:next()
end
intro_wait=50
end
end
function intro_end()
print("intro_end")
-- print("INTRO_END")
fade.fadeoutin()
states:executar("title")
states:executar(next_state)
end
states:registrar("intro", {intro_init, intro_intro, intro_update})
function draw_escenari ()
surf.cls(16)
draw_item_intro("marc",false)
view.origin(scene_x_offset, scene_y_offset)
mapa_draw(0)
-- Borrar la porta del mapa
draw_item_intro("pas porta")
end
function draw_item_intro( name, flip, mood )
if ( name == "abad" ) then
draw.surf(abad.x, abad.y, abad.w, abad.h, abad.dx, abad.dy, abad.dw, abad.dh, flip)
abad_add_mood(abad.dx,0,abad.dy,0,flip,mood)
elseif (name == "batman" ) then
draw.surf(batman.x, batman.y, batman.w, batman.h, batman.dx, batman.dy, batman.dw, batman.dh, flip)
elseif (name == "cacaus" ) then
draw.surf(cacaus.x, cacaus.y, cacaus.w, cacaus.h, cacaus.dx, cacaus.dy, cacaus.dw, cacaus.dh, flip)
elseif (name == "cacaus trans" ) then
draw.surf(cacaus_trans.x, cacaus_trans.y, cacaus_trans.w, cacaus_trans.h, cacaus_trans.dx, cacaus_trans.dy, cacaus_trans.dw, cacaus_trans.dh, flip)
elseif (name == "marc" ) then
draw.rect(marc.x, marc.y, marc.w, marc.h, marc.color)
elseif (name == "pas porta" ) then
draw.rectf(pas_porta.x, pas_porta.y, pas_porta.w, pas_porta.h, pas_porta.color)
end
end
states:registrar("intro", {intro_init, intro_intro, intro_update, intro_end})
+4 -94
View File
@@ -1,99 +1,7 @@
arcade_config = require("arcade_config")
coords = require "coords"
require "helpers"
require "controller"
require "states"
-- require "map"
require "mapa"
require "warp"
require "fade"
require "audio"
require "requirements"
require "logo"
require "intro"
require "scenes"
require "title"
require "game"
require "opcions"
require "opcions_input"
require "pause"
require "game_over"
require "point"
require "fps"
--require "menu"
coords.set_config({
tiles_width = arcade_config.tiles_width,
tiles_height = arcade_config.tiles_height,
room_cols = mapa_room_cols,
room_rows = mapa_room_rows,
rooms_per_floor = mapa_rooms_per_piso,
})
font_default = font.current()
function images_init()
tiles=surf.load("tiles.gif")
surf.source(tiles)
local paleta=pal.load("tiles.gif")
pal.set(paleta)
tiles2=surf.load("tiles2.gif")
-- Crear el warp
warp.init(tiles)
end
function image_close()
surf.free(tiles)
warp.close()
end
function fonts_init()
font_sf=font.load("X2_font.fnt")
end
function mapa_init()
sf_mapa=surf.new(mapa_room_cols*mapa_rooms_per_piso,mapa_room_rows*mapa_pisos)
-- load_tilemap( sf_mapa )
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
function mini.init()
-- back_sf=surf.new(256,192)
math.randomseed(os.time())
fonts_init()
images_init()
mapa_init()
fade.init()
audio_init()
controller:init()
logo_config(font_sf)
surf.target(0)
surf.cls(16)
states:executar("check-reqs")
game_load()
end
function mini.update()
@@ -107,7 +15,9 @@ function mini.update()
win.cursor(fs)
end
if (game_update) then game_update() end
if (game_update) then
game_update()
end
-- Pausa per a que vaja be en mini 1.5.1
-- local t0 = os.clock()
+11 -4
View File
@@ -5,6 +5,12 @@ mapa={}
mapa.wait=0
mapa.step=0
mapa_room_cols = 0
mapa_room_rows = 0
mapa_rooms_per_piso = 0
mapa_pisos = 0
mapa_empty_tile = 0
half_block_set={
[20] = true, [21] = true,
[22] = true, [28] = true,
@@ -97,11 +103,12 @@ function arc_mapa_update()
end
end
function mapa_draw(hab)
for ty=0,5 do
for tx=0,11 do
local tile=mapa[1+hab][1+tx+ty*12]
if tile~=256 and (tile<126 or mapa.step>4) then
for ty=0,mapa_room_rows-1 do
for tx=0,mapa_room_cols-1 do
local tile=mapa[1+hab][1+tx+ty*mapa_room_cols]
if tile~=mapa_empty_tile and (tile<126 or mapa.step>4) then
-- draw.surf((tile&15)*8,64+(tile>>4)*8,8,8,tx*8,ty*8)
local txr = arcade_config.tiles_per_row-1
local txr2 = arcade_config.tiles_per_row_base2
+80
View File
@@ -0,0 +1,80 @@
music_info = {
mus_life_ogg = 1.6
}
music_player = {
playlist = {song="", pos=0},
song = "",
playing = false,
pos = 0,
old_pos = 0,
check_time = 0,
}
function music_player:play(song, loop, enqueue)
-- print("MUSIC_PLAYER:PLAY "..song)
if enqueue then
self.playlist.song = self.song
self.playlist.pos = music.pos()
end
-- print( os.clock())
if loop~=nil then
music.play(song, loop)
else
music.play(song)
end
-- print( os.clock())
self.song = song
-- self.old_pos = music.pos()
self.playing = true
self.check_time = os.clock()
end
function music_player:pause()
music.pause()
end
function music_player:resume()
music.resume()
end
function music_player:stop()
music.stop()
end
function music_player:pos()
music.pos()
end
function music_player:enabled()
music.enabled()
end
function music_player:update()
-- self.pos = music.pos()
local curr_time = os.clock()
local song_name = self.song:gsub("%.", "_")
if music_info[song_name]~=nil and curr_time-self.check_time>music_info[song_name] then
-- print("MUSIC_PLAYER:UPDATE "..self.pos.." / "..self.old_pos.." / "..music.pos())
-- if self.pos==self.old_pos then self.playing = false end
self.playing = false
self.old_pos = self.pos
self.check_time = curr_time
end
if not self.playing and self.playlist.song~="" then
self.song = self.playlist.song
self.pos = self.playlist.pos
-- print( os.clock())
music.play(self.song)
-- print( os.clock())
-- music.pos(self.pos)
self.playlist.song = ""
self.playlist.pos = 0
end
end
+2 -1
View File
@@ -21,7 +21,8 @@ function opcions_update()
if key.press(keyShoot) or key.press(key.SPACE) or pad.press(pad.A) or pad.press(btnShoot) or key.press(key.RETURN) then
if menu_sel==0 then
music.enabled(not music.enabled())
if music.enabled() then music.play(audio_main_song) end
-- if music.enabled() then music.play(audio_main_song) end
if music.enabled() then music_player:play(audio_main_song) end
elseif menu_sel==1 then
sound.enabled(not sound.enabled())
elseif menu_sel==2 then
+8 -3
View File
@@ -1,21 +1,25 @@
remote_view_wait = 0
remote_view_hab = ""
remote_sf_w = mapa_room_cols*arcade_config.tiles_width
remote_sf_h = mapa_room_rows*arcade_config.tiles_height
remote_sf_w = 0
remote_sf_h = 0
function remote_view_init ()
remote_sf_w = mapa_room_cols*arcade_config.tiles_width
remote_sf_h = mapa_room_rows*arcade_config.tiles_height
sf_remote=surf.new(remote_sf_w, remote_sf_h)
end
function remote_view(hab)
-- print("REMOTE_VIEW "..hab)
remote_view_hab = hab
remote_view_wait = 200
end
function remote_view_draw()
if remote_view_wait>0 then
-- print("REMOTE_VIEW_DRAW "..remote_view_hab)
local x,y = coords.room_to_coord ( remote_view_hab )
-- print("X,Y= "..x.." , "..y)
local curr_source = surf.source()
local curr_target = surf.target()
@@ -30,6 +34,7 @@ function remote_view_draw()
surf.source(sf_remote)
draw.surf(0,0,remote_sf_w,remote_sf_h,11,11,(remote_sf_w/2)-2,(remote_sf_h/2)-2)
draw.rect(10,10,(remote_sf_w/2),(remote_sf_h/2),2)
-- print("RSW,RSH= "..remote_sf_w.." , "..remote_sf_h)
surf.source(curr_source)
remote_view_wait = remote_view_wait-1
end
+17 -14
View File
@@ -1,6 +1,7 @@
local mini_version = ""
local versio_req = {1,5,0}
local parts = {}
local printed = false
function reqs_init()
local version=sys.version()
@@ -16,32 +17,34 @@ end
function reqs_draw()
-- print("LOGO DRAW "..logo_step)
-- Seleccionar font i destí
-- surf.source(logo_sf)
surf.target(0)
-- Netejar destí
surf.cls(16)
draw.text("Es requerix mini "..table.concat(versio_req, "."),20,20,2)
draw.text("Executant amb mini "..table.concat(parts, "."),20,30,2)
local str1 = "Es requerix mini "..table.concat(versio_req, ".")
local str2 = "Executant amb mini "..table.concat(parts, ".")
draw.text(str1,20,20,2)
draw.text(str2,20,30,2)
if not printed then
print(str1)
print(str2)
printed = true
end
end
function reqs_end()
-- print("LOGO_END")
-- game_update = intro_init
states:executar("logo")
-- surf.free(logo_sf)
end
function reqs_update()
if parts[1]>versio_req[1] then
states:next()
elseif parts[2]>versio_req[2] then
states:next()
elseif parts[3]>=versio_req[3] then
states:next()
else
if parts[1]<versio_req[1] then
reqs_draw()
elseif parts[2]<versio_req[2] then
reqs_draw()
elseif parts[3]<versio_req[3] then
reqs_draw()
else
states:next()
end
if controller:check("ESC") or controller:check("shoot") then
+19 -23
View File
@@ -191,12 +191,12 @@ scenes={
}
function start_scene(_scene, offset, stop_music)
--bkg=newsurf(128,96)
--setdest(bkg)
--setsource(0)
--draw.surf(0,0,128,96,0,0)
--setsource(tiles)
--setdest(0)
if stop_music then
print("STOP MUSIC")
elseif _scene[1].musica then
print("PLAY ".._scene[1].musica)
end
scenes.current_scene=_scene
scenes.dnum=1
scenes.step=0
@@ -205,15 +205,15 @@ function start_scene(_scene, offset, stop_music)
scenes.offset=28
scenes.die=scenes.current_scene[scenes.dnum].die or 0
if _scene[1].musica then
--print(scene[1].musica)
music.play(scenes.current_scene[scenes.dnum].musica)
-- print(scene[1].musica)
-- music.play(scenes.current_scene[scenes.dnum].musica)
music_player:play(scenes.current_scene[scenes.dnum].musica)
end
if offset then scenes.offset=offset end
-- old_update=game_update
-- game_update=update_scene
scene.running = true
if not stop_music then scene.stop_music = false end
-- print("SCENE START")
print("SCENE START")
states:executar("scene", true); -- guardar l'estat anterior i executar
end
@@ -242,29 +242,24 @@ end
function play_music()
if scenes.current_scene[scenes.dnum].musica then
-- print("PLAY MUSIC "..scenes.dnum)
music.stop()
music.play(scenes.current_scene[scenes.dnum].musica)
-- music.stop()
-- music.play(scenes.current_scene[scenes.dnum].musica)
music_player:stop()
music_player:play(scenes.current_scene[scenes.dnum].musica)
end
end
function draw_abad_with_mood(mood, dx, dy, dw, dh)
local ox, oy =view.origin()
view.origin(0,0)
-- -- composicio
-- composicio
local curr_sf = surf.target()
surf.target(avatar_sf)
surf.cls(16)
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,0,0,avatar_w,avatar_h)
abad_add_mood(0,scenes.current_scene[scenes.dnum].x,0,scenes.current_scene[scenes.dnum].y,false,mood)
-- if mood=="sorpresa" then
-- draw.surf(240,0,11,4,16-scenes.current_scene[scenes.dnum].x,5-scenes.current_scene[scenes.dnum].y,11,4)
-- elseif mood=="enfadat" then
-- draw.surf(240,4,11,4,16-scenes.current_scene[scenes.dnum].x,5-scenes.current_scene[scenes.dnum].y,11,4)
-- elseif mood=="interessant" then
-- draw.surf(240,8,11,4,16-scenes.current_scene[scenes.dnum].x,5-scenes.current_scene[scenes.dnum].y,11,4)
-- else
-- abad.mood="normal"
-- end
-- Dibuixar
view.origin(ox, oy)
surf.target(curr_sf)
@@ -392,6 +387,7 @@ function update_scene()
if scenes.die==0 then
if scenes.dnum==#scenes.current_scene then
if scene.stop_music then music.stop() end
-- if batman.endgame then
-- final_init()
-- fade.fadeoutin()
+62 -47
View File
@@ -1,14 +1,40 @@
function stages.stage1_init()
-- stagemgr init
stages.actors={}
stages.boss_loaded = false
stages.boss_ready = false
stages.boss_finished = false
boss = nil
-- actors={}
-- mapa init
mapa = stage1_mapa
print("mapa loaded")
mapa_room_cols = s01_mapa_room_cols
mapa_room_rows = s01_mapa_room_rows
mapa_rooms_per_piso = s01_mapa_rooms_per_piso
mapa_pisos = s01_mapa_pisos
mapa_empty_tile = s01_mapa_empty_tile
tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5}
mapa.wait=0
mapa.step=0
mapa.tobatcave = false
mapa_surface_init()
load_tilemap( sf_mapa )
mapa.tobatcave = false
coords.set_config({
tiles_width = arcade_config.tiles_width,
tiles_height = arcade_config.tiles_height,
room_cols = mapa_room_cols,
room_rows = mapa_room_rows,
rooms_per_floor = mapa_rooms_per_piso,
})
remote_view_init()
-- actors init
llibre.init()
table.insert(actors,llibre)
@@ -31,8 +57,6 @@ function stages.stage1_init()
table.insert( actors, boss )
boss_meter = bar_meter.new(20,12,128,10,1,1,boss,5)
--batman
bol.init()
table.insert(actors,bol)
@@ -104,10 +128,10 @@ function stages.stage1_init()
local hp_x, hp_y = coords.room_to_world(69, 9, 3)
table.insert( actors, health_potion.new(77, hp_x, hp_y, 0, 0, 1) )
-- 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","TR01") )
table.insert( actors, trigger.new(10,8,3,triggers.start_bg_music,"musica") )
table.insert( actors, trigger.new(11,2,3,triggers.escena_abad_corfes,"corfes","TR02") )
table.insert( actors, trigger.new(31,1,3,triggers.escena_abad_portes,"portes","TR03") )
@@ -129,18 +153,11 @@ function stages.stage1_init()
table.insert( actors, trigger.new(75,6,1,triggers.open_door,"","pasillo inf","switch",{77, 50,38,26}) )
table.insert( actors, trigger.new(75,9,1,triggers.open_door,"","acces inf casa batman","switch",{57, 53,41},{"TR07"}) )
table.insert( actors, trigger.new(79,5,1,triggers.open_door,"","sotan casa batman","switch",{36, 56,44}) )
-- table.insert( actors, trigger.new(38,2,2,triggers.open_door,"","","switch",{39, 62,63}) )
table.insert( actors, trigger.new(38,2,2,triggers.add_1up,"","","switch",{39, 62,63}) )
table.insert( actors, trigger.new(35,1,3,triggers.open_door,"","batman a casa abad (1/2)","invisible",{36, 12,24 }) )
table.insert( actors, trigger.new(35,1,3,triggers.open_door,"","batman a casa abad (2/2)","invisible",{35, 23,35 }) )
-- table.insert( actors, trigger.new(1, 1,1,triggers.open_door,"","acces cacaus","switch",{20, 53,41},{"TR08"}))
-- 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))
-- Dialegs
trigger_event.new("Premiere dialeg 1",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
@@ -185,49 +202,17 @@ function stages.stage1_init()
tiles_layer2.new(76,3,2,128,208,16,16, tiles_layer2.update_aranya, tiles_layer2.draw_aranya)
tiles_layer2.new(78,6,2,128,208,16,16, tiles_layer2.update_aranya, tiles_layer2.draw_aranya)
-- table.insert( actors, sign.new(10, 6 , 3, 0, false) ) -- L
-- abad init
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
-- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
-- table.insert( actors, trigger.new(8,4,3,triggers.escena_stage1_ending,"stage1 ending","TR09") )
-- local abad_x, abad_y = coords.room_to_world ( 8, 9, 3 )
-- local abad_x, abad_y = coords.room_to_world ( 8, 9, 3 )
abad:move(abad_x, abad_y)
abad_make_safe( true )
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
remote_view_init()
viewp:free_move()
end
function stages.stage1_toBatcave()
local switches_enabled = 0
if mapa.tobatcave then return end
for key,actor in pairs(actors) do
if actor.type=="switch" and actor.enabled then
switches_enabled = switches_enabled +1
end
end
if switches_enabled<=2 then
mapa.tobatcave = true
table.insert( stages.actors, sign.new(76, 8 , 1, 0, true) ) -- L
table.insert( stages.actors, sign.new(73, 10, 3, 0, true) ) -- L
table.insert( stages.actors, sign.new(72, 5 , 1, 0, true) ) -- L
-- table.insert( stages.actors, sign.new(61, 6 , 1, 0, true) ) -- L
-- table.insert( stages.actors, sign.new(50, 9 , 1, 0, true) ) -- L
table.insert( stages.actors, sign.new(41, 5, 3, 0, false) ) -- R
-- table.insert( actors, sign.new(40, 10, 3, 0, false) ) -- R
-- table.insert( actors, sign.new(42, 1 , 2, 90, false) ) -- D
table.insert( stages.actors, sign.new(53, 4 , 3, 0, false) ) -- R
-- print("GO TO BATCAVE")
end
end
function stages.stage1_update()
stages.stage1_toBatcave()
for key,actor in pairs(stages.actors) do
@@ -256,6 +241,36 @@ function stages.stage1_draw_front()
-- boss_meter:draw()
end
function stages.stage1_bg_music()
music_player:play(audio_song_premiere)
end
function stages.stage1_toBatcave()
local switches_enabled = 0
if mapa.tobatcave then return end
for key,actor in pairs(actors) do
if actor.type=="switch" and actor.enabled then
switches_enabled = switches_enabled +1
end
end
if switches_enabled<=2 then
mapa.tobatcave = true
table.insert( stages.actors, sign.new(76, 8 , 1, 0, true) ) -- L
table.insert( stages.actors, sign.new(73, 10, 3, 0, true) ) -- L
table.insert( stages.actors, sign.new(72, 5 , 1, 0, true) ) -- L
-- table.insert( stages.actors, sign.new(61, 6 , 1, 0, true) ) -- L
-- table.insert( stages.actors, sign.new(50, 9 , 1, 0, true) ) -- L
table.insert( stages.actors, sign.new(41, 5, 3, 0, false) ) -- R
-- table.insert( actors, sign.new(40, 10, 3, 0, false) ) -- R
-- table.insert( actors, sign.new(42, 1 , 2, 90, false) ) -- D
table.insert( stages.actors, sign.new(53, 4 , 3, 0, false) ) -- R
-- print("GO TO BATCAVE")
end
end
require "stage1_world_map"
require "stage1_boss_map"
require "stage1_boss"
+2 -1
View File
@@ -48,7 +48,8 @@ function stage1_ending:update_scene()
-- copter.init()
copter.y=copter.y-16
table.insert( actors, copter)
music.play(audio_song_copter)
-- music.play(audio_song_copter)
music_player:play(audio_song_copter)
elseif self.time<720 then
-- sisena escena - premiere copter
premiere.update()
+5 -5
View File
@@ -1,8 +1,8 @@
mapa_room_cols = 12; -- en quantitat de tiles
mapa_room_rows = 6; -- en quantitat de tiles
mapa_rooms_per_piso = 10
mapa_pisos = 8
mapa_empty_tile = 256
s01_mapa_room_cols = 12; -- en quantitat de tiles
s01_mapa_room_rows = 6; -- en quantitat de tiles
s01_mapa_rooms_per_piso = 10
s01_mapa_pisos = 8
s01_mapa_empty_tile = 256
stage1_mapa={
-- 1
+13 -14
View File
@@ -1,40 +1,39 @@
stages = {}
-- stages = {}
stages.actors={}
stages.boss_loaded = false
stages.boss_ready = false
stages.boss_finished = false
boss = nil
-- stages.actors={}
function stages.stage2_init()
-- stagemgr init
stages.actors={}
stages.boss_loaded = false
stages.boss_ready = false
stages.boss_finished = false
boss = nil
actors={}
-- mapa init
mapa = stage2_mapa
tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5}
mapa.wait=0
mapa.step=0
surf.free(sf_mapa)
sf_mapa=surf.new(s2_mapa_room_cols*s2_mapa_rooms_per_piso,s2_mapa_room_rows*s2_mapa_pisos)
load_tilemap( sf_mapa )
-- actors init
batvio.init()
table.insert(actors,batvio)
local abad_x, abad_y = coords.room_to_world ( 1, 4, 3 )
-- abad init
local abad_x, abad_y = coords.room_to_world ( 1, 4, 3 )
abad:move(abad_x, abad_y)
abad_make_safe( true )
-- viewport init
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
remote_view_init()
viewp:free_move()
stages.boss_ready = false
stages.boss_loaded = false
-- remote_view_init()
end
function stages.stage2_update()
+2 -1
View File
@@ -48,7 +48,8 @@ function stage2_ending:update_scene()
-- copter.init()
copter.y=copter.y-16
table.insert( actors, copter)
music.play(audio_song_copter)
-- music.play(audio_song_copter)
music_player:play(audio_song_copter)
elseif self.time<720 then
-- sisena escena - premiere copter
premiere.update()
+3
View File
@@ -15,14 +15,17 @@ stages.stage_update = nil
stages.stage_draw_back = nil
stages.stage_draw_middle = nil
stages.stage_draw_front = nil
stages.stage_bg_music = nil
function stages.load_stage( init )
print("Loading stage "..stages.stage)
init = init or false
stages.stage_init = stages["stage"..stages.stage.."_init"]
stages.stage_update = stages["stage"..stages.stage.."_update"]
stages.stage_draw_back = stages["stage"..stages.stage.."_draw_back"]
stages.stage_draw_middle = stages["stage"..stages.stage.."_draw_middle"]
stages.stage_draw_front = stages["stage"..stages.stage.."_draw_front"]
stages.stage_bg_music = stages["stage"..stages.stage.."_bg_music"]
stages.stage_loaded = stages.stage
stages.boss_ready = false
stages.boss_loaded = false
+11 -30
View File
@@ -1,25 +1,3 @@
-- flow={
-- level=1,
-- step={0},
-- actiu="",
-- pila={},
-- paths={ {flow_safe} },
-- registre={}
-- -- sub_path_enable = false,
-- -- sub_step = 0,
-- -- sub_path={}
-- }
-- function flow:print()
-- print("> STEP= "..self.step.." / "..#self.path)
-- if self.sub_path_enable then
-- print("> SUB_PATH_ENABLE= TRUE")
-- else
-- print("> SUB_PATH_ENABLE= FALSE")
-- end
-- print("> SUB_STEP= "..self.sub_step.." / "..#self.sub_path)
-- print("")
-- end
states={
registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
@@ -40,7 +18,8 @@ end
function states:registrar(nom, _path)
print("[STATES] REGISTRAR => "..nom)
self.registre[nom]= {ptr=0, path=_path}
print(self.registre[nom].ptr)
-- print(" nom.ptr -> "..self.registre[nom].ptr)
-- print(" nom.path -> "..#self.registre[nom].path)
end
function states:borrar(nom)
@@ -68,22 +47,24 @@ function states:executar(nom, stacking)
end
self.actiu=nom
self.registre[self.actiu].ptr=0
-- Executar el primer pas
self:next()
end
function states:next()
print("[STATES] NEXT "..self.actiu);
local ptr = self.registre[self.actiu].ptr
local steps = #self.registre[self.actiu].path
-- print("STATES_NEXT= "..self.actiu..", "..ptr..", "..steps)
-- print("[STATES] NEXT "..self.actiu);
local estat = self.registre[self.actiu]
local ptr = estat.ptr
local steps = #estat.path
if ptr+1>steps then
self:finish()
else
self.registre[self.actiu].ptr = ptr+1
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
estat.ptr = ptr+1
-- print("[STATES] NEXT "..self.actiu.." ("..estat.ptr.." / "..steps..")")
game_update = estat.path[estat.ptr]
end
return self.actiu, self.registre[self.actiu].ptr
return self.actiu, estat.ptr
end
function states:finish()
+2 -1
View File
@@ -32,7 +32,8 @@ local rect_wait = 0
function title_init()
title_sf=surf.load("title_tiles.gif")
surf.source(title_sf)
music.play(audio_main_song)
-- music.play(audio_main_song)
music_player:play(audio_main_song)
states:next()
end
+5
View File
@@ -93,6 +93,11 @@ function triggers:add_1up()
triggers.open_door(self)
end
function triggers:start_bg_music()
stages.stage_bg_music()
remove_actor(self)
end
function triggers:escena_abad_inici()
start_scene(scenes.abad_inici)
remove_actor(self)