skippppp=false
local takeled=false;

AddParticleToObject(1,"Highlight");
MoveEmiter("Highlight",460,465);
AddParticleToObject(100,"door");
MoveEmiter("door",390,376);
AddParticleToObject(99,"mini1");
MoveEmiter("mini1",64,441);
AddParticleToObject(105,"led");
MoveEmiter("led",185,270);
if flags.door and not flags.vzali then
Set_Cursor(105,4)
StartEmiter( "led" );
end
WaitRender();

function gameinput(sender,obj_id,attachedID)
	if SLevel==1.0 then return; end;
	if sender == 2 then		
		RemoveFromMouse(object);
		MessageProc(sender,obj_id);
	return;end;	
--тыкнули на скип в комиксе в конце	
	if sender == 1 then
		if obj_id == skip_id then			
			MoveObjectY(top_plush_id, -256, -384, 1.5/2);
			MoveObjectY(bottom_plush_id, 640, 769, 1.5/2);
			HideSkipButton()	
			StartTimer(5335,1.5,"lvl6end")	
			skippppp=true
			function lvl6end()
			set_visible_object(333,false)
			set_visible_object(100004,true)
			LevelEnd(7)
			flags.finish=true;	
			end
			
			
		end;
		
		if obj_id == obj.CD1.id or obj_id == obj.CD2.id or obj_id == obj.CD3.id or obj_id == obj.CD4.id or obj_id == obj.darts.id or
			obj_id == obj.nitki.id or obj_id == obj.news.id or obj_id == obj.tetris.id or obj_id == obj.glasses.id or obj_id == obj.player.id or
			obj_id == obj.keys.id or obj_id == obj.cup.id or obj_id == obj.ball.id or obj_id == obj.litgher.id or obj_id == obj.lupa2.id then
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
				flags.items = flags.items + 1;
				CollapseObj(obj_id);

		return; end;
		if obj_id == 105  then
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
			if flags.door then
		 	if not glove_on then
			imagetex=-1;
				CreatePlashechka(9999,"60","goodgirl")
			return; end;			
				Set_Cursor(105, 3 );
				add_to_mouse(105)
				--addObjectToMouse(105,-40,-100);
				takeobjecttohand=true
				takeled=true;
				set_visible_object(104,true)
				setcolor(104,0.5,0.5,0.5,0.5)
				StopEmiter( "led" );
				
			return; end;
		return; end;
		
		if obj_id == 100  then
		if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
		if flags.door and not flags.mini_com then
		 	if takeobjecttohand then
			playeffect("059")
			flags.vzali= true
			takeobjecttohand=false
				flags.comics2= true;
				set_visible_object(104,false)
				speciale_action(2,104, true)
				speciale_action(2,105)
				RemoveFromMouse(105);
				StopEmiter("door")
				Set_Cursor(100, 3 );				
				-- HideGlove();
				takeled=false
				StartTimer(544,0.5);
			return; end;
			imagetex=-1;
			CreatePlashechka(9999,"63","goodgirl")
		return; end;
		return; end;
		if obj_id == 99 and flags.mini1  then
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
				flags.mini1 = false;
				Set_Cursor( 99, 3 );
				ShowMenu( false );
				HideGlove()
				ClosePlushes(1);
				flags.start_mini1 = true;	
				set_visible_object(obj.plashechka.id,false)
				set_visible_object(obj.goodgirl.id,false)
				del_object_from_game(5654547)		
		return; end;
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)
				del_object_from_game(5654547)
end
	
	
--наведение на лестницу
	if sender==35 then
	
		if not glove_on and not canusegadjets then
			if obj_id == 105 and flags.door and not flags.mini1 and not flags.mini_com2 then
				set_visible_object(100004,false)
				set_visible_object(333,true)
				StartAnimation(333)			
			return;end	
	
		end
	return;end
--уведение с лестницы	
	if sender==39 then	
	set_visible_object(333,false)
	set_visible_object(100004,true)
	return;end		
	
	if sender==777 then
	--старт уровня	
		if flags.comics1 then	
		StartTimer(43342,0.5,"conv6")
			function conv6()
				CreatePlashechka(9999,"51","goodgirl")
			end		
			
			flags.comics1=false;
			ShowMenu(true);
			SwitchToSheet("re")
		return;end
--старт мини игры 1			
		 if flags.start_mini1 and not flags.start_mini2  then			
			StopEmiter( "mini1" );		
			leafobj={2234}
			GetRenderTarget(2234,"rendertar");	
			mininame="mini1";
			mininum1=6;
			mininum2=10;
			mininame2="angar";
		return; end;
--старт мини игры 2		
		if flags.start_mini2 and not flags.mini1_complete2 then					
			leafobj={2234}
			GetRenderTarget(2234,"rendertar");	
			mininame="mini1";
			mininum1=6;
			mininum2=11;
			mininame2="angar";
		return; end;
	if top_plush_id then		
		ShowMenu(true)
		SwitchToSheet("re")
	end	
	end


	
	
	if sender==36 then
