 ------Emitters-------------------
AddParticleToObject(32,"cube");
MoveEmiter("cube",240,190);

AddParticleToObject(23,"rope");
MoveEmiter("rope",340,450);

AddParticleToObject(201,"fakel1");
MoveEmiter("fakel1",160,510);
StartEmiter("fakel1");

AddParticleToObject(202,"fakel2");
MoveEmiter("fakel2",90,500);
StartEmiter("fakel2");

AddParticleToObject(203,"fakel3");
MoveEmiter("fakel3",825,535);
StartEmiter("fakel3");

AddParticleToObject(204,"fakel4");
MoveEmiter("fakel4",910,555);
StartEmiter("fakel4");


local speed = 1;
last_id = nil;
flag1,flag2 = false;
myid=-1;
WaitRender();

--Set_Cursor(60,4);

function gameinput( sender,obj_id,attachedID )
	if SLevel==1.0 then return; end;
	
 if (sender == 1  or sender==5) and not isTimes  and imagetex~=-1 then
			set_visible_object(obj.plashechka.id,false)
			set_visible_object(obj[imagetex].id,false)
			del_object_from_game(5654547)		
			gameinput(26,imageid)	
end
	
	if sender == 33 then	
		if flags.finish then
			ShowMenu(false);
		else
			ShowMenu(true);
		end;
	return;end;
	
	if sender == 2 then
		RemoveFromMouse(object);
		MessageProc(sender,obj_id);
	return;end;	
	if sender==777 then
	--старт левела	
			if flags.comics1 then			
				
				StartTimer(43342,0.5,"conv28")
			function conv28()
				CreatePlashechka(79,"100","goodgirl")	
			end		
				ShowMenu(true)
				SwitchSheet("re")	
				flags.comics1=false				
			end			
			
	if top_plush_id then		
		ShowMenu(true)
		end	
	
	end
		
			
	if sender == 100 then
			if  not flags.kluch  then
				flags.kluch= true;
				AddElement(sheet,obj.kluch28.id);
				MoveObjectToTree(obj.kluch28.id);		
				obj.kluch28.is_stored = true;			
			end	

		if flags.anim and not flag1 and not flag2 then
			frame1();
			playeffect("133")
		end;		
			
		-- Third Comics --
		if flags.comics3 and flag1 then
			flags.comics3 = false;
			CreatePlashechka(50,"104","goodgirl")	
			BlockCursor(false)
		return; end;
		-- End Third Comics --		
		
		if flags.first_time_load then
				flags.first_time_load=false
			set_visible_object(obj.intro.id,true);
			speciale_action(4,obj.intro.id);
			-- StartEmiter("Level");
		return; end;

	
		if flags.start_draw then		
			flags.start_draw = false;
			
		return;		
		end;
		-- End Starting Opening Plushes --
		
		if flag2 then
			RotateObject(35,-25,0,1,false);
		return;end;
		
	return; end;

	
	
	if sender == 8 or sender==44 then
		HideGlove();
		takeobjecttohand=false
		HideScaner();
		HideRentgen()
		HideNvg();
		setcolor(myid,0.5,0.5,0.5,0.5)
		if myid~=-1 then
		StopColorCollapse(myid)
		myid=-1;
		end
		
	return end;	
	if sender == 41 then
		RotateHandler(obj_id);	
		
	if obj_id ==obj.dragonfly.id then	
	StartAnimation( 5555555555,1,5 );
	return;end;	
	
	return end;

	
	if sender == 1 then
	

		if attachedID ~=-1 and attachedID == obj.gear1_201.id and obj_id == 403 then
			if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear1_20 = detail(26,obj.gear1_201.id,403);
			speciale_action(2,26)
			speciale_action(2,266)
			playeffect("143")
		return;end;		
		
		if attachedID ~=-1  and attachedID == obj.gear3_201.id  and obj_id == 404 then
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear3_20 = detail(28,obj.gear3_201.id,404);
			playeffect("143")
			speciale_action(2,28)
			speciale_action(2,288)
		return;end;	
		
		if attachedID ~=-1 and attachedID == obj.gear5_201.id  and obj_id == 402 then
			if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear5_20 = detail(30,obj.gear5_201.id,402);
			playeffect("143")
			speciale_action(2,30)
			speciale_action(2,300)
		return;end;

		if attachedID ~=-1 and attachedID == obj.mayatnik_201.id  and obj_id == 401 then
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.mayatnik_20 = detail(34,obj.mayatnik_201.id,401);
			speciale_action(2,34)
			speciale_action(2,344)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.ball_201.id  and obj_id == 405 then
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.ball_20 = detail(31,obj.ball_201.id,405);
			speciale_action(2,31)
			speciale_action(2,311)
		return;end;
			
		if	attachedID ~=-1 and attachedID == obj.weight_201.id  and (obj_id == 406) then
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.weight_20 = detail(37,obj.weight_201.id ,406);
			speciale_action(2,37)
			speciale_action(2,377)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.cube_201.id  and obj_id == 400 then
			if flags.parts_plased >= 6 and flags.all_items then
		
				if myid~=-1 then
						StopColorCollapse(myid)	
						myid=-1;
						-- SetAlfa(32,1,1,0.0001)
				end
				RemoveFromMouse(attachedID);
				set_visible_object(400,false)
				UnStoreObj(attachedID);
				flags.anim = true;				
					speciale_action(2,32)
					speciale_action(2,322)
	
				WaitRender();
			else
				c(flags.n)
				CreatePlashechka(9999,"202","goodgirl")
			end;
		return;end;
	
		
		if attachedID == -1 then
			if obj_id >= 400 and obj_id <= 406  then
				CreatePlashechka(9999,"205","goodgirl")
			return;end;
			
			if obj_id >= obj.braslet_20.id and obj_id <= obj.spear_20.id and attachedID==-1 then
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
				CollapseObj(obj_id);
				flags.n = flags.n + 1;
				
			return;end;
			if obj_id >= obj.weight_20.id and obj_id <= obj.cube_20.id then
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
				CollapseObj(obj_id);
				-- AlternateTimer("SwitchSheet",4000)
				flags.n = flags.n + 1;
			return;end;
			
			if obj_id==obj.ball_20.id then
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
			CollapseObj(obj_id);
				-- AlternateTimer("SwitchSheet",4000)
				flags.n = flags.n + 1;			
			end
			
			
			--last_id = obj_id;
		end;
	return; end;
	
	if sender == 12 then
	
		if obj.braslet_20.is_collapsed and obj.podkova_20.is_collapsed and obj.gear1_20.is_collapsed and obj.koleso.is_collapsed and 
			obj.gear3_20.is_collapsed and obj.verevka.is_collapsed and obj.gear5_20.is_collapsed and obj.mayatnik_20.is_collapsed and
			obj.watch_20.is_collapsed and obj.ball_20.is_collapsed and obj.sword_20.is_collapsed and obj.cube_20.is_collapsed
			and obj.spear_20.is_collapsed and obj.weight_20.is_collapsed and obj.magnet_20.is_collapsed  then
			flags.all_items = true;			
				StartTimer(234234,1,"Switch22")
				function Switch22()
					SwitchToSheet("gr")
				end
	end;
		
	if obj_id== obj.ball_20.id then
	
	flags.storedobj=flags.storedobj+1
	if flags.storedobj==7 and flags.n==15 then			
		for i,v in pairs(obj) do
		if obj[i].id == obj_id then
			AddElement(sheet,obj[i.."1"].id);
			MoveObjectToTree(obj[i.."1"].id);			
			obj[i.."1"].is_stored = true;
			switched=true;		
			takeobjecttohand=false
		return; end;
		end;
	return end
	StoreObj(obj_id);
	end
	
	if obj_id >= obj.weight_20.id and obj_id <= obj.cube_20.id then
	
	flags.storedobj=flags.storedobj+1
	if flags.storedobj==7 and flags.n==15 then			
		for i,v in pairs(obj) do
		if obj[i].id == obj_id then
			AddElement(sheet,obj[i.."1"].id);
			MoveObjectToTree(obj[i.."1"].id);			
			obj[i.."1"].is_stored = true;
			switched=true;			
			takeobjecttohand=false
		return; end;
	end;
	return end
	StoreObj(obj_id);
	end
	
	end;
	
	if sender == 14 then
	if scaner_on then return;end
		takeobjecttohand=true;			
			if obj_id==obj.gear1_201.id then
			addObjectToMouse(obj_id);			
			myid=26;
			ColorCollapse(26,100,3,0.5)
			
			return;end
			
			if obj_id==obj.gear3_201.id then
			addObjectToMouse(obj_id);			
			myid=28;
			ColorCollapse(28,100,3,0.5)
			return;end
			
			if obj_id==obj.gear5_201.id then
			addObjectToMouse(obj_id);			
			myid=30;
			ColorCollapse(30,100,3,0.5)
			return;end
			
			if obj_id==obj.mayatnik_201.id then
			addObjectToMouse(obj_id);			
			myid=34;
			ColorCollapse(34,100,3,0.5)
			return;end
			
			if obj_id==obj.ball_201.id then
			addObjectToMouse(obj_id);			
			myid=31;
			ColorCollapse(31,100,3,0.5)
			return;end
			
			if obj_id==obj.weight_201.id  then
			addObjectToMouse(obj_id);			
			myid=37;
			ColorCollapse(37,100,3,0.5)
			return;end
			
			if obj_id==obj.cube_201.id then
			addObjectToMouse(obj_id);			
			myid=32;
			ColorCollapse(32,100,3,0.5)
			return;end	
			addObjectToMouse(obj_id);		
	return;end;
	
	if sender == 28 then
	

			
		if obj_id == 35 then
			RotateObject(311,0,450,3,false);
			StartTravel(311,3,nil,nil,{"InstantiationOfLine",2,480,290,560,290,2,false},{"InstantiationOfFreeParabola",3,560,290,495,440,585,410,0.5,false},
			{"InstantiationOfCircleR",3,525,497,590,410,-1,1,2,false});
			AlternateTimer("frame3",2500);
		return;end;
	end;
	
	if sender == 7 then
		if obj_id == 344 then
			flag2 = true;
			WaitRender();
		end;
		if obj_id == 266 then
			flag1 = true;
			WaitRender();
		end;
	return;end;	
	
	if sender==26 then
	if obj_id==50 then
		flags.finish=true;		
		RemoveFromMouse(obj.kluch28.id)
		UnStoreObj(obj.kluch28.id)		
		StartTimer(24242342,0.01,"endloc28")		
		function endloc28()
			del_object_from_game(obj.dragonfly.id)
			leafobj={2234}
			GetRenderTarget(2234,"rendertar");	
			minigg=true;
			levelnext=21;
		end	
	end
	if obj_id==1 then
	StartAnimation( 5555555555,2,5 );
	return;end;
	return;end
	
		
