io.write("Starting script for Level: 1 in BlinkenLUA / ",_VERSION,"!\n")
bs.callback.engine.init("initLevel");
function initLevel ()
    bs.include("_water.inc.bsl");	
    GFX_DOOR_CLOSED = bs.gfx.load("boxtile_door_closed.bmp");
    GFX_DOOR_OPEN = bs.gfx.load("boxtile_door_open.bmp");
    SND_DOOR_OPEN = bs.snd.load("fx_open_door.ogg");
    DOOR_OPEN=0;
    OBJ_DOOR = bs.obj.new(24*32, 7*32, GFX_DOOR_CLOSED, "visible,ontop,blocking");
    for i=2,23 do
        Water:new(i,18,1);
	Water:new(i,19,0);
	Water:new(i,20,0);
	Water:new(i,21,0);
	Water:new(i,22,0);
	Water:new(i,23,0);
	Water:new(i,24,0);
	Water:new(i,25,0);
	Water:new(i,26,0);
	Water:new(i,27,0);
	Water:new(i,28,0);
    end
    for i=27,31 do
        Water:new(i,18,1);
	Water:new(i,19,0);
	Water:new(i,20,0);
	Water:new(i,21,0);
	Water:new(i,22,0);
    end
    for i=35,53 do
        Water:new(i,18,1);
	Water:new(i,19,0);
    end
    for i=62,65 do
        Water:new(i,18,1);
	Water:new(i,19,0);
    end
    bs.callback.engine.physics("scriptPhysics");
end
function opendoor()
    OBJ_DOOR.gfx(GFX_DOOR_OPEN);
    OBJ_DOOR.blocking(bs.no);
    SND_DOOR_OPEN.play();
end
function scriptPhysics()
    if bs.level.pixels.required()==bs.level.pixels.collected() and DOOR_OPEN==0 then
        opendoor();
	DOOR_OPEN=1;
    end
end
