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

--
-- required files:
--  * elevator1.bmp
--  * elevator2.bmp
--
-- use with:
--  Elevator:new(x, y_top, y_bottom, speed_y);
-- 
-- where speed_y is a number [1..3]. 
--
-- Example:
--  Elevator:new(40, 80, 400, 2);
-- 


Elevator = {
	gfx = bs.anim.load("elevator%.bmp", 1, 2, 1, bs.anim.type.forwardloop),
	timer = bs.timer.new("Elevator_Timer", 0.01),
	obj_cnt = 0
};
function Elevator:new(x, y_top, y_bottom, speed_y)
	local obj = {};
    setmetatable(obj, self);
	self.__index = self;
	obj.fgobject = bs.obj.new(x, (y_bottom-y_top)/2, self.gfx, "visible,blocking,ontop,elevator");
	obj.y_top = y_top;
	obj.y_bottom = y_bottom;
	obj.speed_y = speed_y;
	self.obj_cnt = self.obj_cnt + 1;
	self[self.obj_cnt] = obj;
	return obj_cnt;
end

function Elevator_Timer(fgObject)
	for i = 1,Elevator.obj_cnt do
		Elevator[i].fgobject.y( Elevator[i].fgobject.y() + Elevator[i].speed_y);
		if Elevator[i].fgobject.y() <= Elevator[i].y_top or Elevator[i].fgobject.y() >= Elevator[i].y_bottom then
			Elevator[i].speed_y = Elevator[i].speed_y * -1;
		end
	end
end
