io.write("FreezeableTropfLava-Maker included!\n");

--
-- required files:
--  * tropflava%%%%.png (0-29)
--
-- use with:
--  FreezeableTropfLava:new (x_pos, y_pos, startframe, framerate, x_pos_switch, y_pos_switch);
--    where "startframe" is a number from 0..29
--
-- ToDo:
--  * Add Sound
--

FreezeableTropfLava = {
	count_objects = 0,
	GfxSwitchOn = bs.gfx.load("fg_switch_green.bmp"),
	GfxSwitchOff = bs.gfx.load("fg_switch_red.bmp")
}
function FreezeableTropfLava:new (x_pos, y_pos, startframe, framerate, x_pos_switch, y_pos_switch)
	self.count_objects = self.count_objects + 1;
	local i = self.count_objects;
	self[i] = {};
	
	self[i].switchOn = 0;
	self[i].fgObjSwitch = bs.obj.new(x_pos_switch, y_pos_switch, self.GfxSwitchOff, "visible");
	self[i].fgObjSwitch.callback.playeraction("FreezeableTropfLava_ToggleSwitch");
	
	self[i].framerate = framerate;
	self[i].fgObjTropfLava = TropfLava:new(x_pos, y_pos, startframe, framerate);
end

function FreezeableTropfLava_ToggleSwitch(fgObjSwitch)
	for i = 1,FreezeableTropfLava.count_objects do
		--TODO fix workaround, warum geht "FreezeableTropfLava[i].fgObjSwitch == fgObjSwitch" nicht?
		if FreezeableTropfLava[i].fgObjSwitch.x() == fgObjSwitch.x() and FreezeableTropfLava[i].fgObjSwitch.y() == fgObjSwitch.y() then
			if FreezeableTropfLava[i].switchOn == 0 then
				FreezeableTropfLava[i].switchOn = 1;
				FreezeableTropfLava[i].fgObjSwitch.gfx(FreezeableTropfLava.GfxSwitchOn);
				FreezeableTropfLava[i].fgObjTropfLava.gfx().framerate(0);
				FreezeableTropfLava[i].fgObjTropfLava.killing(bs.no);
			else
				FreezeableTropfLava[i].switchOn = 0;
				FreezeableTropfLava[i].fgObjSwitch.gfx(FreezeableTropfLava.GfxSwitchOff);
				FreezeableTropfLava[i].fgObjTropfLava.gfx().framerate(FreezeableTropfLava[i].framerate);
				FreezeableTropfLava[i].fgObjTropfLava.killing(bs.yes);
			end
		end
	end
end
