-- write out that we loaded sucessfully (mor or less, anyway)
io.write("Starting script for Level: Desert 6 (19) in BlinkenLUA / ",_VERSION,"!\n");

bs.callback.engine.init("initLevel");

-- declare some global variables

-- Fire-Tiles
-- --Config-- How many Fire-Tiles are there overall?
COUNT_FIRETILES = 0;
-- -- End of Config --
-- --Config-- Where should they be (x,y)
CFG_FIRETILES_VALUES_Y = { };
CFG_FIRETILES_VALUES_X = { };
for i=2,8 do
    COUNT_FIRETILES=COUNT_FIRETILES+1;
    CFG_FIRETILES_VALUES_Y[COUNT_FIRETILES] = 23;
    CFG_FIRETILES_VALUES_X[COUNT_FIRETILES] = i;
end
for i=47,53 do
    COUNT_FIRETILES=COUNT_FIRETILES+1;
    CFG_FIRETILES_VALUES_Y[COUNT_FIRETILES] = 23;
    CFG_FIRETILES_VALUES_X[COUNT_FIRETILES] = i;
end
-- -- End of Config --


GFX_FIRETILES = {};
GFX_WALLTILE = -1;
for i=1,6 do
    GFX_FIRETILES[i]=-1;
end
OBJ_FIRETILES = {};
OBJ_WALLTILES = {};
for i=1,COUNT_FIRETILES do
    OBJ_FIRETILES[i] = -1;
    OBJ_WALLTILES[i] = -1;
end



BLINKEN_TIMER = 0;
FOO = 23;




-- Required function: Initializing the level
function initLevel ()

    -- Create Fire-Tiles
    --    Load gfx
    GFX_FIRETILES[1] = bs.gfx.load("firetile1.png");
    GFX_FIRETILES[2] = bs.gfx.load("firetile2.png");
    GFX_FIRETILES[3] = bs.gfx.load("firetile3.png");
    GFX_FIRETILES[4] = bs.gfx.load("firetile4.png");
    GFX_FIRETILES[5] = bs.gfx.load("firetile5.png");
    GFX_FIRETILES[6] = bs.gfx.load("firetile6.png");
    
    GFX_WALLTILE = bs.gfx.load("wall_tile.bmp");
    
    --    Add Objects
    for i=1,COUNT_FIRETILES do
        OBJ_FIRETILES[i] = bs.obj.new(32*(CFG_FIRETILES_VALUES_X[i]-1), 32*(CFG_FIRETILES_VALUES_Y[i]-1), GFX_FIRETILES[1], "killing,visible,ontop");
        OBJ_WALLTILES[i] = bs.obj.new(32*(CFG_FIRETILES_VALUES_X[i]-1), 32*(CFG_FIRETILES_VALUES_Y[i]-1), GFX_WALLTILE, "visible");
    end
   
   bs.callback.engine.physics("scriptPhysics");
end




-- Required function: Physics-loop for scripting part
function scriptPhysics ()
    
    -- Fire-Tiles display
    BLINKEN_TIMER = BLINKEN_TIMER + 1;
    if BLINKEN_TIMER > 12 then
        for i=1,COUNT_FIRETILES do
            OBJ_FIRETILES[i].gfx(GFX_FIRETILES[math.mod(i+FOO,6)+1]);
        end
        FOO=FOO+1
        if FOO>1000 then
            FOO=0;
        end
        BLINKEN_TIMER = 0;
    end
    
end

