require "final"
require "fade"
require "audio"
require "dead"
require "scenes"
require "trigger"
require "score"
require "switches"
require "map"
require "mapa"
require "bol"
require "invisibl"
require "gota"
require "fireball"
require "cacau"
require "bambolla"
require "imp"
require "gps"
require "peu"
require "gorro"
require "batman"
require "elalien"
require "premiere"
require "caco"
require "zombie"
require "abad"
require "intro"
require "game"

--require "fade"
--require "audio"
--require "intro"

function _init()
    tiles=loadsurf("tiles.gif")
    setsource(tiles)
    local pal=loadpal("tiles.gif")
    setpal(pal)

    logo=newsurf(36,5)
    back=newsurf(128,96)
    fade.init()

    audio_text_abad     = loadsound(audio_text_abad)
    audio_text_premiere = loadsound(audio_text_premiere)
    audio_text_elalien  = loadsound(audio_text_elalien)
    audio_text_batman   = loadsound(audio_text_batman)
    audio_abad_jump     = loadsound(audio_abad_jump)
    audio_abad_fall     = loadsound(audio_abad_fall)
    audio_abad_hit      = loadsound(audio_abad_hit)
    audio_abad_shot     = loadsound(audio_abad_shot)
    audio_abad_step[1]  = loadsound(audio_abad_step[1])
    audio_abad_step[2]  = loadsound(audio_abad_step[2])
    audio_abad_step[3]  = loadsound(audio_abad_step[3])
    audio_abad_step[4]  = audio_abad_step[2]
    audio_switch        = loadsound(audio_switch)
    audio_hit           = loadsound(audio_hit)
    audio_low           = loadsound(audio_low)

    keyUp = tonumber(getconf("keyup")) or KEY_UP
    keyDown = tonumber(getconf("keydown")) or KEY_DOWN
    keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
    keyRight = tonumber(getconf("keyright")) or KEY_RIGHT
    keyJump = tonumber(getconf("keyjump")) or KEY_UP
    keyShoot = tonumber(getconf("keyshoot")) or KEY_SPACE

    btnUp = tonumber(getconf("btnup")) or  BTN_UP
    btnDown = tonumber(getconf("btndown")) or  BTN_DOWN
    btnLeft = tonumber(getconf("btnleft")) or  BTN_LEFT
    btnRight = tonumber(getconf("btnright")) or  BTN_RIGHT
    btnJump = tonumber(getconf("btnjump")) or  BTN_B
    btnShoot = tonumber(getconf("btnshoot")) or  BTN_A
    btnCycle1 = tonumber(getconf("btnCycle1")) or  BTN_RIGHTSHOULDER
    btnCycle2 = tonumber(getconf("btnCycle2")) or  BTN_LEFTSHOULDER
    btnPause = tonumber(getconf("btnPause")) or  BTN_START

    --game_init()
    intro_init()
    --final_init()
end

function _update()
    if btnp(KEY_F1) then
        zoom(zoom()-1)
    elseif btnp(KEY_F2) then
        zoom(zoom()+1)
    elseif btnp(KEY_F3) then
        local fs = fullscreen()
        fullscreen(not fs)
        cursor(fs)
    end

    if (game_update) then game_update() end
end

function text(str,x,y,col)
    color(16)
    prnt(str,x-1,y-1)
    prnt(str,x,y-1)
    prnt(str,x+1,y-1)
    prnt(str,x-1,y)
    prnt(str,x+1,y)
    prnt(str,x-1,y+1)
    prnt(str,x,y+1)
    prnt(str,x+1,y+1)

    prnt(str,x,y,col)
end
