Files
cacaus-arcade/data/game.lua
T

246 lines
5.3 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()
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)
math.randomseed(os.time())
mapa_surface_init()
-- states:executar("check-reqs")
states:executar("title")
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
function game_exit()
-- mapa_restore_backup()
actors={}
-- cameras={}
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 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 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()
stages.stage_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"