e0825e5bbb
[NEW] Afegit music_player [NEW] Música de fons des de l'inici
348 lines
8.4 KiB
Lua
348 lines
8.4 KiB
Lua
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"
|
|
require "cacau"
|
|
require "llibre"
|
|
require "gorro"
|
|
require "peu"
|
|
require "premiere"
|
|
require "elalien"
|
|
require "bol"
|
|
require "gota"
|
|
require "invisible"
|
|
require "caco"
|
|
require "zombie"
|
|
require "score"
|
|
-- require "switches"
|
|
require "trigger"
|
|
require "imp3"
|
|
require "fireball"
|
|
require "bar_meter"
|
|
|
|
-- require "stage1"
|
|
require "remote_view"
|
|
require "dialeg"
|
|
require "trigger_event"
|
|
|
|
require "batman"
|
|
require "health_potion"
|
|
require "one_up"
|
|
require "tiles_layer2"
|
|
require "batvio"
|
|
-- require "live_scene"
|
|
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
|
|
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)
|
|
map.cell(16, 16)
|
|
surf.source(sf_tiles)
|
|
surf.target(target)
|
|
view.origin(-x,-y)
|
|
map.draw()
|
|
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()
|
|
tiles_layer2.update()
|
|
|
|
-- Moure a tots
|
|
for key,actor in pairs(actors) do
|
|
actor:update()
|
|
|
|
-- Comprovar dispars contra "monstres"
|
|
if viewp:inside(actor.x, actor.y, actor.w, actor.h) and actor~=abad then
|
|
for _, cacau_shot in pairs(cacau.shots()) do
|
|
-- if collision(actor,cacau_shot) then print("COLLISION") end
|
|
-- if actor.enabled then print(actor.name) else print("NOT "..actor.name) end
|
|
-- if cacau_shot.alive then print("CACAU") end
|
|
if actor.enabled and cacau_shot.alive and collision(actor,cacau_shot) then
|
|
if actor.hit ~= nil and not actor.dying then
|
|
actor:hit()
|
|
if actor.can_warp then warp.open(actor) end
|
|
cacau:kill(cacau_shot)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
if stages.stage_update then stages.stage_update() end
|
|
|
|
-- Actualizar el que queda
|
|
cacau.update()
|
|
|
|
-- switches.update()
|
|
warp.update_all()
|
|
|
|
trigger_event.update()
|
|
end
|
|
|
|
function world_draw()
|
|
-- Pintar la finestra del mon
|
|
render_map(sf_mapa, tiles, viewp.x, viewp.y)
|
|
tiles_layer2.draw()
|
|
|
|
-- if stage_draw_back then stage_draw_back() end
|
|
if stages.stage_draw_back then stages.stage_draw_back() end
|
|
|
|
-- 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) and actor~=abad then
|
|
actor:draw()
|
|
end
|
|
end
|
|
abad:draw(); -- per a que estiga davant de tots
|
|
|
|
dialeg.draw()
|
|
|
|
-- if stage_draw_middle then stage_draw_middle() end
|
|
if stages.stage_draw_middle then stages.stage_draw_middle() end
|
|
|
|
cacau:draw()
|
|
if stages.stage_draw_front then stages.stage_draw_front() end
|
|
|
|
remote_view_draw()
|
|
end
|
|
|
|
function update_game()
|
|
surf.target(0)
|
|
surf.cls(16)
|
|
|
|
music_player:update()
|
|
|
|
world_update()
|
|
|
|
viewport_update()
|
|
|
|
world_draw()
|
|
|
|
score.draw()
|
|
|
|
if controller:check("ESC") then
|
|
states:executar("pause", true)
|
|
end
|
|
|
|
if DEBUG then
|
|
special_keys()
|
|
debug_info()
|
|
end
|
|
end
|
|
|
|
states:registrar("game", {game_init, update_game} )
|
|
|
|
require "game_debug" |