------Emitters-------------------
AddParticleToObject(201,"fakel1");
MoveEmiter("fakel1",185,167);
StartEmiter("fakel1");

AddParticleToObject(202,"fakel2");
MoveEmiter("fakel2",110,123);
StartEmiter("fakel2");

AddParticleToObject(203,"fakel3");
MoveEmiter("fakel3",830,165);
StartEmiter("fakel3");

AddParticleToObject(204,"fakel4");
MoveEmiter("fakel4",905,120);
StartEmiter("fakel4");

AddParticleToObject(10,"wheel");
MoveEmiter("wheel",520,350);
StartEmiter("wheel");
------End Emitters------------
-- CreateConsole()

local speed = 1;
last_id = nil;

Set_Cursor(17,1);
Set_Cursor(205,4);
--Set_Cursor(13,4);

WaitRender();

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)		
del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)				
	end
	if sender == 6 then
		if flags.first_time_load then
			flags.first_time_load = false;			
		end;
	end;	
	
	if sender == 33 then
	
		if flags.finish then
			ShowMenu(false);
		else
			ShowMenu(true);
			SwitchToSheet("re");
		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 == 2 then
		RemoveFromMouse(object);
		MessageProc(sender,obj_id);
	return;end;	
	
	if sender==26 then
		if obj_id ==50 then
		flags.finish=true;
		SwitchToSheet("gr")	
		RemoveFromMouse(obj.kluch24.id)		
		DeleteElement("gr",obj.kluch24.id);		
		StartTimer(24242342,0.01,"endloc24")
		del_object_from_game(obj.dragonfly.id)
		function endloc24()
		    leafobj={2234}
			GetRenderTarget(2234,"rendertar");	
			minigg=true;
			levelnext=25;
		end	
		
	end
	
	end
	if sender==777 then
		if  flags.comics1 then			
			StartTimer(43342,0.5,"conv24")
			function conv24()
				CreatePlashechka(79,"100","goodgirl")	
			end		
			
			ShowMenu(true)
			SwitchToSheet("re")
			flags.comics1=false;
			return;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.kluch24.id);
			MoveObjectToTree(obj.kluch24.id);		
			obj.kluch24.is_stored = true;			
		end	
		if flags.anim then
			frame1();		
			flags.anim=false;
		end;
	
		-- First Comics --
		
		-- End First 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;

		-- Starting Opening Plushes --
		if flags.start_draw then
		
			flags.start_draw = false;
			-- WaitRender();
		return;
		-- else
			-- ShowMenu(true);
		end;
		-- End Starting Opening Plushes --
				
	return; end;
	-- End WaitRender() --

	-- Left click active object --

	
	if sender == 8 or sender==44 then
		HideGlove();
		takeobjecttohand=false
		HideScaner();
		HideRentgen()
		HideNvg();
		
		if myid~=-1 then
		StopColorCollapse(myid)
		myid=-1;
		end
		
	return end;

	
	if sender == 1 then	
		if attachedID ~=-1 and attachedID == obj.gear1_241.id and obj_id == 500 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear1_24 = detail(5,attachedID);
			playeffect("139")
			speciale_action(2,5)
			speciale_action(2,55)			
		return;end;
		if attachedID ~=-1 and attachedID == obj.gear2_241.id and obj_id == 500 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear2_24 = detail(4,attachedID);
			playeffect("139")
			speciale_action(2,4)
			speciale_action(2,44)			
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear3_241.id  and obj_id == 502 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear3_24 = detail(7,attachedID);
			playeffect("139")
			speciale_action(2,7)
			speciale_action(2,77)		
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear4_241.id  and obj_id == 500 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear4_24 = detail(8,attachedID);
			playeffect("139")
			speciale_action(2,8)
			speciale_action(2,88)			
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.gear5_241.id  and obj_id == 500 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.gear5_24 = detail(6,attachedID);
			speciale_action(2,6)
			speciale_action(2,66)
			playeffect("139")			
		return;end;

		if attachedID ~=-1 and attachedID == obj.porshen_241.id  and obj_id == 500 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.porshen_24 = detail(15,attachedID);
			playeffect("139")
			speciale_action(2,15)
			speciale_action(2,155)
		return;end;
		
		if attachedID ~=-1 and attachedID == obj.mayatnik_241.id  and obj_id == 501 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.mayatnik_24 = detail(11,attachedID);
			playeffect("139")
			speciale_action(2,11)
			speciale_action(2,111)
		return;end;
			
		if attachedID ~=-1 and attachedID == obj.pila_241.id  and obj_id == 500 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			flags.pila_24 = detail(3,attachedID);
			speciale_action(2,3)
			speciale_action(2,33)
		return;end;
				
		--if attachedID == obj.cube_20.id 
		if attachedID == -1 then
		if scaner_on then
							CreatePlashechka(9999,"70","goodgirl")
			return;end;
			if obj_id ==500 or obj_id==501 or obj_id==502  then
				CreatePlashechka(5,"205","goodgirl")
			return;end;
			
			if obj_id == 205 and flags.parts_plased < 8 then
				CreatePlashechka(9999,"202","goodgirl")
			end;
			if obj_id >= obj.sova_24.id and obj_id <= obj.sova_24.id + 5 then
				CollapseObj(obj_id);
				last_id = obj_id;
				flags.n = flags.n + 1;
				if flags.n>=15 then
					AlternateTimer("SwitchSheet1",2000)	
				end
			end;
			if obj_id == obj.perchatki_24.id then
				speciale_action(2,1);
				CollapseObj(obj_id);
				last_id = obj_id;
				flags.n = flags.n + 1;
				if flags.n>=15 then
					AlternateTimer("SwitchSheet1",2000)	
				end
			end;
			if obj_id >= obj.gear1_24.id and obj_id <= obj.pila_24.id and attachedID==-1  then
				CollapseObj(obj_id);
				-- StoreObj(obj_id);
				-- AlternateTimer("SwitchSheet",4000)
				last_id = obj_id;
				flags.n = flags.n + 1;
				
				
			end;
			if obj_id == 17 then
				if flags.n >= 15 then
				AlternateTimer("SwitchSheet1",2000)	
					-- Second Comics --
					if flags.comics2 then
						flags.comics2 = false;
						CreatePlashechka(50,"102","goodgirl")	
						canmenu=true
						takeobjecttohand=true
					return; end;
					-- End Second Comics --
				else
					CreatePlashechka(9999,"201","goodgirl")
				return;end;
			return;end;
		end;
	return; end;
	
	 if sender == 12 then
		
		if obj_id >= obj.gear1_24.id and obj_id <= obj.pila_24.id then
		 flags.storedobj= flags.storedobj+1
	if flags.storedobj==8 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_241.id then
			addObjectToMouse(obj_id);			
			myid=5;
			ColorCollapse(5,100,3,0.5)
			return;end
			
			if obj_id==obj.gear2_241.id then
			addObjectToMouse(obj_id);			
			myid=4;
			ColorCollapse(4,100,3,0.5)
			return;end
			
			if obj_id==obj.gear3_241.id then
			addObjectToMouse(obj_id);			
			myid=7;
			ColorCollapse(7,100,3,0.5)
			return;end
			
			if obj_id==obj.gear4_241.id then
			addObjectToMouse(obj_id);			
			myid=8;
			ColorCollapse(8,100,3,0.5)
			return;end
			
			if obj_id==obj.gear5_241.id then
			addObjectToMouse(obj_id);			
			myid=6;
			ColorCollapse(6,100,3,0.5)
			return;end
			
			if obj_id==obj.porshen_241.id then
			addObjectToMouse(obj_id);			
			myid=15;
			ColorCollapse(15,100,3,0.5)
			return;end
			
			if obj_id== obj.mayatnik_241.id then
			addObjectToMouse(obj_id);			
			myid=11;
			ColorCollapse(11,100,3,0.5)
			return;end
			
			if obj_id==obj.pila_241.id  then
			addObjectToMouse(obj_id);			
			myid=3;
			ColorCollapse(3,100,3,0.5)
			return;end
		addObjectToMouse(obj_id);		
	return;end;
			
	-- if sender == 35 then
		-- setcolor(obj_id,0.75,0.75,0.75,0.75);
	-- return;end;
	
	-- if sender == 39 then
		-- setcolor(obj_id,0.5,0.5,0.5,0.5);
	-- 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.n >= 15 then
	computation(17);		
	
		
		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()
playeffect("140")
	RotateObject(44,0,-180,3,false);	--(большая зеленая)
	RotateObject(55,0,90,3,false);	--(большая красная)
	RotateObject(66,0,45,3,false);	--(маленькая зеленая)
	RotateObject(77,0,-360,3,false);	--(маленькая красная)
	RotateObject(88,0,-90,3,false);	--(синяя)
	MoveObjectX(33,328,370,3);
	MoveObjectY(111,255,200,3);
	MoveObjectX(12,403,333,3);
	MoveObjectX(13,504,574,3);
	AlternateTimer("PlayComics", 3000);
return;end;

function PlayComics()
	
return;end;