[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() -- dead.start()
-- music.play(audio_game_over,0) -- music.play(audio_game_over,0)
else 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.energia=abad.max_energia
-- abad.hab=abad.safe.hab -- abad.hab=abad.safe.hab
-- abad.x=abad.safe.x -- 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") viewport= require("viewport")
require "stage_mgr" require "stage_mgr"
require "abad" require "abad"
@@ -33,6 +62,80 @@ require "batvio"
require "copter" require "copter"
require "sign" 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_w = arcade_config.tiles_width
local tile_h = arcade_config.tiles_height local tile_h = arcade_config.tiles_height
local res_w = arcade_config.resolucion.width local res_w = arcade_config.resolucion.width
@@ -116,19 +219,6 @@ function game_exit()
-- cameras={} -- cameras={}
end 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 ) function render_map( sf_map, sf_tiles, x, y, target )
target = target or 0 target = target or 0
map.surf(sf_map) map.surf(sf_map)
@@ -232,6 +322,8 @@ end
function update_game() function update_game()
surf.target(0) surf.target(0)
surf.cls(16) surf.cls(16)
music_player:update()
world_update() world_update()
+2 -1
View File
@@ -9,7 +9,8 @@ function game_over_init()
dead.vel[i]=(200+math.random(0,399))/400 dead.vel[i]=(200+math.random(0,399))/400
end end
-- game_update=dead.update -- 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() states:next()
end 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 abad ={ x=0, y= 0, w=32, h=32, dx= 88, 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 batman={ x=0, y= 96, w=32, h=32, dx=164, dy=48, dw=32, dh=32 }
local cacaus_trans={x=192,y=176,w=16,h=8,dx=65,dy=56,dw=16,dh=8} local cacaus={ x=224, y=176, w=32, h=16, dx=152, dy=64, dw=32, dh=16 }
local marc={x=30,y=6,w=198,h=102,color=2} local cacaus_trans={ x=192, y=176, w=16, h=8, dx=65, dy=56, dw=16, dh=8 }
local pas_porta={x=146,y=48,w=14,h=32,color=16} 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_x_offset = 32
local scene_y_offset = 8 local scene_y_offset = 8
intro_wait=40 local tiles_file = "tiles.gif"
intro_step=0 local next_state = "title"
function draw_escenari () local intro_wait=40
surf.cls(16) local intro_step=0
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
function draw_item_intro( name, flip, mood ) local intro_mapa_room_cols = 12; -- en quantitat de tiles
if ( name == "abad" ) then local intro_mapa_room_rows = 6; -- en quantitat de tiles
-- abad.mood = mood or "normal" local intro_mapa_rooms_per_piso = 1
draw.surf(abad.x, abad.y, abad.w, abad.h, abad.dx, abad.dy, abad.dw, abad.dh, flip) local intro_mapa_pisos = 1
abad_add_mood(abad.dx,0,abad.dy,0,flip,mood) local intro_mapa_empty_tile = 256
elseif (name == "batman" ) then
draw.surf(batman.x, batman.y, batman.w, batman.h, batman.dx, batman.dy, batman.dw, batman.dh, flip) local intro_mapa={
elseif (name == "cacaus" ) then -- 1
draw.surf(cacaus.x, cacaus.y, cacaus.w, cacaus.h, cacaus.dx, cacaus.dy, cacaus.dw, cacaus.dh, flip) {
elseif (name == "cacaus trans" ) then 256, 66, 26, 27, 28, 29, 28, 29, 26, 27, 28, 29,
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) 256,256,256, 24,256,256,256,256,256, 25,256,256,
elseif (name == "marc" ) then 64, 68,256,256,256,256,256,256,256, 25,256,256,
draw.rect(marc.x, marc.y, marc.w, marc.h, marc.color) 256,256, 66, 24,256,121,256,256,256, 38,256,256,
elseif (name == "pas porta" ) then 256, 66,256, 24,101,102,103,256,256, 38,256,256,
draw.rectf(pas_porta.x, pas_porta.y, pas_porta.w, pas_porta.h, pas_porta.color) 66,256,256, 24, 28, 29, 28, 29, 28, 29, 28, 29,
end },
end }
function intro_init() function intro_init()
print("INTRO_INIT") -- print("INTRO_INIT")
-- game_update = intro_intro mapa = intro_mapa
mapa = stage1_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 ) load_tilemap( sf_mapa )
tiles=surf.load(tiles_file)
surf.source(tiles)
local paleta=pal.load(tiles_file)
pal.set(paleta)
intro_wait=400 intro_wait=400
surf.source(tiles)
surf.target(0) surf.target(0)
surf.cls(16) surf.cls(16)
fade.fadein() fade.fadein()
font.current(font_sf) font.current(font_sf)
-- flow:add_path({intro_intro, intro_update})
states:next() states:next()
end end
function intro_intro() function intro_intro()
-- print("INTRO_INTRO")
intro_wait=1 intro_wait=1
-- game_update = intro_update
states:next() states:next()
fade.fadeoutin() fade.fadeoutin()
end end
function intro_update() function intro_update()
-- print("INTRO_UPDATE")
if key.press(key.ESCAPE) or pad.press(btnPause) then if key.press(key.ESCAPE) or pad.press(btnPause) then
-- game_init(true) states:next()
print("INTRO_UPDATE")
-- game_update = menu_init
-- game_init(true)
intro_end()
elseif key.press(key.SPACE) then elseif key.press(key.SPACE) then
intro_wait=1 intro_wait=1
end end
@@ -124,21 +126,50 @@ function intro_update()
elseif intro_step==7 then elseif intro_step==7 then
start_scene(scenes.intro_04,58) start_scene(scenes.intro_04,58)
intro_step=intro_step+1 intro_step=intro_step+1
-- STEP 8 -- STEP 8
elseif intro_step==8 then elseif intro_step==8 then
-- game_init(true) states:next()
-- game_update = menu_init
intro_end()
end end
intro_wait=50 intro_wait=50
end end
end end
function intro_end() function intro_end()
print("intro_end") -- print("INTRO_END")
fade.fadeoutin() fade.fadeoutin()
states:executar("title") states:executar(next_state)
end 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 "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() function mini.init()
-- back_sf=surf.new(256,192) game_load()
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")
end end
function mini.update() function mini.update()
@@ -107,7 +15,9 @@ function mini.update()
win.cursor(fs) win.cursor(fs)
end 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 -- Pausa per a que vaja be en mini 1.5.1
-- local t0 = os.clock() -- local t0 = os.clock()
+11 -4
View File
@@ -5,6 +5,12 @@ mapa={}
mapa.wait=0 mapa.wait=0
mapa.step=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={ half_block_set={
[20] = true, [21] = true, [20] = true, [21] = true,
[22] = true, [28] = true, [22] = true, [28] = true,
@@ -97,11 +103,12 @@ function arc_mapa_update()
end end
end end
function mapa_draw(hab) function mapa_draw(hab)
for ty=0,5 do for ty=0,mapa_room_rows-1 do
for tx=0,11 do for tx=0,mapa_room_cols-1 do
local tile=mapa[1+hab][1+tx+ty*12] local tile=mapa[1+hab][1+tx+ty*mapa_room_cols]
if tile~=256 and (tile<126 or mapa.step>4) then 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) -- draw.surf((tile&15)*8,64+(tile>>4)*8,8,8,tx*8,ty*8)
local txr = arcade_config.tiles_per_row-1 local txr = arcade_config.tiles_per_row-1
local txr2 = arcade_config.tiles_per_row_base2 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 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 if menu_sel==0 then
music.enabled(not music.enabled()) 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 elseif menu_sel==1 then
sound.enabled(not sound.enabled()) sound.enabled(not sound.enabled())
elseif menu_sel==2 then elseif menu_sel==2 then
+8 -3
View File
@@ -1,21 +1,25 @@
remote_view_wait = 0 remote_view_wait = 0
remote_view_hab = "" remote_view_hab = ""
remote_sf_w = mapa_room_cols*arcade_config.tiles_width remote_sf_w = 0
remote_sf_h = mapa_room_rows*arcade_config.tiles_height remote_sf_h = 0
function remote_view_init () 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) sf_remote=surf.new(remote_sf_w, remote_sf_h)
end end
function remote_view(hab) function remote_view(hab)
-- print("REMOTE_VIEW "..hab)
remote_view_hab = hab remote_view_hab = hab
remote_view_wait = 200 remote_view_wait = 200
end end
function remote_view_draw() function remote_view_draw()
if remote_view_wait>0 then if remote_view_wait>0 then
-- print("REMOTE_VIEW_DRAW "..remote_view_hab)
local x,y = coords.room_to_coord ( 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_source = surf.source()
local curr_target = surf.target() local curr_target = surf.target()
@@ -30,6 +34,7 @@ function remote_view_draw()
surf.source(sf_remote) 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.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) 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) surf.source(curr_source)
remote_view_wait = remote_view_wait-1 remote_view_wait = remote_view_wait-1
end end
+17 -14
View File
@@ -1,6 +1,7 @@
local mini_version = "" local mini_version = ""
local versio_req = {1,5,0} local versio_req = {1,5,0}
local parts = {} local parts = {}
local printed = false
function reqs_init() function reqs_init()
local version=sys.version() local version=sys.version()
@@ -16,32 +17,34 @@ end
function reqs_draw() function reqs_draw()
-- print("LOGO DRAW "..logo_step) -- print("LOGO DRAW "..logo_step)
-- Seleccionar font i destí
-- surf.source(logo_sf)
surf.target(0) surf.target(0)
-- Netejar destí
surf.cls(16) surf.cls(16)
draw.text("Es requerix mini "..table.concat(versio_req, "."),20,20,2) local str1 = "Es requerix mini "..table.concat(versio_req, ".")
draw.text("Executant amb mini "..table.concat(parts, "."),20,30,2) 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 end
function reqs_end() function reqs_end()
-- print("LOGO_END") -- print("LOGO_END")
-- game_update = intro_init
states:executar("logo") states:executar("logo")
-- surf.free(logo_sf)
end end
function reqs_update() function reqs_update()
if parts[1]>versio_req[1] then 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
reqs_draw() reqs_draw()
elseif parts[2]<versio_req[2] then
reqs_draw()
elseif parts[3]<versio_req[3] then
reqs_draw()
else
states:next()
end end
if controller:check("ESC") or controller:check("shoot") then 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) function start_scene(_scene, offset, stop_music)
--bkg=newsurf(128,96) if stop_music then
--setdest(bkg) print("STOP MUSIC")
--setsource(0) elseif _scene[1].musica then
--draw.surf(0,0,128,96,0,0) print("PLAY ".._scene[1].musica)
--setsource(tiles) end
--setdest(0)
scenes.current_scene=_scene scenes.current_scene=_scene
scenes.dnum=1 scenes.dnum=1
scenes.step=0 scenes.step=0
@@ -205,15 +205,15 @@ function start_scene(_scene, offset, stop_music)
scenes.offset=28 scenes.offset=28
scenes.die=scenes.current_scene[scenes.dnum].die or 0 scenes.die=scenes.current_scene[scenes.dnum].die or 0
if _scene[1].musica then if _scene[1].musica then
--print(scene[1].musica) -- print(scene[1].musica)
music.play(scenes.current_scene[scenes.dnum].musica) -- music.play(scenes.current_scene[scenes.dnum].musica)
music_player:play(scenes.current_scene[scenes.dnum].musica)
end end
if offset then scenes.offset=offset end if offset then scenes.offset=offset end
-- old_update=game_update
-- game_update=update_scene
scene.running = true scene.running = true
if not stop_music then scene.stop_music = false end 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 states:executar("scene", true); -- guardar l'estat anterior i executar
end end
@@ -242,29 +242,24 @@ end
function play_music() function play_music()
if scenes.current_scene[scenes.dnum].musica then if scenes.current_scene[scenes.dnum].musica then
-- print("PLAY MUSIC "..scenes.dnum) -- print("PLAY MUSIC "..scenes.dnum)
music.stop() -- music.stop()
music.play(scenes.current_scene[scenes.dnum].musica) -- music.play(scenes.current_scene[scenes.dnum].musica)
music_player:stop()
music_player:play(scenes.current_scene[scenes.dnum].musica)
end end
end end
function draw_abad_with_mood(mood, dx, dy, dw, dh) function draw_abad_with_mood(mood, dx, dy, dw, dh)
local ox, oy =view.origin() local ox, oy =view.origin()
view.origin(0,0) view.origin(0,0)
-- -- composicio -- composicio
local curr_sf = surf.target() local curr_sf = surf.target()
surf.target(avatar_sf) surf.target(avatar_sf)
surf.cls(16) 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) 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) 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 -- Dibuixar
view.origin(ox, oy) view.origin(ox, oy)
surf.target(curr_sf) surf.target(curr_sf)
@@ -392,6 +387,7 @@ function update_scene()
if scenes.die==0 then if scenes.die==0 then
if scenes.dnum==#scenes.current_scene then if scenes.dnum==#scenes.current_scene then
if scene.stop_music then music.stop() end if scene.stop_music then music.stop() end
-- if batman.endgame then -- if batman.endgame then
-- final_init() -- final_init()
-- fade.fadeoutin() -- fade.fadeoutin()
+62 -47
View File
@@ -1,14 +1,40 @@
function stages.stage1_init() function stages.stage1_init()
-- stagemgr init
stages.actors={} stages.actors={}
stages.boss_loaded = false
stages.boss_ready = false
stages.boss_finished = false
boss = nil
-- actors={}
-- mapa init
mapa = stage1_mapa 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} tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5}
mapa.wait=0 mapa.wait=0
mapa.step=0 mapa.step=0
mapa.tobatcave = false mapa_surface_init()
load_tilemap( sf_mapa ) 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() llibre.init()
table.insert(actors,llibre) table.insert(actors,llibre)
@@ -31,8 +57,6 @@ function stages.stage1_init()
table.insert( actors, boss ) table.insert( actors, boss )
boss_meter = bar_meter.new(20,12,128,10,1,1,boss,5) boss_meter = bar_meter.new(20,12,128,10,1,1,boss,5)
--batman
bol.init() bol.init()
table.insert(actors,bol) table.insert(actors,bol)
@@ -104,10 +128,10 @@ function stages.stage1_init()
local hp_x, hp_y = coords.room_to_world(69, 9, 3) 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) ) table.insert( actors, health_potion.new(77, hp_x, hp_y, 0, 0, 1) )
-- TRIGGERS -- TRIGGERS
-- if not menu then table.insert(actors,trigger.new(10,57,32,triggers.escena_abad_inici)) end -- 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,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(11,2,3,triggers.escena_abad_corfes,"corfes","TR02") )
table.insert( actors, trigger.new(31,1,3,triggers.escena_abad_portes,"portes","TR03") ) 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,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(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(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(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 (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(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"})) -- Dialegs
-- 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))
trigger_event.new("Premiere dialeg 1", trigger_event.new("Premiere dialeg 1",
trigger_ev.dialeg_trigger, trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init, 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(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) 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 ( 10, 4, 3 )
-- local abad_x, abad_y = coords.room_to_world ( 54, 8, 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: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)
remote_view_init()
viewp:free_move() viewp:free_move()
end 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() function stages.stage1_update()
stages.stage1_toBatcave() stages.stage1_toBatcave()
for key,actor in pairs(stages.actors) do for key,actor in pairs(stages.actors) do
@@ -256,6 +241,36 @@ function stages.stage1_draw_front()
-- boss_meter:draw() -- boss_meter:draw()
end 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_world_map"
require "stage1_boss_map" require "stage1_boss_map"
require "stage1_boss" require "stage1_boss"
+2 -1
View File
@@ -48,7 +48,8 @@ function stage1_ending:update_scene()
-- copter.init() -- copter.init()
copter.y=copter.y-16 copter.y=copter.y-16
table.insert( actors, copter) 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 elseif self.time<720 then
-- sisena escena - premiere copter -- sisena escena - premiere copter
premiere.update() premiere.update()
+5 -5
View File
@@ -1,8 +1,8 @@
mapa_room_cols = 12; -- en quantitat de tiles s01_mapa_room_cols = 12; -- en quantitat de tiles
mapa_room_rows = 6; -- en quantitat de tiles s01_mapa_room_rows = 6; -- en quantitat de tiles
mapa_rooms_per_piso = 10 s01_mapa_rooms_per_piso = 10
mapa_pisos = 8 s01_mapa_pisos = 8
mapa_empty_tile = 256 s01_mapa_empty_tile = 256
stage1_mapa={ stage1_mapa={
-- 1 -- 1
+13 -14
View File
@@ -1,40 +1,39 @@
stages = {} -- stages = {}
stages.actors={} -- stages.actors={}
stages.boss_loaded = false
stages.boss_ready = false
stages.boss_finished = false
boss = nil
function stages.stage2_init() function stages.stage2_init()
-- stagemgr init
stages.actors={} stages.actors={}
stages.boss_loaded = false
stages.boss_ready = false
stages.boss_finished = false
boss = nil
actors={} actors={}
-- mapa init
mapa = stage2_mapa mapa = stage2_mapa
tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5} tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5}
mapa.wait=0 mapa.wait=0
mapa.step=0 mapa.step=0
surf.free(sf_mapa) surf.free(sf_mapa)
sf_mapa=surf.new(s2_mapa_room_cols*s2_mapa_rooms_per_piso,s2_mapa_room_rows*s2_mapa_pisos) sf_mapa=surf.new(s2_mapa_room_cols*s2_mapa_rooms_per_piso,s2_mapa_room_rows*s2_mapa_pisos)
load_tilemap( sf_mapa ) load_tilemap( sf_mapa )
-- actors init
batvio.init() batvio.init()
table.insert(actors,batvio) 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:move(abad_x, abad_y)
abad_make_safe( true ) abad_make_safe( true )
-- viewport init
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
remote_view_init()
viewp:free_move() viewp:free_move()
stages.boss_ready = false -- remote_view_init()
stages.boss_loaded = false
end end
function stages.stage2_update() function stages.stage2_update()
+2 -1
View File
@@ -48,7 +48,8 @@ function stage2_ending:update_scene()
-- copter.init() -- copter.init()
copter.y=copter.y-16 copter.y=copter.y-16
table.insert( actors, copter) 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 elseif self.time<720 then
-- sisena escena - premiere copter -- sisena escena - premiere copter
premiere.update() premiere.update()
+3
View File
@@ -15,14 +15,17 @@ stages.stage_update = nil
stages.stage_draw_back = nil stages.stage_draw_back = nil
stages.stage_draw_middle = nil stages.stage_draw_middle = nil
stages.stage_draw_front = nil stages.stage_draw_front = nil
stages.stage_bg_music = nil
function stages.load_stage( init ) function stages.load_stage( init )
print("Loading stage "..stages.stage)
init = init or false init = init or false
stages.stage_init = stages["stage"..stages.stage.."_init"] stages.stage_init = stages["stage"..stages.stage.."_init"]
stages.stage_update = stages["stage"..stages.stage.."_update"] stages.stage_update = stages["stage"..stages.stage.."_update"]
stages.stage_draw_back = stages["stage"..stages.stage.."_draw_back"] stages.stage_draw_back = stages["stage"..stages.stage.."_draw_back"]
stages.stage_draw_middle = stages["stage"..stages.stage.."_draw_middle"] stages.stage_draw_middle = stages["stage"..stages.stage.."_draw_middle"]
stages.stage_draw_front = stages["stage"..stages.stage.."_draw_front"] 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.stage_loaded = stages.stage
stages.boss_ready = false stages.boss_ready = false
stages.boss_loaded = 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={ states={
registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...} registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
@@ -40,7 +18,8 @@ end
function states:registrar(nom, _path) function states:registrar(nom, _path)
print("[STATES] REGISTRAR => "..nom) print("[STATES] REGISTRAR => "..nom)
self.registre[nom]= {ptr=0, path=_path} 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 end
function states:borrar(nom) function states:borrar(nom)
@@ -68,22 +47,24 @@ function states:executar(nom, stacking)
end end
self.actiu=nom self.actiu=nom
self.registre[self.actiu].ptr=0 self.registre[self.actiu].ptr=0
-- Executar el primer pas
self:next() self:next()
end end
function states:next() function states:next()
print("[STATES] NEXT "..self.actiu); -- print("[STATES] NEXT "..self.actiu);
local ptr = self.registre[self.actiu].ptr local estat = self.registre[self.actiu]
local steps = #self.registre[self.actiu].path local ptr = estat.ptr
-- print("STATES_NEXT= "..self.actiu..", "..ptr..", "..steps) local steps = #estat.path
if ptr+1>steps then if ptr+1>steps then
self:finish() self:finish()
else else
self.registre[self.actiu].ptr = ptr+1 estat.ptr = ptr+1
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr] -- print("[STATES] NEXT "..self.actiu.." ("..estat.ptr.." / "..steps..")")
game_update = estat.path[estat.ptr]
end end
return self.actiu, self.registre[self.actiu].ptr return self.actiu, estat.ptr
end end
function states:finish() function states:finish()
+2 -1
View File
@@ -32,7 +32,8 @@ local rect_wait = 0
function title_init() function title_init()
title_sf=surf.load("title_tiles.gif") title_sf=surf.load("title_tiles.gif")
surf.source(title_sf) surf.source(title_sf)
music.play(audio_main_song) -- music.play(audio_main_song)
music_player:play(audio_main_song)
states:next() states:next()
end end
+5
View File
@@ -93,6 +93,11 @@ function triggers:add_1up()
triggers.open_door(self) triggers.open_door(self)
end end
function triggers:start_bg_music()
stages.stage_bg_music()
remove_actor(self)
end
function triggers:escena_abad_inici() function triggers:escena_abad_inici()
start_scene(scenes.abad_inici) start_scene(scenes.abad_inici)
remove_actor(self) remove_actor(self)