- Primer 'redo' de part del codi
- Afegida la pantalla de titol
This commit is contained in:
251
data/main.lua
251
data/main.lua
@@ -1,19 +1,25 @@
|
||||
debug = require "debug"
|
||||
arcade_config = require("arcade_config")
|
||||
coords = require "coords"
|
||||
require "helpers"
|
||||
|
||||
require "fps"
|
||||
require "fade"
|
||||
require "audio"
|
||||
require "map"
|
||||
require "mapa"
|
||||
require "warp"
|
||||
require "fade"
|
||||
require "audio"
|
||||
require "logo"
|
||||
require "intro"
|
||||
require "game"
|
||||
require "switches"
|
||||
require "warp"
|
||||
require "trigger"
|
||||
require "scenes"
|
||||
require "title"
|
||||
require "game"
|
||||
|
||||
--require "fps"
|
||||
--require "title"
|
||||
--require "menu"
|
||||
--require "switches"
|
||||
--require "trigger"
|
||||
|
||||
require "flow"
|
||||
|
||||
coords.set_config({
|
||||
tiles_width = arcade_config.tiles_width,
|
||||
@@ -23,82 +29,7 @@ coords.set_config({
|
||||
rooms_per_floor = mapa_rooms_per_piso,
|
||||
})
|
||||
|
||||
function editor_to_map_tile(editor_tile)
|
||||
local result = 0
|
||||
if editor_tile<256 then result = editor_tile + arcade_config.tiles_offset end
|
||||
return result
|
||||
end
|
||||
|
||||
function map_to_editor_tile(map_tile)
|
||||
local result = map_tile - arcade_config.tiles_offset
|
||||
if map_tile==0 then result = 256 end
|
||||
return result
|
||||
end
|
||||
|
||||
function load_tilemap( sf_mapa )
|
||||
local mapa_tw, mapa_th = surf.size(sf_mapa)
|
||||
local nrooms = mapa_rooms_per_piso*mapa_pisos
|
||||
local x = 0
|
||||
local y = 0
|
||||
local yroom = 0
|
||||
local xroom = 0
|
||||
|
||||
map.surf(sf_mapa)
|
||||
for ty=0,mapa_th-1 do
|
||||
if y == mapa_room_rows then
|
||||
yroom = yroom + mapa_rooms_per_piso
|
||||
y = 0
|
||||
end
|
||||
xroom = yroom
|
||||
for tx=0,mapa_tw-1 do
|
||||
local tile=editor_to_map_tile(mapa[1+xroom][1+x+y*mapa_room_cols])
|
||||
map.tile(tx, ty, tile)
|
||||
x = x + 1
|
||||
if x == mapa_room_cols then
|
||||
x = 0
|
||||
xroom = xroom + 1
|
||||
end
|
||||
end
|
||||
y = y +1
|
||||
end
|
||||
end
|
||||
|
||||
function mini.init()
|
||||
tiles=surf.load("tiles.gif")
|
||||
surf.source(tiles)
|
||||
local paleta=pal.load("tiles.gif")
|
||||
pal.set(paleta)
|
||||
|
||||
-- Crear el warp
|
||||
warp.init()
|
||||
|
||||
logo=surf.new(arcade_config.logo_sf.width,arcade_config.logo_sf.height)
|
||||
back=surf.new(arcade_config.surface.width,arcade_config.surface.height)
|
||||
sf_mapa=surf.new(mapa_room_cols*mapa_rooms_per_piso,mapa_room_rows*mapa_pisos)
|
||||
load_tilemap( sf_mapa )
|
||||
fade.init()
|
||||
|
||||
font_sf=font.load("X2_font.fnt")
|
||||
|
||||
textsf=surf.new(arcade_config.org_resolucion.width,arcade_config.org_resolucion.height)
|
||||
|
||||
-- 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_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)
|
||||
|
||||
function keys_init()
|
||||
-- Configuració dels input
|
||||
keyUp = tonumber(config.key("keyup")) or key.UP
|
||||
keyDown = tonumber(config.key("keydown")) or key.DOWN
|
||||
@@ -116,11 +47,70 @@ function mini.init()
|
||||
btnCycle1 = tonumber(config.key("btncycle1")) or pad.RIGHTSHOULDER
|
||||
btnCycle2 = tonumber(config.key("btncycle2")) or pad.LEFTSHOULDER
|
||||
btnPause = tonumber(config.key("btnpause")) or pad.START
|
||||
end
|
||||
|
||||
logo_init()
|
||||
-- intro_init()
|
||||
-- game_init()
|
||||
-- final_init()
|
||||
function images_init()
|
||||
tiles=surf.load("tiles.gif")
|
||||
surf.source(tiles)
|
||||
local paleta=pal.load("tiles.gif")
|
||||
pal.set(paleta)
|
||||
|
||||
-- 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_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)
|
||||
fonts_init()
|
||||
images_init()
|
||||
mapa_init()
|
||||
fade.init()
|
||||
audio_init()
|
||||
keys_init()
|
||||
logo_config(font_sf)
|
||||
surf.target(0)
|
||||
surf.cls(16)
|
||||
flow:add("logo", logo_init)
|
||||
flow:add("intro", intro_init)
|
||||
flow:add("title", title_init)
|
||||
flow:add("game", game_init)
|
||||
-- flow:add("ending", ending_init)
|
||||
-- flow:add("credits", credits_init)
|
||||
flow:add_path( { logo_init, intro_init, title_init, game_init } )
|
||||
flow:next()
|
||||
end
|
||||
|
||||
function mini.update()
|
||||
@@ -138,85 +128,6 @@ function mini.update()
|
||||
|
||||
end
|
||||
|
||||
function arc_text(str, x, y, col)
|
||||
font.current(font_sf)
|
||||
draw.text(str,x,y,col)
|
||||
end
|
||||
|
||||
function arc_textB(str, x, y, col)
|
||||
font.current(font_sf)
|
||||
-- Crear el borde negre
|
||||
draw.text(str, x-1, y-1, 16)
|
||||
draw.text(str, x , y-1, 16)
|
||||
draw.text(str, x+1, y-1, 16)
|
||||
|
||||
draw.text(str, x-1, y, 16)
|
||||
draw.text(str, x+1, y, 16)
|
||||
|
||||
draw.text(str, x-1, y+1, 16)
|
||||
draw.text(str, x , y+1, 16)
|
||||
draw.text(str, x+1, y+1, 16)
|
||||
-- Escriure la cadena
|
||||
draw.text(str,x,y,col)
|
||||
end
|
||||
|
||||
-- DEBUG
|
||||
|
||||
-- Imprime cualquier valor, incluyendo tablas anidadas
|
||||
function dump(value, indent)
|
||||
indent = indent or ""
|
||||
if type(value) ~= "table" then
|
||||
return tostring(value)
|
||||
end
|
||||
|
||||
local parts = {"{"}
|
||||
for k, v in pairs(value) do
|
||||
local key = (type(k) == "string") and k or "["..tostring(k).."]"
|
||||
table.insert(parts,
|
||||
string.format("%s %s = %s,",
|
||||
indent, key, dump(v, indent.." ")))
|
||||
end
|
||||
table.insert(parts, indent.."}")
|
||||
return table.concat(parts, "\n")
|
||||
end
|
||||
|
||||
function msg_print(x, y, msg, direct_print )
|
||||
local scr_x, scr_y
|
||||
direct_print = direct_print or false
|
||||
if direct_print then
|
||||
scr_x = x
|
||||
scr_y = y
|
||||
else
|
||||
scr_x, scr_y = viewp:screen_coords(x, y)
|
||||
end
|
||||
draw.rectf(scr_x,scr_y,45,7,16)
|
||||
draw.text(msg,scr_x+1,scr_y+1,2)
|
||||
end
|
||||
|
||||
function view_coord(x, y, w, h, color)
|
||||
local scr_x, scr_y = viewp:screen_coords(x, y)
|
||||
draw.rect(scr_x, scr_y, w, h, color)
|
||||
end
|
||||
|
||||
function debug.write_tile(x, y, yplus, print_type, align )
|
||||
local scr_x, scr_y = viewp:screen_coords(x, y)
|
||||
local hab, xx, yy = coords.world_to_tile(x, y)
|
||||
|
||||
yplus = yplus or 0
|
||||
print_type = print_type or false
|
||||
align = align or "R"
|
||||
|
||||
local txt_offset = -7
|
||||
if align=="R" then txt_offset = -14
|
||||
elseif align=="L" then txt_offset = 0
|
||||
end
|
||||
|
||||
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
|
||||
-- local msg = mapa_get_tile(hab,xx,yy)
|
||||
local msg = arc_get_tile(x,y)
|
||||
if print_type then
|
||||
msg = msg.." "..arc_check_tile(x, y)
|
||||
end
|
||||
draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2)
|
||||
end
|
||||
|
||||
function mini.close()
|
||||
surf.free(font_sf)
|
||||
end
|
||||
Reference in New Issue
Block a user