end;

function SelectRandom()
local dist=-1;local a=-1;local b=-1;local v=100;local t=-1;local diag=-1;
local width = -1;local height = -1;local radius=1.2;
	if flags.startanimation then
	return;end	
	if flags.n >= 15 then
		
		CreatePlashechka(1,"204","goodgirl")
			StartTimer(43224,0.1,"muha")
				
				function muha ()
					StartAnimation( 5555555555,1,5 );			
				end
		return
	end
	
	ok = false
	while not ok do
		help_id = GetRandomObject();
		for i,v in pairs(obj) do
			if v.id == help_id and not v.is_collapsed then
				ok = true
				x,y=GetObjectPosition(v.id);
				x1,y1=GetObjectPosition(obj.dragonfly.id);
				width,height = GetObjectSize(v.id)
				a= (x-x1); b= (y-y1);  dist= math.sqrt (a^2+b^2);				
		        t=dist/400;		
                r = (math.sqrt(width^2+height^2)*0.5);		
				
				if r<50 then	r=75;	radius=4;	end  -- при радиусе меньше 50 определяем время кружения и радиус стрекозы
				
				if r>50 and r <100 then	r=87 radius=2.5;  end  --при радиусе больше 50 и меньше 100
				
				if r>100 then 	r=100 	radius=0.75;  end  -- при радиусе больше 100
				
				StartBigTravel(obj.dragonfly.id, v.id, 0, t, r/90, t, 2 ,radius);
			return end
		end
	end
