-- write out that we loaded sucessfully (mor or less, anyway)
io.write("Starting oo-script for Level 2 of S23-IvoryTower in BlinkenLUA / ",_VERSION,"!\n")

-- Register my init call
bs.callback.engine.init("myInit");


function myInit ()
	
	bs.include("_firetile.inc.bsl");	

	Firetile:new(12, 41);
	Firetile:new(5, 35);
	Firetile:new(33, 35);
	Firetile:new(35, 33);
	Firetile:new(21, 41);
	
	Firetile:new(50, 16);
	Firetile:new(51, 12);
	Firetile:new(32, 23);
	Firetile:new(6, 46);
	Firetile:new(12, 23);
	
	Firetile:new(7, 21);
	Firetile:new(12, 10);
	Firetile:new(4, 45);
	Firetile:new(33, 15);
	Firetile:new(28, 26);
	
	for i=15,53 do
	    Firetile:new(i, 53);
	end
	for i=2,14 do
	    Firetile:new(i, 31);
	end
	for i=34,36 do
	    Firetile:new(i, 21);
	end
	for i=49,53 do
	    Firetile:new(i, 21);
	end
	
	
	-- Deadly bouncing walltiles
	GFX_DEADLYWALLTILE = bs.gfx.load("wall_tile.bmp");
	OBJ_DEADLYWALLTILES = {};
	DIR_DEADLYWALLTILES = {};
	CNT_DEADLYWALLTILES = 5;
	for i=1,CNT_DEADLYWALLTILES do
	    OBJ_DEADLYWALLTILES[i] = bs.obj.new(528+(i-1)*59, 192+(i-1)*48, GFX_DEADLYWALLTILE, "visible, killing");
	    DIR_DEADLYWALLTILES[i] = 1;
	end
	
	
	bs.include("_tropflava.inc.bsl");
	TropfLava:new(670, 64, 0, 15);
	TropfLava:new(702, 64, 20, 15);
	TropfLava:new(750, 64, 10, 15);
	TropfLava:new(838, 64, 15, 18);
	TropfLava:new(850, 64, 23, 18);
	TropfLava:new(950, 64, 2, 15);
	TropfLava:new(1000, 64, 15, 15);
	TropfLava:new(1058, 64, 23, 15);
	
	bs.callback.engine.physics("scriptPhysics");
end



-- Required function: Physics-loop for scripting part
function scriptPhysics ()

    -- Deadly bouncing walltiles
    for i=1,CNT_DEADLYWALLTILES do
	    if DIR_DEADLYWALLTILES[i] == 1 and OBJ_DEADLYWALLTILES[i].y() >= 416 then
	    	DIR_DEADLYWALLTILES[i] = -1;
	    end
	    if DIR_DEADLYWALLTILES[i] == -1 and OBJ_DEADLYWALLTILES[i].y() <= 192 then
	    	DIR_DEADLYWALLTILES[i] = 1;
	    end
	    OBJ_DEADLYWALLTILES[i].y(OBJ_DEADLYWALLTILES[i].y() + 4.5 * DIR_DEADLYWALLTILES[i]);
	end
end