--комикс в конце, меняются кадры	
	if obj_id ==333 and   not skippppp then
	speciale_action(2,1006,true) --время исчезнуть плохим героям
	speciale_action(2,1007,true)
	StartTimer(5232335,1,"nextframe")
	
	function nextframe()
	if   not skippppp then
	del_object_from_game(1006)
	del_object_from_game(1007)
	addstaticobjecttogame(1008, "bg_action",0,0,"");
	speciale_action(4,1008)	
	speciale_action(4,bottom_plush_id)	
	speciale_action(4,top_plush_id)
	speciale_action(4,skip_id);	
	speciale_action(2,1008)		
	speciale_action(2,1008,true)
	StartTimer(5335,1.5,"badaction")
	end
	function badaction()
	if   not skippppp then
	addstaticobjecttogame(1009, "action",0,0,"");
	speciale_action(4,1009)	
	speciale_action(4,bottom_plush_id)	
	speciale_action(4,top_plush_id)
	speciale_action(4,skip_id);	
	speciale_action(2,1009)
	speciale_action(2,1009,true)
	StartTimer(444,3.2)
	end
	end
	
	end
	return;end
--плашки закрываются в конце комикса	
	if obj_id ==444 and  not skippppp then		
		ShowMenu( false );			
		flags.finish=true;			
		
		MoveObjectY(top_plush_id, -256, -384, 1.5/2);
		MoveObjectY(bottom_plush_id, 640, 769, 1.5/2);
		StartTimer(5335,1.5,"lvl66end")
		
		function lvl66end()		
			LevelEnd(7)
		end
		
		HideSkipButton()		
	return;end
	
	if obj_id ==544 then
--поставили лестницу, говорит что нужно открыть ворота ангара	
	if flags.comics2 then		
			CreatePlashechka(9999,"57","goodgirl")
			flags.mini1= true;
			flags.mini_com= true;			
			StartEmiter("mini1");
			Set_Cursor(99, 2 );
		return; end;
	return;end;
	return;end

	if sender == 12 then
--коллапс мусора	
	if not flags.items_collected then
		if obj.CD1.is_collapsed and obj.CD2.is_collapsed and obj.CD3.is_collapsed and obj.CD4.is_collapsed and obj.darts.is_collapsed and
			 obj.nitki.is_collapsed and obj.news.is_collapsed and obj.tetris.is_collapsed and obj.glasses.is_collapsed and obj.player.is_collapsed and
			 obj.keys.is_collapsed and obj.cup.is_collapsed and obj.ball.is_collapsed and obj.litgher.is_collapsed and obj.lupa2.is_collapsed then
		
				flags.items_collected = true;
				CreatePlashechka(9999,"59","goodgirl")				
				StartEmiter("door");
				Set_Cursor(100, 4 );
				flags.door= true;
				Set_Cursor(105,4)
				StartEmiter( "led" );
				AlternateTimer("SwitchSheet1",1000)		
 end;
	return; 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 == 33 then	
--рендер таргет перед комиксом	
	if  flags.comicswithbad then

		speciale_action(2,obj.vremea.id,true);
		speciale_action(4,obj.vremea.id);
		StartTimer(25235,3,"startbadhero")
		
		function startbadhero()
		speciale_action(2,obj.vremea.id);
		leafobj={2235}
		GetRenderTarget(2235,"rendertar1");	
		end
		
		
		
		function rendertar1(tex_name,tex_id)
			FlipVertical(2235);
			SetAlfa(2235,0,1,0,"vasea3353523")
			SetObjectPosition(2235,0,-256);
			LeaveObjectsOnReder("leafobj");
			ShowMenu(false)
			addstaticobjecttogame(top_plush_id, "plush", 0, 0, "");
			addstaticobjecttogame(bottom_plush_id, "plush", 0, 384, "");
			addstaticobjecttogame(1006, "BadB",-10,170,"");------
			addstaticobjecttogame(1007, "BadG",530,200,"");	
		
			speciale_action(2,1006)
			speciale_action(2,1007)			
			MoveObjectY(top_plush_id, -384, -256, 1.5/2);
			MoveObjectY(bottom_plush_id, 769, 640, 1.5/2);				
			speciale_action(4,1006)	
			speciale_action(4,1007)
			takeobjecttohand=true
			speciale_action(4,bottom_plush_id)	
			speciale_action(4,top_plush_id)
			speciale_action(2,1006,true)	
			speciale_action(2,1007,true)
			DrawSkipButton()
			StartTimer(333,3)
			flags.comicswithbad=false;
			showoptions=false
			ShowMenu(false)
		return end
	
		return;end			
		
		if not flags.finish then
		flags.finish = false;
			ShowMenu(true);
			SwitchToSheet("re");
		return end
	return;end;
	
if sender == 100 then	

			if flags.first_time_load then
					flags.first_time_load=false
			set_visible_object(obj.intro.id,true);
			speciale_action(4,obj.intro.id);
			
		return; end;	
return; end;


	if sender == 8 then
--правой ложим лестницу на место		 
		HideScaner();
		c1(flags.door)
		if takeled then
		RemoveFromMouse(105);
		c("gsdsda")
		SetObjectPosition(105,173,206)
		speciale_action(4,101)
		set_visible_object(104,false)
		takeobjecttohand=false
		takeled=false
		if flags.vzali then
		StartEmiter( "led" );
		end
		return;end
		
		HideGlove();
		HideRentgen()
		HideNvg();
		
	return end;	


	return; 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 takeled then 

RemoveFromMouse(105);
SetObjectPosition(105,173,206)
speciale_action(4,101)
HideGlove();
takeled=false;
StartAnimation( 5555555555,2,5 );

end;
				
	if flags.items >= 15 then
--предметы собраны летим на лестницу	
		if not flags.vzali  then
		computation(105)			
		return; end;
--поставили лестницу летим на рычаг	
		if flags.door and not flags.mini_com then
		computation(99)					
		return; end;
		if flags.mini_com and not flags.mini_com2 then
		computation(99)	
		return; 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;