end;

function frame1()
	canmenu=true
	BlockCursor(true)
	RotateObject(4,0,-45,2,false);
	StartTravel(5,1,nil,nil,{"InstantiationOfCircleR",3,253,136,291,136,0,-0.78,2,false});
	StartTravel(6,1,nil,nil,{"InstantiationOfCircleR",3,253,136,212,136,3.14,2.35,2,false});
	StartTravel(322,1,nil,nil,{"InstantiationOfFreeParabola",3,228,188,235,205,242,220,2,false});
	MoveObjectX(7,198,148,2);
	RotateObject(27,0,40,2,false);
	RotateObject(300,0,30,2,false);
	RotateObject(344,0,-35,1,false);
	MoveObjectY(36,81,0,2);
	AlternateTimer("frame2",2000);
	flags.startanimation=true
return;end;

function frame2()
	MoveObjectY(23,361,391,1);
	MoveObjectY(377,421,451,1);
	MoveObjectX(35,180,195,1);
	RotateObject(25,0,-35,1,false);
	RotateObject(24,0,70,1,false);
return;end;
	
function frame3()
	RotateObject(288,0,90,2,false);
	RotateObject(266,0,360,3,false);
return;end;


function detail(obj_id,attachedID,poly)	
	-- setcolor(obj_id,1,1,1,1);	
		if myid~=-1 then
			StopColorCollapse(myid)	
			myid=-1;				
		end	
	for i,v in pairs(obj) do	
		RemoveFromMouse(obj[i].id);	
	end
	UnStoreObj(attachedID);
	playeffect("134")
	takeobjecttohand=false	
	set_visible_object(poly,false)
	flags.parts_plased = flags.parts_plased + 1;
	if flags.parts_plased >= 6 then
		StartEmiter("cube");
	end;
return true;
end;