
// set window properties
SetWindowTitle( "AR kpac" )
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetScissor(0,0,0,0)
SetClearColor( 101,120,154 )
SetGenerateMipmaps( 1 )
UseNewDefaultFonts(1)
SetPrintSize(40)

permission$ = "WriteExternal"
if ( CheckPermission( permission$ ) <= 0 )
        RequestPermission( permission$ )
        while( CheckPermission( permission$ ) = 1 )
                Sync()
        endwhile
endif

permission$ = "Camera"


if ( CheckPermission( permission$ ) <= 0 )
        RequestPermission( permission$ )
        while( CheckPermission( permission$ ) = 1 )
                Sync()
        endwhile
endif


// camera range from 0.1 meters to 40 meters
SetCameraRange( 1, 0.1, 100 )
SetAmbientColor( 128,128,128 )
SetSunColor( 255,255,255 )

global test
dim bricks[1000]
dim x_pos[1000] as float
dim y_pos[1000] as float	
dim z_pos[1000] as float
dim drones[1000]
dim drone_time[1000]
dim drone_move[1000]
dim drone_turn[100,100]
dim drone_maker[100,100]
dim drone_test_under[1000]
dim rings[1000] 
dim drone_skin[1000]



global music
global me
global keep
global brick
global pivot
global test_front
global test_under
global jump
global Move
global move_time#
global arrow
global rings_amount
global drone_amount
global pick_up
move_time#=0
global ball
global dropping=0



 for i = 101 to 150
	CreateObjectPlane( i, 1,1 )
	SetObjectCollisionMode(i,0)
	SetObjectRotation( i, 90,0,0 )
	FixObjectPivot( i )
	SetObjectVisible( i, 0 )
	SetObjectColor( i, 255,255,255,128 ) // 50% transparent
	SetObjectTransparency( i, 1 )
next i

 
AddVirtualButton(90,100,300,200)
AddVirtualButton(91,300,300,200)
AddVirtualButton(92,100,500,200)
AddVirtualButton(93,300,500,200)
AddVirtualButton(94,100,100,200)
AddVirtualButton(95,300,100,200)
AddVirtualButton(96,100,700,200)
AddVirtualButton(97,300,700,200)
AddVirtualButton(98,1024-200,500,200)
AddVirtualButton(99,1024-200,700,200)
setVirtualButtontext(90,"rotate x+")
setVirtualButtontext(91,"rotate x-")
setVirtualButtontext(92,"rotate z+")
setVirtualButtontext(93,"rotate z-")
setVirtualButtontext(94,"rotate y+")
setVirtualButtontext(95,"rotate y-")
setVirtualButtontext(96,"turn left")
setVirtualButtontext(97,"turn right")
setVirtualButtontext(98,"jump")
setVirtualButtontext(99,"move")


SetCameraRotation(1,0,0,0)
setcameraposition(1,0,1,-4)
 

AddVirtualButton( 1, 100,465,200 )
AddVirtualButton( 2, 100,665,200 )
SetVirtualButtonText( 1, "level +" )
SetVirtualButtonText( 2, "level -" )
AddVirtualButton( 4, 924,665,200 )
SetVirtualButtonText( 4, "Hide" )
AddVirtualButton( 5, 305,465,200 )
AddVirtualButton( 6, 305,665,200 )
SetVirtualButtonText( 5, "Light +" )
SetVirtualButtonText( 6, "Light -" )
AddVirtualButton( 9, 300,70,200 )
SetVirtualButtonText( 9, "zoom -" )
AddVirtualButton( 10, 100,70,200 )
SetVirtualButtonText( 10, "zoom +" )
AddVirtualButton( 11, 1024/2,10,200 )
SetVirtualButtonText( 11, "menu" )


function ShowHUD( show as integer,show2 as integer )
	SetVirtualButtonVisible( 1, show )
	SetVirtualButtonVisible( 2, show )
	SetVirtualButtonVisible( 4, show )
	SetVirtualButtonVisible( 5, show )
	SetVirtualButtonVisible( 6, show )
	SetVirtualButtonVisible( 9, show )
	SetVirtualButtonVisible( 10, show )
	SetVirtualButtonVisible( 11, show2 )
	SetVirtualButtonVisible( 90, show2 )
	SetVirtualButtonVisible( 91, show2 )
	SetVirtualButtonVisible( 92, show2 )
	SetVirtualButtonVisible( 93, show2 )
	SetVirtualButtonVisible( 94, show2 )
	SetVirtualButtonVisible( 95, show2 )
	SetVirtualButtonVisible( 96, show2 )
	SetVirtualButtonVisible( 97, show2 )
	SetVirtualButtonVisible( 98, show2 )
	SetVirtualButtonVisible( 99, show2 )
	
	SetVirtualButtonActive( 1, show )
	SetVirtualButtonActive( 2, show )
	SetVirtualButtonActive( 4, show )
	SetVirtualButtonActive( 5, show )
	SetVirtualButtonActive( 6, show )
	SetVirtualButtonActive( 9, show )
	SetVirtualButtonActive( 10, show )
	SetVirtualButtonActive( 11, show2 )
	
	
	SetVirtualButtonActive( 90, show2 )
	SetVirtualButtonActive( 91, show2 )
	SetVirtualButtonActive( 92, show2 )
	SetVirtualButtonActive( 93, show2 )
	SetVirtualButtonActive( 94, show2 )
	SetVirtualButtonActive( 95, show2 )
	SetVirtualButtonActive( 96, show2 )
	SetVirtualButtonActive( 97, show2 )
	SetVirtualButtonActive( 98, show2 )
	SetVirtualButtonActive( 99, show2 )
	
	
	
endfunction

// initialize AR, if possible
ARSetup()
while( ARGetStatus() = 1 )
	// wait while user is being prompted to install ARCore
	Sync()
endwhile

AnchorID as integer = 0
ShowPlanes as integer = 1
ambientScale# = 1.0

ShowHUD( 1,0 )

SetCameraRotation(1,0,0,0)
setcameraposition(1,0,0.3,-2)
global lev=1
global play_game=0
level1()
global object_hit11

do
	// get light estimation
			ambient = ARGetLightEstimate() * 255 * ambientScale#
			SetAmbientColor( ambient,ambient,ambient )
				if ( GetPointerReleased() and ShowPlanes = 1 )
		
				numHits = ARHitTest( GetPointerX(), GetPointerY() )
			if ( numHits > 0 )
				if ( AnchorID > 0 ) then ARDeleteAnchor( AnchorID )
				 AnchorID = ARCreateAnchorFromHitTest( 1 )
			
			
		keep=AnchorID
		ARFixObjectToAnchor( pivot, AnchorID)
		

		else
			// if the user didn't tap on any planes then hide the object
			
		endif
		// clean up some internal resources
		ARHitTestFinish()
	endif
	
	// place the buttons at the edge of the screen
	// needs to be done regularly in case orientation changes
	SetVirtualButtonPosition( 1, GetScreenBoundsLeft()+105, GetScreenBoundsBottom()-310 )
	SetVirtualButtonPosition( 2, GetScreenBoundsLeft()+105, GetScreenBoundsBottom()-105 )
	SetVirtualButtonPosition( 4, GetScreenBoundsRight()-105, GetScreenBoundsBottom()-105 )
	SetVirtualButtonPosition( 5, GetScreenBoundsLeft()+310, GetScreenBoundsBottom()-310 )
	SetVirtualButtonPosition( 6, GetScreenBoundsLeft()+310, GetScreenBoundsBottom()-105 )
	
	// detect button presses if they are visible
	if ( ShowPlanes = 1 )
		if ( GetVirtualButtonPressed(1) )
			if lev<10 
			for t=1 to 1000
			if GetObjectExists(bricks[t]):deleteobject(bricks[t]) : endif
			if GetObjectExists( rings[t] )=1:deleteobject( rings[t] ) : endif
			if GetObjectExists( drones[t])=1:deleteobject( drones[t]) : endif
			
			if GetObjectExists( drone_test_under[t])=1:deleteobject( drone_test_under[t]) : endif
			x_pos[t] =0
			y_pos[t] =0	
			z_pos[t] =0
			drone_time[t]=0
			drone_move[t]=0
			
			next

			for t=1 to 100
				for q=1 to 100
				drone_turn[t,q]=0
				drone_maker[t,q]=0
				next
			next

						if  GetObjectExists(me)=1:deleteobject(me):endif
						if	GetObjectExists( pivot)=1:deleteobject(pivot):endif
						if	GetObjectExists( test_front)=1:deleteobject(test_front):endif
						if	GetObjectExists( test_under)=1:deleteobject(test_under):endif
						if	GetObjectExists( ball)=1:deleteobject(ball):endif
						if	GetObjectExists( arrow)=1:deleteobject(arrow):endif
		
			win=0
			brick=0
			jump=0
			Move=0
			move_time#=0
			lev=lev+1
			IF lev=11 then lev=1
			select lev
				case 1:level1():endcase
				case 2:level2():endcase
				case 3:level3():endcase
				case 4:level4():endcase
				case 5:level5():endcase
				case 6:level6():endcase
				case 7:level7():endcase					
			    case 8:level8():endcase
				case 9:level9():endcase
				case 10:level10():endcase		
			endselect
			
		ARFixObjectToAnchor( pivot, keep)
			endif
			
	
			
		endif

if ( GetVirtualButtonPressed(2) )
	if lev>1
					for t=1 to 1000
			if GetObjectExists(bricks[t]):deleteobject(bricks[t]) : endif
			if GetObjectExists( rings[t] )=1:deleteobject( rings[t] ) : endif
			if GetObjectExists( drones[t])=1:deleteobject( drones[t]) : endif
			
			if GetObjectExists( drone_test_under[t])=1:deleteobject( drone_test_under[t]) : endif
			x_pos[t] =0
			y_pos[t] =0	
			z_pos[t] =0
			drone_time[t]=0
			drone_move[t]=0

			
			next

			for t=1 to 100
				for q=1 to 100
				drone_turn[t,q]=0
				drone_maker[t,q]=0

				next
					next

			
			
	if  GetObjectExists(me)=1:deleteobject(me):endif
	if	GetObjectExists( pivot)=1:deleteobject(pivot):endif
	if	GetObjectExists( test_front)=1:deleteobject(test_front):endif
	if	GetObjectExists( test_under)=1:deleteobject(test_under):endif
	if	GetObjectExists( ball)=1:deleteobject(ball):endif
	if	GetObjectExists( arrow)=1:deleteobject(arrow):endif
			brick=0
			jump=0
			Move=0
			move_time#=0
			lev=lev-1
			win=0
			select lev
				case 1:level1():endcase
				case 2:level2():endcase
				case 3:level3():endcase
				case 4:level4():endcase
				case 5:level5():endcase
				case 6:level6():endcase
				case 7:level7():endcase					
			    case 8:level8():endcase
				case 9:level9():endcase
				case 10:level10():endcase		
			endselect
			
		ARFixObjectToAnchor( pivot, keep)

	endif
			
			
			
endif
			if ( GetVirtualButtonPressed(9) )
					MoveObjectLocalZ(pivot,-0.08)
					endif
					
			if ( GetVirtualButtonPressed(10) )
					MoveObjectLocalZ(pivot,0.08)
					endif
			
		
		

		if ( GetVirtualButtonReleased(4)=1 and play_game=0)
			ShowPlanes = 1 - ShowPlanes
			ShowHUD( 0,1 )
			play_game=1
		endif
		if ( GetVirtualButtonPressed(5) )
			inc ambientScale#, 0.1
		endif
		if ( GetVirtualButtonPressed(6) )
			dec ambientScale#, 0.1
		endif
	else
		

		if ( GetVirtualButtonReleased(11)=1 and play_game=1 )
			ShowPlanes = 1 - ShowPlanes
			ShowHUD( 1,0 )
			play_game=0
		endif
	endif
	

    for i = 101 to 150
		SetObjectVisible( i, 0 )
	next i
	
	// show detected planes
	if ( ShowPlanes )
		numPlanes = ARGetPlanes(0)
		// this demo stops at 50 planes, but there is no internal limit
		if numPlanes > 50 then numPlanes = 50
		for i = 1 to numPlanes
			SetObjectPosition( i+100, ARGetPlaneX(i), ARGetPlaneY(i), ARGetPlaneZ(i) )
			SetObjectRotation( i+100, ARGetPlaneAngleX(i), ARGetPlaneAngleY(i), ARGetPlaneAngleZ(i) )
			SetObjectScale( i+100, ARGetPlaneSizeX(i), 1, ARGetPlaneSizeZ(i) )
			
			SetObjectVisible( i+100, 1 )
		next i
		ARGetPlanesFinish()
	endif
	
	
	
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
      ////*********************************************************************************************************************************************************
				
				ARDrawBackground() 
				
				
				if play_game=1

				game_on()
				endif
			
				
    Sync()
loop

function game_on()
	
	
   if GetVirtualButtonState(98)=1 and move_time#=0 and move=0
	   move_time#=10
	   jump=1
	   endif
	   
	if jump=0
		
		if move=0 and GetVirtualButtonState(99)=1   and move_time#=0
			move=1
			move_time#=10
			endif
		
		if move_time#>0 and move=1
			move_time#=move_time#-1
			MoveObjectLocalZ(me,0.008)
			RotateObjectLocalX(ball,9)
			
		if move_time#=0
				move=0
				endif
				endif

		if move=0 and GetVirtualButtonState(97)=1  and move_time#=0
			move_time#=10
			move=10
			endif
	
		if move=0 and GetVirtualButtonState(96)=1  and move_time#=0
			move_time#=10
			move=11
			endif	
			
			
			if (move=10)
				move_time#=move_time#-1
				if move_time#=0:move=0:endif
				RotateObjectLocalY(me,9)
			endif
			
			if (move=11)
				move_time#=move_time#-1
				if move_time#=0:move=0:endif
				RotateObjectLocalY(me,-9)
			endif
			
			
			
			if (move=5)
				move_time#=move_time#-1
				if move_time#=0
					move=6
					move_time#=10
					endif
					
				RotateObjectLocalx(me,9)
			endif
			
			if (move=6)
				move_time#=move_time#-1
				if move_time#=0
					move=0
					endif
				MoveObjectLocalZ(me,0.008)
			endif
					
			
			
			
			if move=0
				x#=GetObjectWorldX(me)
				y#=GetObjectWorldy(me)
				z#=GetObjectWorldz(me)
				
				x1#=GetObjectWorldX(test_under)
				y1#=GetObjectWorldy(test_under)
				z1#=GetObjectWorldz(test_under)
				
				
				
				object_hit1=ObjectRayCast(0,x#,y#,z#,x1#,y1#,z1#)
				
				
				hit_front=0
				hit_under=0
				
				for t=1 to brick
					if object_hit1=bricks[t] then hit_under=t
					next
				
				
				if hit_front>0 and move_time#=0 and move=0
					RotateobjectLocalX(me,-90)
					endif
					
				
					if hit_under=0 and move_time#=0 and move=0
						
						move_time#=10
						move=5
					endif
					endif

						x2#=GetObjectWorldX(test_front)
						y2#=GetObjectWorldy(test_front)
						z2#=GetObjectWorldz(test_front)
						object_hit2=ObjectRayCast(0,x#,y#,z#,x2#,y2#,z2#)
					
					for t=1 to brick
						if object_hit2=bricks[t] then hit_front=t
						next
					
					if hit_front>0 and move_time#=0 and move=0 
						RotateobjectLocalX(me,-90)
						endif	
					
					
					
	endif
	
	
				for p=1 to rings_amount
					
					if GetObjectExists(rings[p])=1
						
							x#=GetObjectWorldX(me)
							y#=GetObjectWorldy(me)
							z#=GetObjectWorldz(me)
						
							x1#=GetObjectWorldX(rings[p])
							y1#=GetObjectWorldy(rings[p])
							z1#=GetObjectWorldz(rings[p])
						
					
					if x#>x1#-0.04 and x#<x1#+0.04
					if y#>y1#-0.04 and y#<y1#+0.04
					if z#>z1#-0.04 and z#<z1#+0.04	
						
						if GetObjectVisible(rings[p])=1
							
						setObjectVisible(rings[p],0)
						pick_up=pick_up+1
						endif
						
					
					endif
					endif
					endif
					
					
					RotateObjectLocalY(rings[p],1)
					endif

					next
	
	
				move_drones()
	
				if GetVirtualButtonState(90)=1 :RotateObjectLocalx(pivot,1):endif
				if GetVirtualButtonState(91)=1 :RotateObjectLocalx(pivot,-1):endif
				if GetVirtualButtonState(92)=1 :RotateObjectLocalz(pivot,1):endif
				if GetVirtualButtonState(93)=1 :RotateObjectLocalz(pivot,-1):endif
				if GetVirtualButtonState(94)=1 :RotateObjectLocaly(pivot,1):endif
				if GetVirtualButtonState(95)=1 :RotateObjectLocaly(pivot,-1):endif
				
				if jump=1
				Jump1()
				endif
				if jump=2
				drop()
				endif
				
				print (hit_under)
				print (hit_front)
				print (brick)
				print(pick_up)
				
	if pick_up=rings_amount
		
			if hit_under =101 and lev=1 :win=1:	endif
			if hit_under =77  and lev=2   :win=1: endif
			if hit_under =97  and lev=3   :win=1: endif
			if hit_under =149 and lev=4   :win=1: endif
			if hit_under =101 and lev=5   :win=1: endif	
			if hit_under =101 and lev=6   :win=1: endif	
			if hit_under =95  and lev=7   :win=1: endif	
			if hit_under =146 and lev=8   :win=1: endif
			if hit_under =135 and lev=9   :win=1: endif
			if hit_under =185 and lev=10  :win=1: endif				
	endif
	
			if win=1
				
				if lev<10
			for t=1 to 1000
			if GetObjectExists(bricks[t]):deleteobject(bricks[t]) : endif
			if GetObjectExists( rings[t] )=1:deleteobject( rings[t] ) : endif
			if GetObjectExists( drones[t])=1:deleteobject( drones[t]) : endif
			
			if GetObjectExists( drone_test_under[t])=1:deleteobject( drone_test_under[t]) : endif
			x_pos[t] =0
			y_pos[t] =0	
			z_pos[t] =0
			drone_time[t]=0
			drone_move[t]=0
			
			next

			for t=1 to 100
				for q=1 to 100
				drone_turn[t,q]=0
				drone_maker[t,q]=0
				next
			next

			
			
						if  GetObjectExists(me)=1:deleteobject(me):endif
						if	GetObjectExists( pivot)=1:deleteobject(pivot):endif
						if	GetObjectExists( test_front)=1:deleteobject(test_front):endif
						if	GetObjectExists( test_under)=1:deleteobject(test_under):endif
						if	GetObjectExists( ball)=1:deleteobject(ball):endif
						if	GetObjectExists( arrow)=1:deleteobject(arrow):endif
		
			win=0
			brick=0
			jump=0
			Move=0
			move_time#=0
			lev=lev+1
			select lev
				case 1:level1():endcase
				case 2:level2():endcase
				case 3:level3():endcase
				case 4:level4():endcase
				case 5:level5():endcase
				case 6:level6():endcase
				case 7:level7():endcase					
			    case 8:level8():endcase
				case 9:level9():endcase
				case 10:level10():endcase		
			endselect
			
		ARFixObjectToAnchor( pivot, keep)
		
	
		
		
		
			endif
			
				endif
	
endfunction

function move_drones()
	for q=1 to drone_amount
		
if GetObjectExists(drones[q])=1
	MoveObjectLocalZ(drones[q],0.008)
	RotateObjectLocalX(drone_skin[q],9)
				x#=GetObjectWorldX(me)
				y#=GetObjectWorldy(me)
				z#=GetObjectWorldz(me)
				x1#=GetObjectWorldX(drones[q])
				y1#=GetObjectWorldy(drones[q])
				z1#=GetObjectWorldz(drones[q])
					if x#>x1#-0.04 and x#<x1#+0.04
					if y#>y1#-0.04 and y#<y1#+0.04
					if z#>z1#-0.04 and z#<z1#+0.04	
						reset_me()
						endif
						endif
						endif

	drone_time[q]=drone_time[q]+1
	if drone_time[q]=10
		drone_time[q]=0
		
		
		
				x#=GetObjectWorldX(drones[q])
				y#=GetObjectWorldy(drones[q])
				z#=GetObjectWorldz(drones[q])

				x1#=GetObjectWorldX(drone_test_under[q])
				y1#=GetObjectWorldy(drone_test_under[q])
				z1#=GetObjectWorldz(drone_test_under[q])
				
				object_hit11=ObjectRayCast(0,x#,y#,z#,x1#,y1#,z1#)
					
					
					
					if object_hit11=bricks[drone_maker[q,drone_move[q]]]
						
						select  drone_turn[q,drone_move[q]]
						case 1:	RotateObjectLocalX(drones[q],-90): drone_move[q]=drone_move[q]+1 : endcase
						case 2:	RotateObjectLocalY(drones[q],-90): drone_move[q]=drone_move[q]+1 : endcase	
						case 3:	RotateObjectLocaly(drones[q],90) : drone_move[q]=drone_move[q]+1 : endcase	
						case 4:	RotateObjectLocalx(drones[Q],90) : drone_move[Q]=drone_move[Q]+1:endcase	
						case 5:	RotateObjectLocalY(drones[Q	],180) : drone_move[Q]=drone_move[Q]+1:endcase
						endselect
							
							if lev=1
								if drone_move[1]=7 then drone_move[1]=1
								if drone_move[2]=5 then drone_move[2]=1
								if drone_move[3]=7 then drone_move[3]=1
								endif
							if lev=2
								if drone_move[1]=5 then drone_move[1]=1
								if drone_move[2]=5 then drone_move[2]=1
								if drone_move[3]=5 then drone_move[3]=1
								endif
							
							if lev=3
								if drone_move[1]=5 then drone_move[1]=1
								if drone_move[2]=5 then drone_move[2]=1
								if drone_move[3]=5 then drone_move[3]=1
								if drone_move[4]=5 then drone_move[4]=1
								endif
							if lev=4
								if drone_move[1]=5 then drone_move[1]=1
								if drone_move[2]=5 then drone_move[2]=1
								if drone_move[3]=5 then drone_move[3]=1
								if drone_move[4]=5 then drone_move[4]=1
								if drone_move[5]=5 then drone_move[5]=1
								endif	
							if lev=5
								if drone_move[1]=5 then drone_move[1]=1
								if drone_move[2]=5 then drone_move[2]=1
								if drone_move[3]=5 then drone_move[3]=1
								if drone_move[4]=5 then drone_move[4]=1
								
								
								endif	
								
								
							if lev=6
								if drone_move[1]=5 then drone_move[1]=1
								if drone_move[2]=5 then drone_move[2]=1
								if drone_move[3]=5 then drone_move[3]=1
								if drone_move[4]=5 then drone_move[4]=1
								
								endif
								
								
									
							if lev=7
								if drone_move[1]=7 then drone_move[1]=1
								if drone_move[2]=7 then drone_move[2]=1
								if drone_move[3]=5 then drone_move[3]=1
								endif
								
							if lev=8
								if drone_move[1]=5 then drone_move[1]=1
								if drone_move[2]=5 then drone_move[2]=1
								if drone_move[3]=5 then drone_move[3]=1
								if drone_move[4]=5 then drone_move[4]=1
								if drone_move[5]=5 then drone_move[5]=1
								if drone_move[6]=5 then drone_move[6]=1
								endif	
								
								
							if lev=9
								if drone_move[1]=5 then drone_move[1]=1
								if drone_move[2]=7 then drone_move[2]=1
								if drone_move[3]=7 then drone_move[3]=1
								if drone_move[4]=5 then drone_move[4]=1
								
								endif	
								
								
							if lev=10
								if drone_move[1]=11 then drone_move[1]=1
								if drone_move[2]=11 then drone_move[2]=1
								if drone_move[3]=11 then drone_move[3]=1
								if drone_move[4]=11 then drone_move[4]=1
								if drone_move[5]=11 then drone_move[5]=1
								if drone_move[6]=11 then drone_move[6]=1
								if drone_move[7]=11 then drone_move[7]=1
								if drone_move[8]=11 then drone_move[8]=1
								endif	
						endif
					
	
		endif
	endif
next

endfunction

function Jump1()
	
	move_time#=move_time#-1
	if move_time#>0
	MoveObjectLocalz(me,0.02)
	MoveObjectLocaly(me,0.05)
	endif
	
	x#=GetObjectWorldX(me)
	y#=GetObjectWorldy(me)
	z#=GetObjectWorldz(me)
			
	x1#=GetObjectWorldX(test_front)
	y1#=GetObjectWorldy(test_front)
	z1#=GetObjectWorldz(test_front)
			
	object_hit2=ObjectRayCast(0,x#,y#,z#,x1#,y1#,z1#)
	if object_hit2<>0:MoveObjectLocalz(me,-0.02):endif
	
	if move_time#=0 
		 jump=2
		 move_time#=10
		 endif
	endfunction

function reset_me()
	 FixObjectToObject(me,0)
	    setobjectposition(me,0,0,0)
	    setobjectrotation(me,0,0,0)
	    
	    
	    select lev
	    case 1
			FixObjectToObject(me,bricks[99])
			MoveObjectLocalY(me,0.08)
			endcase
			
		case 2
			FixObjectToObject(me,bricks[75])
			MoveObjectLocalY(me,0.08)
			endcase	


		case 3
			FixObjectToObject(me,bricks[102])
			MoveObjectLocalY(me,0.08)
			endcase


		case 4
			FixObjectToObject(me,bricks[145])
			MoveObjectLocalY(me,0.08)
			endcase

		case 5
			FixObjectToObject(me,bricks[97])
			MoveObjectLocalY(me,0.08)
			endcase
			
		case 6
			FixObjectToObject(me,bricks[97])
			MoveObjectLocalY(me,0.08)
			endcase	

		case 7
			FixObjectToObject(me,bricks[93])
			MoveObjectLocalY(me,0.08)
			RotateObjectLocalY(me,180)
			endcase
		case 8
			FixObjectToObject(me,bricks[148])
			MoveObjectLocalY(me,0.08)
			RotateObjectLocalY(me,180)
			endcase		
			
		endselect
			
	
				
	    
	    dropping=0
	    jump=0
		move_time#=0
		move=0
		endfunction
		
function drop()
	
	MoveObjectLocaly(me,-0.04)
   dropping=dropping+1
   if dropping=100
	   reset_me()
	endif
	   
	   
				for t=1 to brick
				 if jump>0
					x#=GetObjectWorldX(test_under)
					y#=GetObjectWorldy(test_under)
					z#=GetObjectWorldz(test_under)
				x1#=GetObjectWorldX(bricks[t])
				y1#=GetObjectWorldy(bricks[t])
				z1#=GetObjectWorldz(bricks[t])
					
					if x#>x1#-0.04 and x#<x1#+0.04
					if y#>y1#-0.04 and y#<y1#+0.04
					if z#>z1#-0.04 and z#<z1#+0.04	
						FixObjectToObject(me,0)
						setobjectposition(me,0,0,0)
						FixObjectToObject(me,bricks[t])
						MoveObjectLocalY(me,0.08)
						jump=0
						move_time#=0
						move=0
						dropping=0
					endif
					endif
					endif
					endif
					next
	
	endfunction

function level1()
	
	
		if GetMusicExists(music):DeleteMusic(music):endif
			music=LoadMusic("\media\music\music1.mp3")

pick_up=0
texture_1=LoadImage("\media\textures\lev1.jpg") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy

brick=0	
	
		opentoread(1,"\media\data\Level1.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.001,32,32)	
						SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],-0.08*14)
						MoveObjectLocaly(bricks[t],-0.08*4)
						next
				
		
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[99])
				MoveObjectLocalY(me,0.08)

				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)

				loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)

				
				rings[1]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[1],0.04,0.04,0.04)
				FixObjectToObject(rings[1],bricks[1])
				MoveObjectLocalY(rings[1],0.08)
				SetObjectCollisionMode(rings[1],0)
				
				rings[2]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[2],0.04,0.04,0.04)
				FixObjectToObject(rings[2],bricks[31])
				MoveObjectLocalY(rings[2],0.08)
				SetObjectCollisionMode(rings[2],0)
				
				
				rings[3]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[3],0.04,0.04,0.04)
				FixObjectToObject(rings[3],bricks[13])
				MoveObjectLocalY(rings[3],0.08)
				SetObjectCollisionMode(rings[3],0)
				
				
				rings[4]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[4],0.04,0.04,0.04)
				FixObjectToObject(rings[4],bricks[19])
				MoveObjectLocalY(rings[4],0.08)
				SetObjectCollisionMode(rings[4],0)
				
				
				rings[5]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[5],0.04,0.04,0.04)
				FixObjectToObject(rings[5],bricks[37])
				MoveObjectLocalY(rings[5],0.08)
				SetObjectCollisionMode(rings[5],0)
				
				rings[6]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[6],0.04,0.04,0.04)
				FixObjectToObject(rings[6],bricks[43])
				MoveObjectLocalY(rings[6],0.08)
				SetObjectCollisionMode(rings[6],0)
				
				
				rings[7]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[7],0.04,0.04,0.04)
				FixObjectToObject(rings[7],bricks[54])
				MoveObjectLocalY(rings[7],0.08)
				SetObjectCollisionMode(rings[7],0)
				
				rings[8]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[8],0.04,0.04,0.04)
				FixObjectToObject(rings[8],bricks[49])
				MoveObjectLocalY(rings[8],0.08)
				SetObjectCollisionMode(rings[8],0)
				
				
				rings[9]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[9],0.04,0.04,0.04)
				FixObjectToObject(rings[9],bricks[79])
				MoveObjectLocalY(rings[9],0.08)
				SetObjectCollisionMode(rings[9],0)
				
				rings[10]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[10],0.04,0.04,0.04)
				FixObjectToObject(rings[10],bricks[67])
				MoveObjectLocalY(rings[10],0.08)
				SetObjectCollisionMode(rings[10],0)
				
				
				rings[11]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[11],0.04,0.04,0.04)
				FixObjectToObject(rings[11],bricks[85])
				MoveObjectLocalY(rings[11],0.08)
				SetObjectCollisionMode(rings[11],0)
				
				rings[12]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[12],0.04,0.04,0.04)
				FixObjectToObject(rings[12],bricks[61])
				MoveObjectLocalY(rings[12],0.08)
				SetObjectCollisionMode(rings[12],0)
				rings_amount=12
				
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		 drones[1]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[1],bricks[31])
			MoveObjectLocalY(drones[1],0.08)
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
			
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocalY(drone_test_under[1],-0.08)
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)
				SetObjectVisible(drone_test_under[1],0)
		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=1//rotatex -90
		 drone_turn[1,2]=2//rotatey -90
		 drone_turn[1,3]=2//rotatey -90
		 drone_turn[1,4]=1//rotatex -90
		 drone_turn[1,5]=2
		 drone_turn[1,6]=2
		 
		 drone_maker[1,1]=26
		 drone_maker[1,2]=19	
		 drone_maker[1,3]=13
         drone_maker[1,4]=8
		 drone_maker[1,5]=1
		 drone_maker[1,6]=31
		 
			
drones[2]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[2],bricks[55])
			MoveObjectLocalY(drones[2],0.08)
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocalY(drone_test_under[2],-0.08)
			
			
				
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)
				SetObjectVisible(drone_test_under[2],0)
		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[2,1]=2
		 drone_turn[2,2]=2
		 drone_turn[2,3]=2
		 drone_turn[2,4]=2
		 drone_turn[2,5]=2
		 
		 drone_maker[2,1]=49
		 drone_maker[2,2]=43	
		 drone_maker[2,3]=37
         drone_maker[2,4]=55
		

drones[3]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[3],bricks[79])
			RotateObjectLocaly(drones[3],180)
			MoveObjectLocalY(drones[3],0.08)
			
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocalY(drone_test_under[3],-0.08)
			
			
				
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)
				SetObjectVisible(drone_test_under[3],0)
		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[3,1]=1
		 drone_turn[3,2]=3
		 drone_turn[3,3]=3
		 drone_turn[3,4]=1
		 drone_turn[3,5]=3
		 drone_turn[3,6]=3
		 
		 drone_maker[3,1]=74
		 drone_maker[3,2]=67	
		 drone_maker[3,3]=61
         drone_maker[3,4]=92
         drone_maker[3,5]=85
         drone_maker[3,6]=79
         
			drone_amount=3
			
			
			
			for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to 3
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
			
			PlayMusic(music,1)
			SetObjectVisible(pivot,0)
			
endfunction






function level2()
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music2.mp3")
pick_up=0


texture_1=LoadImage("\media\textures\tex1.png") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy

brick=0	
	
		opentoread(1,"\media\data\Level2.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.001,32,32)	
		SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],-0.08*14)
						MoveObjectLocaly(bricks[t],-0.08*4)
						next

		
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[75])
				MoveObjectLocalY(me,0.08)
				
				
				
				
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				

				
				rings[1]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[1],0.04,0.04,0.04)
				FixObjectToObject(rings[1],bricks[19])
				MoveObjectLocalY(rings[1],0.08)
				SetObjectCollisionMode(rings[1],0)
				
				rings[2]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[2],0.04,0.04,0.04)
				FixObjectToObject(rings[2],bricks[13])
				MoveObjectLocalY(rings[2],0.08)
				SetObjectCollisionMode(rings[2],0)
				
				
				rings[3]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[3],0.04,0.04,0.04)
				FixObjectToObject(rings[3],bricks[7])
				MoveObjectLocalY(rings[3],0.08)
				SetObjectCollisionMode(rings[3],0)
				
				
				rings[4]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[4],0.04,0.04,0.04)
				FixObjectToObject(rings[4],bricks[1])
				MoveObjectLocalY(rings[4],0.08)
				SetObjectCollisionMode(rings[4],0)
				
				
				rings[5]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[5],0.04,0.04,0.04)
				FixObjectToObject(rings[5],bricks[25])
				MoveObjectLocalY(rings[5],0.08)
				SetObjectCollisionMode(rings[5],0)
				
				rings[6]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[6],0.04,0.04,0.04)
				FixObjectToObject(rings[6],bricks[31])
				MoveObjectLocalY(rings[6],0.08)
				SetObjectCollisionMode(rings[6],0)
				
				
				rings[7]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[7],0.04,0.04,0.04)
				FixObjectToObject(rings[7],bricks[37])
				MoveObjectLocalY(rings[7],0.08)
				SetObjectCollisionMode(rings[7],0)
				
				rings[8]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[8],0.04,0.04,0.04)
				FixObjectToObject(rings[8],bricks[43])
				MoveObjectLocalY(rings[8],0.08)
				SetObjectCollisionMode(rings[8],0)
				
				
				rings[9]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[9],0.04,0.04,0.04)
				FixObjectToObject(rings[9],bricks[67])
				MoveObjectLocalY(rings[9],0.08)
				SetObjectCollisionMode(rings[9],0)
				
				rings[10]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[10],0.04,0.04,0.04)
				FixObjectToObject(rings[10],bricks[61])
				MoveObjectLocalY(rings[10],0.08)
				SetObjectCollisionMode(rings[10],0)
				
				
				rings[11]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[11],0.04,0.04,0.04)
				FixObjectToObject(rings[11],bricks[55])
				MoveObjectLocalY(rings[11],0.08)
				SetObjectCollisionMode(rings[11],0)
				
				rings[12]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[12],0.04,0.04,0.04)
				FixObjectToObject(rings[12],bricks[49])
				MoveObjectLocalY(rings[12],0.08)
				SetObjectCollisionMode(rings[12],0)
				rings_amount=12
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		 drones[1]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[1],bricks[19])
			MoveObjectLocalY(drones[1],0.08)
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocalY(drone_test_under[1],-0.08)
			
				
				
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=2//rotatex -90
		 drone_turn[1,2]=2//rotatey -90
		 drone_turn[1,3]=2//rotatey -90
		 drone_turn[1,4]=2//rotatex -90
		
		 
		 drone_maker[1,1]=13
		 drone_maker[1,2]=7	
		 drone_maker[1,3]=1
         drone_maker[1,4]=19
		 
		 
			
drones[2]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[2],bricks[25])
			MoveObjectLocalY(drones[2],0.08)
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
			
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocalY(drone_test_under[2],-0.08)
			
				
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[2,1]=3
		 drone_turn[2,2]=3
		 drone_turn[2,3]=3
		 drone_turn[2,4]=3
		
		 
		 drone_maker[2,1]=31
		 drone_maker[2,2]=37	
		 drone_maker[2,3]=43
         drone_maker[2,4]=25
		

drones[3]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[3],bricks[67])
			
			MoveObjectLocalY(drones[3],0.08)
		
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
			
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocalY(drone_test_under[3],-0.08)
			
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[3,1]=2
		 drone_turn[3,2]=2
		 drone_turn[3,3]=2
		 drone_turn[3,4]=2
	
		 
		 drone_maker[3,1]=61
		 drone_maker[3,2]=55	
		 drone_maker[3,3]=49
         drone_maker[3,4]=67
       
         
         drone_amount=3
         
			
			for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
				
				PlayMusic(music,1)
				SetObjectVisible(pivot,0)
endfunction



function level3()
	
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music3.mp3")
	
	pick_up=0
texture_1=LoadImage("\media\textures\tex1.png") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy
brick=0	
	
		opentoread(1,"\media\data\Level3.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
						SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],-0.08*4)
						MoveObjectLocaly(bricks[t],0.08*7)
						next

		
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[102])
				MoveObjectLocalY(me,0.08)
				
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				rings[1]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[1],0.04,0.04,0.04)
				FixObjectToObject(rings[1],bricks[19])
				MoveObjectLocalY(rings[1],0.08)
				SetObjectCollisionMode(rings[1],0)
				
				rings[2]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[2],0.04,0.04,0.04)
				FixObjectToObject(rings[2],bricks[13])
				MoveObjectLocalY(rings[2],0.08)
				SetObjectCollisionMode(rings[2],0)
				
				
				rings[3]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[3],0.04,0.04,0.04)
				FixObjectToObject(rings[3],bricks[7])
				MoveObjectLocalY(rings[3],0.08)
				SetObjectCollisionMode(rings[3],0)
				
				
				rings[4]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[4],0.04,0.04,0.04)
				FixObjectToObject(rings[4],bricks[1])
				MoveObjectLocalY(rings[4],0.08)
				SetObjectCollisionMode(rings[4],0)
				
				
				rings[5]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[5],0.04,0.04,0.04)
				FixObjectToObject(rings[5],bricks[25])
				MoveObjectLocalY(rings[5],0.08)
				SetObjectCollisionMode(rings[5],0)
				
				rings[6]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[6],0.04,0.04,0.04)
				FixObjectToObject(rings[6],bricks[31])
				MoveObjectLocalY(rings[6],0.08)
				SetObjectCollisionMode(rings[6],0)
				
				
				rings[7]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[7],0.04,0.04,0.04)
				FixObjectToObject(rings[7],bricks[37])
				MoveObjectLocalY(rings[7],0.08)
				SetObjectCollisionMode(rings[7],0)
				
				rings[8]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[8],0.04,0.04,0.04)
				FixObjectToObject(rings[8],bricks[43])
				MoveObjectLocalY(rings[8],0.08)
				SetObjectCollisionMode(rings[8],0)
				
				
				rings[9]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[9],0.04,0.04,0.04)
				FixObjectToObject(rings[9],bricks[67])
				MoveObjectLocalY(rings[9],0.08)
				SetObjectCollisionMode(rings[9],0)
				
				rings[10]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[10],0.04,0.04,0.04)
				FixObjectToObject(rings[10],bricks[61])
				MoveObjectLocalY(rings[10],0.08)
				SetObjectCollisionMode(rings[10],0)
				
				
				rings[11]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[11],0.04,0.04,0.04)
				FixObjectToObject(rings[11],bricks[55])
				MoveObjectLocalY(rings[11],0.08)
				SetObjectCollisionMode(rings[11],0)
				
				rings[12]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[12],0.04,0.04,0.04)
				FixObjectToObject(rings[12],bricks[49])
				MoveObjectLocalY(rings[12],0.08)
				SetObjectCollisionMode(rings[12],0)
				
				
				
				
				rings[13]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[13],0.04,0.04,0.04)
				FixObjectToObject(rings[13],bricks[73])
				MoveObjectLocalY(rings[13],0.08)
				SetObjectCollisionMode(rings[13],0)
				
				rings[14]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[14],0.04,0.04,0.04)
				FixObjectToObject(rings[14],bricks[91])
				MoveObjectLocalY(rings[14],0.08)
				SetObjectCollisionMode(rings[14],0)
				
				rings[15]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[15],0.04,0.04,0.04)
				FixObjectToObject(rings[15],bricks[85])
				MoveObjectLocalY(rings[15],0.08)
				SetObjectCollisionMode(rings[15],0)
				
				rings[16]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[16],0.04,0.04,0.04)
				FixObjectToObject(rings[16],bricks[79])
				MoveObjectLocalY(rings[16],0.08)
				SetObjectCollisionMode(rings[16],0)
				rings_amount=16
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		 drones[1]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[1],bricks[73])
			MoveObjectLocalY(drones[1],0.08)
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocalY(drone_test_under[1],-0.08)
			
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=3//rotatex -90
		 drone_turn[1,2]=3//rotatey -90
		 drone_turn[1,3]=3//rotatey -90
		 drone_turn[1,4]=3//rotatex -90
		
		 
		 drone_maker[1,1]=91
		 drone_maker[1,2]=85	
		 drone_maker[1,3]=79
         drone_maker[1,4]=73
		 
		 
			
drones[2]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[2],bricks[55])
			MoveObjectLocalY(drones[2],0.08)
	
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocalY(drone_test_under[2],-0.08)
			
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[2,1]=2
		 drone_turn[2,2]=2
		 drone_turn[2,3]=2
		 drone_turn[2,4]=2
		
		 
		 drone_maker[2,1]=61
		 drone_maker[2,2]=67	
		 drone_maker[2,3]=49
         drone_maker[2,4]=55
		

		drones[3]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[3],bricks[25])
			
			MoveObjectLocalY(drones[3],0.08)
		
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocalY(drone_test_under[3],-0.08)
			
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[3,1]=3
		 drone_turn[3,2]=3
		 drone_turn[3,3]=3
		 drone_turn[3,4]=3
	
		 
		 drone_maker[3,1]=43
		 drone_maker[3,2]=37	
		 drone_maker[3,3]=31
         drone_maker[3,4]=25
     
         
         
       drones[4]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[4],bricks[7])
			
			MoveObjectLocalY(drones[4],0.08)
		
			
				drone_test_under[4]=createobjectbox(0.08,0.08,0.08)
			
				FixObjectToObject(drone_test_under[4],drones[4])
				MoveObjectLocalY(drone_test_under[4],-0.08)
			
				SetObjectCollisionMode(drone_test_under[4],0)
				SetObjectCollisionMode(drones[4],0)

		 
		 drone_time[4]=0
		 
		 drone_move[4]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[4,1]=2
		 drone_turn[4,2]=2
		 drone_turn[4,3]=2
		 drone_turn[4,4]=2
	
		 
		 drone_maker[4,1]=13
		 drone_maker[4,2]=19	
		 drone_maker[4,3]=1
         drone_maker[4,4]=7
         
         
         
         drone_amount=4
			for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
				PlayMusic(music,1)
				SetObjectVisible(pivot,0)
endfunction




function level4()
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music4.mp3")
pick_up=0

texture_1=LoadImage("\media\textures\tex1.png") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy

brick=0	
	
		opentoread(1,"\media\data\Level4.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
		SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],-0.08*4)
						MoveObjectLocaly(bricks[t],-0.08*3)
						next

		
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[145])
				MoveObjectLocalY(me,0.08)
				
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				
				
				
				
				
				
				
				
				
				
				rings[1]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[1],0.04,0.04,0.04)
				FixObjectToObject(rings[1],bricks[19])
				MoveObjectLocalY(rings[1],0.08)
				SetObjectCollisionMode(rings[1],0)
				
				rings[2]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[2],0.04,0.04,0.04)
				FixObjectToObject(rings[2],bricks[13])
				MoveObjectLocalY(rings[2],0.08)
				SetObjectCollisionMode(rings[2],0)
				
				
				rings[3]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[3],0.04,0.04,0.04)
				FixObjectToObject(rings[3],bricks[7])
				MoveObjectLocalY(rings[3],0.08)
				SetObjectCollisionMode(rings[3],0)
				
				
				rings[4]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[4],0.04,0.04,0.04)
				FixObjectToObject(rings[4],bricks[1])
				MoveObjectLocalY(rings[4],0.08)
				SetObjectCollisionMode(rings[4],0)
				
				
				rings[5]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[5],0.04,0.04,0.04)
				FixObjectToObject(rings[5],bricks[109])
				MoveObjectLocalY(rings[5],0.08)
				SetObjectCollisionMode(rings[5],0)
				
				rings[6]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[6],0.04,0.04,0.04)
				FixObjectToObject(rings[6],bricks[103])
				MoveObjectLocalY(rings[6],0.08)
				SetObjectCollisionMode(rings[6],0)
				
				
				rings[7]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[7],0.04,0.04,0.04)
				FixObjectToObject(rings[7],bricks[97])
				MoveObjectLocalY(rings[7],0.08)
				SetObjectCollisionMode(rings[7],0)
				
				rings[8]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[8],0.04,0.04,0.04)
				FixObjectToObject(rings[8],bricks[115])
				MoveObjectLocalY(rings[8],0.08)
				SetObjectCollisionMode(rings[8],0)
				
				
				rings[9]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[9],0.04,0.04,0.04)
				FixObjectToObject(rings[9],bricks[67])
				MoveObjectLocalY(rings[9],0.08)
				SetObjectCollisionMode(rings[9],0)
				
				rings[10]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[10],0.04,0.04,0.04)
				FixObjectToObject(rings[10],bricks[61])
				MoveObjectLocalY(rings[10],0.08)
				SetObjectCollisionMode(rings[10],0)
				
				
				rings[11]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[11],0.04,0.04,0.04)
				FixObjectToObject(rings[11],bricks[55])
				MoveObjectLocalY(rings[11],0.08)
				SetObjectCollisionMode(rings[11],0)
				
				rings[12]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[12],0.04,0.04,0.04)
				FixObjectToObject(rings[12],bricks[49])
				MoveObjectLocalY(rings[12],0.08)
				SetObjectCollisionMode(rings[12],0)
				
				
				
				
				rings[13]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[13],0.04,0.04,0.04)
				FixObjectToObject(rings[13],bricks[73])
				MoveObjectLocalY(rings[13],0.08)
				SetObjectCollisionMode(rings[13],0)
				
				rings[14]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[14],0.04,0.04,0.04)
				FixObjectToObject(rings[14],bricks[91])
				MoveObjectLocalY(rings[14],0.08)
				SetObjectCollisionMode(rings[14],0)
				
				rings[15]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[15],0.04,0.04,0.04)
				FixObjectToObject(rings[15],bricks[85])
				MoveObjectLocalY(rings[15],0.08)
				SetObjectCollisionMode(rings[15],0)
				
				rings[16]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[16],0.04,0.04,0.04)
				FixObjectToObject(rings[16],bricks[79])
				MoveObjectLocalY(rings[16],0.08)
				SetObjectCollisionMode(rings[16],0)
			
			
				rings[17]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[17],0.04,0.04,0.04)
				FixObjectToObject(rings[17],bricks[139])
				MoveObjectLocalY(rings[17],0.08)
				SetObjectCollisionMode(rings[17],0)
				
				rings[18]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[18],0.04,0.04,0.04)
				FixObjectToObject(rings[18],bricks[121])
				MoveObjectLocalY(rings[18],0.08)
				SetObjectCollisionMode(rings[18],0)
				
				rings[19]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[19],0.04,0.04,0.04)
				FixObjectToObject(rings[19],bricks[127])
				MoveObjectLocalY(rings[19],0.08)
				SetObjectCollisionMode(rings[19],0)
				
				rings[20]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[20],0.04,0.04,0.04)
				FixObjectToObject(rings[20],bricks[133])
				MoveObjectLocalY(rings[20],0.08)
				SetObjectCollisionMode(rings[20],0)
			
			
			rings_amount=20
			
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		 drones[1]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[1],bricks[73])
			MoveObjectLocalY(drones[1],0.08)
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocalY(drone_test_under[1],-0.08)
			
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=3//rotatex -90
		 drone_turn[1,2]=3//rotatey -90
		 drone_turn[1,3]=3//rotatey -90
		 drone_turn[1,4]=3//rotatex -90
		
		 
		 drone_maker[1,1]=91
		 drone_maker[1,2]=85	
		 drone_maker[1,3]=79
         drone_maker[1,4]=73
		 
		 
		   drones[2]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[2],bricks[7])
			
			MoveObjectLocalY(drones[2],0.08)
		
		
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocalY(drone_test_under[2],-0.08)
			
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[4],0)

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[2,1]=2
		 drone_turn[2,2]=2
		 drone_turn[2,3]=2
		 drone_turn[2,4]=2
	
		 
		 drone_maker[2,1]=13
		 drone_maker[2,2]=19	
		 drone_maker[2,3]=1
         drone_maker[2,4]=7
		 
		 
		 
		 
		 
		 
			
drones[3]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[3],bricks[109])
			MoveObjectLocalY(drones[3],0.08)
		
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
			
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocalY(drone_test_under[3],-0.08)
			
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[3,1]=2
		 drone_turn[3,2]=2
		 drone_turn[3,3]=2
		 drone_turn[3,4]=2
		
		 
		 drone_maker[3,1]=103
		 drone_maker[3,2]=97	
		 drone_maker[3,3]=115
         drone_maker[3,4]=109
		

		drones[4]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[4],bricks[49])
			
			MoveObjectLocalY(drones[4],0.08)
		
				drone_test_under[4]=createobjectbox(0.08,0.08,0.08)
			
				FixObjectToObject(drone_test_under[4],drones[4])
				MoveObjectLocalY(drone_test_under[4],-0.08)
			
			
				SetObjectCollisionMode(drone_test_under[4],0)
				SetObjectCollisionMode(drones[4],0)

		 
		 drone_time[4]=0
		 
		 drone_move[4]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[4,1]=2
		 drone_turn[4,2]=2
		 drone_turn[4,3]=2
		 drone_turn[4,4]=2
	
		 
		 drone_maker[4,1]=55
		 drone_maker[4,2]=61	
		 drone_maker[4,3]=67
         drone_maker[4,4]=49
     
        drones[5]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[5],bricks[139])
			
			MoveObjectLocalY(drones[5],0.08)
		
				drone_test_under[5]=createobjectbox(0.08,0.08,0.08)
			
				FixObjectToObject(drone_test_under[5],drones[5])
				MoveObjectLocalY(drone_test_under[5],-0.08)
			
				
				SetObjectCollisionMode(drone_test_under[5],0)
				SetObjectCollisionMode(drones[5],0)

		 
		 drone_time[5]=0
		 
		 drone_move[5]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[5,1]=2
		 drone_turn[5,2]=2
		 drone_turn[5,3]=2
		 drone_turn[5,4]=2
	
		 
		 drone_maker[5,1]=121
		 drone_maker[5,2]=127	
		 drone_maker[5,3]=133
         drone_maker[5,4]=139
         
     
         
         drone_amount=5
         
         for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
			PlayMusic(music,1)
			SetObjectVisible(pivot,0)
endfunction





function level5()
	
if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music5.mp3")
pick_up=0
texture_1=LoadImage("\media\textures\tex1.png") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy

brick=0	
	
		opentoread(1,"\media\data\Level5.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
		SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						//MoveObjectLocalX(bricks[t],0.08*1)
						MoveObjectLocalz(bricks[t],0.08*2)
						MoveObjectLocaly(bricks[t],0.08*3)
						next

		
				
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[97])
				MoveObjectLocalY(me,0.08)
				
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)

				rings[1]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[1],0.04,0.04,0.04)
				FixObjectToObject(rings[1],bricks[49])
				MoveObjectLocalz(rings[1],0.08)
				SetObjectCollisionMode(rings[1],0)
				
				rings[2]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[2],0.04,0.04,0.04)
				FixObjectToObject(rings[2],bricks[55])
				MoveObjectLocalz(rings[2],0.08)
				SetObjectCollisionMode(rings[2],0)
				
				
				rings[3]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[3],0.04,0.04,0.04)
				FixObjectToObject(rings[3],bricks[61])
				MoveObjectLocalz(rings[3],0.08)
				SetObjectCollisionMode(rings[3],0)
				
				
				rings[4]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[4],0.04,0.04,0.04)
				FixObjectToObject(rings[4],bricks[67])
				MoveObjectLocalz(rings[4],0.08)
				SetObjectCollisionMode(rings[4],0)
				
				
				rings[5]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[5],0.04,0.04,0.04)
				FixObjectToObject(rings[5],bricks[73])
				MoveObjectLocalz(rings[5], -0.08)
				SetObjectCollisionMode(rings[5],0)
				
				rings[6]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[6],0.04,0.04,0.04)
				FixObjectToObject(rings[6],bricks[79])
				MoveObjectLocalz(rings[6],-0.08)
				SetObjectCollisionMode(rings[6],0)
				
				
				rings[7]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[7],0.04,0.04,0.04)
				FixObjectToObject(rings[7],bricks[85])
				MoveObjectLocalz(rings[7],-0.08)
				SetObjectCollisionMode(rings[7],0)
				
				
				rings[8]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[8],0.04,0.04,0.04)
				FixObjectToObject(rings[8],bricks[91])
				MoveObjectLocalz(rings[8],-0.08)
				SetObjectCollisionMode(rings[8],0)
			
			////////////////////////////////////////////////////////////////////////////////////////////////////////////
			rings[9]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[9],0.04,0.04,0.04)
				FixObjectToObject(rings[9],bricks[1])
				MoveObjectLocalx(rings[9], 0.08)
				SetObjectCollisionMode(rings[9],0)
				
				rings[10]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[10],0.04,0.04,0.04)
				FixObjectToObject(rings[10],bricks[7])
				MoveObjectLocalx(rings[10],0.08)
				SetObjectCollisionMode(rings[10],0)
				
				
				rings[11]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[11],0.04,0.04,0.04)
				FixObjectToObject(rings[11],bricks[13])
				MoveObjectLocalx(rings[11],0.08)
				SetObjectCollisionMode(rings[11],0)
				
				
				rings[12]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[12],0.04,0.04,0.04)
				FixObjectToObject(rings[12],bricks[19])
				MoveObjectLocalx(rings[12],0.08)
				SetObjectCollisionMode(rings[12],0)
				
				
				
				
				
				rings[13]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[13],0.04,0.04,0.04)
				FixObjectToObject(rings[13],bricks[25])
				MoveObjectLocalx(rings[13],- 0.08)
				SetObjectCollisionMode(rings[13],0)
				
				rings[14]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[14],0.04,0.04,0.04)
				FixObjectToObject(rings[14],bricks[31])
				MoveObjectLocalx(rings[14],-0.08)
				SetObjectCollisionMode(rings[14],0)
				
				
				rings[15]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[15],0.04,0.04,0.04)
				FixObjectToObject(rings[15],bricks[37])
				MoveObjectLocalx(rings[15],-0.08)
				SetObjectCollisionMode(rings[15],0)
				
				
				rings[16]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[16],0.04,0.04,0.04)
				FixObjectToObject(rings[16],bricks[43])
				MoveObjectLocalx(rings[16],-0.08)
				SetObjectCollisionMode(rings[16],0)
				
				
			rings_amount=16
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		 drones[1]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[1],bricks[19])
			
			MoveObjectLocalx(drones[1],0.08)
			RotateObjectLocalz(drones[1],-90)
			
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocaly(drone_test_under[1],-0.08)
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)
				

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=2//rotatex -90
		 drone_turn[1,2]=2//rotatey -90
		 drone_turn[1,3]=2//rotatey -90
		 drone_turn[1,4]=2//rotatex -90
		
		 
		 drone_maker[1,1]=13
		 drone_maker[1,2]=7
		 drone_maker[1,3]=1
         drone_maker[1,4]=19
		 
		 
		 

	
drones[2]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[2],bricks[31])
			MoveObjectLocalx(drones[2],-0.08)
			RotateObjectLocalz(drones[2],90)
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocalY(drone_test_under[2],-0.08)
			
		
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[2,1]=2
		 drone_turn[2,2]=2
		 drone_turn[2,3]=2
		 drone_turn[2,4]=2
		
		 
		 drone_maker[2,1]=25
		 drone_maker[2,2]=43	
		 drone_maker[2,3]=37
         drone_maker[2,4]=31
		



drones[3]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[3],bricks[55])
			MoveObjectLocalz(drones[3],0.08)
			RotateObjectLocalx(drones[3],90)
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocalY(drone_test_under[3],-0.08)
			
		
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[3,1]=3
		 drone_turn[3,2]=3
		 drone_turn[3,3]=3
		 drone_turn[3,4]=3
		
		 
		 drone_maker[3,1]=61
		 drone_maker[3,2]=67	
		 drone_maker[3,3]=49
         drone_maker[3,4]=55

    
     drones[4]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[4],bricks[73])
			MoveObjectLocalz(drones[4],-0.08)
			RotateObjectLocalx(drones[4],-90)
			RotateObjectLocaly(drones[4],90)
				drone_test_under[4]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[4],drones[4])
				MoveObjectLocalY(drone_test_under[4],-0.08)
			
		
				SetObjectCollisionMode(drone_test_under[4],0)
				SetObjectCollisionMode(drones[4],0)

		 
		 drone_time[4]=0
		 
		 drone_move[4]=1
		 //1//rotatex -90
		 //2//rotatey -90
		
		 drone_turn[4,1]=3
		 drone_turn[4,2]=3
		 drone_turn[4,3]=3
		 drone_turn[4,4]=3
		
		 
		 drone_maker[4,1]=79
		 drone_maker[4,2]=85	
		 drone_maker[4,3]=91
         drone_maker[4,4]=73   
   drone_amount=4
   
   for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
   PlayMusic(music,1)
   SetObjectVisible(pivot,0)
endfunction








function level6()
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music6.mp3")
pick_up=0
texture_1=LoadImage("\media\textures\tex1.png") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy

brick=0	
	
		opentoread(1,"\media\data\Level6.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
		SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],0.08*5)
						MoveObjectLocalz(bricks[t],-0.08*3)
						//MoveObjectLocaly(bricks[t],0.08*3)
						next

		
				
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[97])
				MoveObjectLocalY(me,0.08)
				
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				
				
				
				
				
				
				
				
				
				rings[1]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[1],0.04,0.04,0.04)
				FixObjectToObject(rings[1],bricks[1])
				MoveObjectLocalY(rings[1],0.08)
				SetObjectCollisionMode(rings[1],0)
				
				
				rings[2]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[2],0.04,0.04,0.04)
				
				
				FixObjectToObject(rings[2],bricks[19])
				MoveObjectLocalY(rings[2],0.08)
				SetObjectCollisionMode(rings[2],0)
				
				
				rings[3]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[3],0.04,0.04,0.04)
				FixObjectToObject(rings[3],bricks[13])
				MoveObjectLocalY(rings[3],0.08)
				SetObjectCollisionMode(rings[3],0)
				
				
				rings[4]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[4],0.04,0.04,0.04)
				FixObjectToObject(rings[4],bricks[7])
				MoveObjectLocalY(rings[4],0.08)
				SetObjectCollisionMode(rings[4],0)
			
			rings[5]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[5],0.04,0.04,0.04)
				FixObjectToObject(rings[5],bricks[73])
				MoveObjectLocalY(rings[5],0.08)
				SetObjectCollisionMode(rings[5],0)
				
				
				rings[6]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[6],0.04,0.04,0.04)
				
				
				FixObjectToObject(rings[6],bricks[91])
				MoveObjectLocalY(rings[6],0.08)
				SetObjectCollisionMode(rings[6],0)
				
				
				rings[7]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[7],0.04,0.04,0.04)
				FixObjectToObject(rings[7],bricks[85])
				MoveObjectLocalY(rings[7],0.08)
				SetObjectCollisionMode(rings[7],0)
				
				
				rings[8]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[8],0.04,0.04,0.04)
				FixObjectToObject(rings[8],bricks[79])
				MoveObjectLocalY(rings[8],0.08)
				SetObjectCollisionMode(rings[8],0)
			
			
			
			rings[9]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[9],0.04,0.04,0.04)
				FixObjectToObject(rings[9],bricks[25])
				MoveObjectLocalY(rings[9],0.08)
				SetObjectCollisionMode(rings[9],0)
				
				
				rings[10]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[10],0.04,0.04,0.04)
				
				
				FixObjectToObject(rings[10],bricks[43])
				MoveObjectLocalY(rings[10],0.08)
				SetObjectCollisionMode(rings[10],0)
				
				
				rings[11]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[11],0.04,0.04,0.04)
				FixObjectToObject(rings[11],bricks[37])
				MoveObjectLocalY(rings[11],0.08)
				SetObjectCollisionMode(rings[11],0)
				
				
				rings[12]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[12],0.04,0.04,0.04)
				FixObjectToObject(rings[12],bricks[31])
				MoveObjectLocalY(rings[12],0.08)
				SetObjectCollisionMode(rings[12],0)
			
			
			
			rings[13]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[13],0.04,0.04,0.04)
				FixObjectToObject(rings[13],bricks[49])
				MoveObjectLocalY(rings[13],0.08)
				SetObjectCollisionMode(rings[13],0)
				
				
				rings[14]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[14],0.04,0.04,0.04)
				
				
				FixObjectToObject(rings[14],bricks[67])
				MoveObjectLocalY(rings[14],0.08)
				SetObjectCollisionMode(rings[14],0)
				
				
				rings[15]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[15],0.04,0.04,0.04)
				FixObjectToObject(rings[15],bricks[61])
				MoveObjectLocalY(rings[15],0.08)
				SetObjectCollisionMode(rings[15],0)
				
				
				rings[16]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[16],0.04,0.04,0.04)
				FixObjectToObject(rings[16],bricks[55])
				MoveObjectLocalY(rings[16],0.08)
				SetObjectCollisionMode(rings[16],0)
			
			
			rings_amount=16
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		 drones[1]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[1],bricks[1])
			
			MoveObjectLocaly(drones[1],0.08)
		
			
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocaly(drone_test_under[1],-0.08)
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)
				

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=3//rotatex -90
		 drone_turn[1,2]=3//rotatey -90
		 drone_turn[1,3]=3//rotatey -90
		 drone_turn[1,4]=3//rotatex -90
		
		 
		 drone_maker[1,1]=19
		 drone_maker[1,2]=13
		 drone_maker[1,3]=7
         drone_maker[1,4]=1
		 
		 
		 

		 
		 
drones[2]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[2],bricks[73])
			
			MoveObjectLocaly(drones[2],0.08)
		
			
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocaly(drone_test_under[2],-0.08)
			SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)
				

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 drone_turn[2,1]=3//rotatex -90
		 drone_turn[2,2]=3//rotatey -90
		 drone_turn[2,3]=3//rotatey -90
		 drone_turn[2,4]=3//rotatex -90
		
		 
		 drone_maker[2,1]=91
		 drone_maker[2,2]=85
		 drone_maker[2,3]=79
         drone_maker[2,4]=73
		


drones[3]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[3],bricks[25])
			
			MoveObjectLocaly(drones[3],0.08)
		
			
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocaly(drone_test_under[3],-0.08)
			SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)
				

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 drone_turn[3,1]=3//rotatex -90
		 drone_turn[3,2]=3//rotatey -90
		 drone_turn[3,3]=3//rotatey -90
		 drone_turn[3,4]=3//rotatex -90
		
		 
		 drone_maker[3,1]=43
		 drone_maker[3,2]=37
		 drone_maker[3,3]=31
         drone_maker[3,4]=25


  
	
    
drones[4]=createobjectsphere(0.01,32,32)
			FixObjectToObject(drones[4],bricks[49])
			
			MoveObjectLocaly(drones[4],0.08)
		
			
			
				drone_test_under[4]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[4],drones[4])
				MoveObjectLocaly(drone_test_under[4],-0.08)
			SetObjectCollisionMode(drone_test_under[4],0)
				SetObjectCollisionMode(drones[4],0)
				

		 
		 drone_time[4]=0	 
		 drone_move[4]=1
		 drone_turn[4,1]=3//rotatex -90
		 drone_turn[4,2]=3//rotatey -90
		 drone_turn[4,3]=3//rotatey -90
		 drone_turn[4,4]=3//rotatex -90
		
		 
		 drone_maker[4,1]=67
		 drone_maker[4,2]=61
		 drone_maker[4,3]=55
         drone_maker[4,4]=49
    
    drone_amount=4
    
         for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
		PlayMusic(music,1)
		SetObjectVisible(pivot,0)
endfunction




function level7()
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music7.mp3")
pick_up=0
texture_1=LoadImage("\media\textures\tex1.png") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy

brick=0	
	
		opentoread(1,"\media\data\Level7.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
						SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],0.08*3)
						MoveObjectLocaly(bricks[t],-0.08*7)
						next

		RotateObjectLocalY(pivot,180)
				
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[93])
				MoveObjectLocalY(me,0.08)
				RotateObjectLocalY(me,180)
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				
				
				
				
				
				
				
				
				
				for t=1 to 8
				rings[t]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[t],0.04,0.04,0.04)
				
				
				SetObjectCollisionMode(rings[t],0)
				
				next
			
			FixObjectToObject(rings[1],bricks[7])
			FixObjectToObject(rings[2],bricks[30])
			FixObjectToObject(rings[3],bricks[64])
			FixObjectToObject(rings[4],bricks[87])
			FixObjectToObject(rings[5],bricks[81])
			FixObjectToObject(rings[6],bricks[70])
			FixObjectToObject(rings[7],bricks[36])
			FixObjectToObject(rings[8],bricks[13])
			
			
			
			
			for t=1 to 8
			
			MoveObjectLocalY(rings[t],0.08)
			next
			rings_amount=8
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		
		
		
		drones[1]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[1],bricks[13])
			
		MoveObjectLocaly(drones[1],0.08)
		RotateObjectLocalY(drones[1],180)
			
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocaly(drone_test_under[1],-0.08)
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)
				

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=1//rotatex -90
		 drone_turn[1,2]=3//rotatey -90
		 drone_turn[1,3]=3//rotatey -90
		 drone_turn[1,4]=1//rotatex -90
			drone_turn[1,5]=3//rotatex -90
			
		 drone_turn[1,6]=3//rotatex -90
		 
		 drone_maker[1,1]=18
		 drone_maker[1,2]=36
		 drone_maker[1,3]=30
         drone_maker[1,4]=25
         drone_maker[1,5]=7
         drone_maker[1,6]=13
         
		 
		 
		drones[2]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[2],bricks[36])
			
		MoveObjectLocaly(drones[2],0.08)
		RotateObjectLocalY(drones[2],180)
			
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocaly(drone_test_under[2],-0.08)
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)
				

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 drone_turn[2,1]=1//rotatex -90
		 drone_turn[2,2]=3//rotatey -90
		 drone_turn[2,3]=3//rotatey -90
		 drone_turn[2,4]=1//rotatex -90
			drone_turn[2,5]=3//rotatex -90
			
		 drone_turn[2,6]=3//rotatex -90
		 
		 drone_maker[2,1]=46
		 drone_maker[2,2]=70
		 drone_maker[2,3]=64
         drone_maker[2,4]=59
         drone_maker[2,5]=30
         drone_maker[2,6]=36

		 
		drones[3]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[3],bricks[70])
			
		MoveObjectLocaly(drones[3],0.08)
		RotateObjectLocalY(drones[3],180)
			
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocaly(drone_test_under[3],-0.08)
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)
				

		 
		 drone_time[3]=0
		 drone_move[3]=1
		 drone_turn[3,1]=3//rotatex -90
		 drone_turn[3,2]=3//rotatey -90
		 drone_turn[3,3]=3//rotatey -90
		 drone_turn[3,4]=3//rotatex -90
		
		 
		 drone_maker[3,1]=81
		 drone_maker[3,2]=87
		 drone_maker[3,3]=64
         drone_maker[3,4]=70




  
	
    drone_amount=3
    
    for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
        
		PlayMusic(music,1)
		SetObjectVisible(pivot,0)
endfunction






function level8()
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music8.mp3")
pick_up=0
texture_1=LoadImage("\media\textures\tex1.png") /// bricks
texture_2=LoadImage("\media\textures\tex2.png") /// my balll
texture_4=LoadImage("\media\textures\tex3.png") // bad guy

brick=0	
	
		opentoread(1,"\media\data\Level8.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
						SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],-0.08*3)
						MoveObjectLocaly(bricks[t],-0.08*5)
						next

		RotateObjectLocalY(pivot,180)
				
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[148])
				MoveObjectLocalY(me,0.08)
				RotateObjectLocalY(me,180)
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				
				
				
				
				
				
				
				
				for t=1 to 24
				rings[t]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[t],0.04,0.04,0.04)
				
				
				SetObjectCollisionMode(rings[t],0)
				
				next
			
			
			FixObjectToObject(rings[1],bricks[91])
			FixObjectToObject(rings[2],bricks[73])
			FixObjectToObject(rings[3],bricks[79])
			FixObjectToObject(rings[4],bricks[85])
			
			FixObjectToObject(rings[5],bricks[37])
			FixObjectToObject(rings[6],bricks[31])
			FixObjectToObject(rings[7],bricks[25])
			FixObjectToObject(rings[8],bricks[43])
			
			
			FixObjectToObject(rings[9],bricks[115])
			FixObjectToObject(rings[10],bricks[109])
			FixObjectToObject(rings[11],bricks[103])
			FixObjectToObject(rings[12],bricks[97])
			
			FixObjectToObject(rings[13],bricks[121])
			FixObjectToObject(rings[14],bricks[139])
			FixObjectToObject(rings[15],bricks[133])
			FixObjectToObject(rings[16],bricks[127])
			
			FixObjectToObject(rings[17],bricks[13])
			FixObjectToObject(rings[18],bricks[19])
			FixObjectToObject(rings[19],bricks[1])
			FixObjectToObject(rings[20],bricks[7])
			
			FixObjectToObject(rings[21],bricks[67])
			FixObjectToObject(rings[22],bricks[61])
			FixObjectToObject(rings[23],bricks[55])
			FixObjectToObject(rings[24],bricks[49])		
			
			
			

			for t=1 to 4
			
			MoveObjectLocalz(rings[t],0.08)
			RotateObjectLocalx(rings[t],-90)
			next
				
			for t=5 to 8
			
			MoveObjectLocalz(rings[t],-0.08)
			RotateObjectLocalx(rings[t],-90)
			next	
				
				
			for t=9 to 12
			
			MoveObjectLocalx(rings[t],-0.08)
			RotateObjectLocalx(rings[t],-90)
			next
				
			for t=13 to 16
			
			MoveObjectLocalx(rings[t],0.08)
			RotateObjectLocalx(rings[t],-90)
			next	
				
				
			for t=17 to 20
			
			MoveObjectLocaly(rings[t],-0.08)
			
			next
				
			for t=21 to 24
			
			MoveObjectLocaly(rings[t],0.08)
		
			next	
				
				
			rings_amount=24
			
			
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		
		
		
		drones[1]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[1],bricks[13])
		RotateObjectLocalX(drones[1],180)
		MoveObjectLocaly(drones[1],0.08)
		
		
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocaly(drone_test_under[1],-0.08)
				
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)
				

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=2//rotatex -90
		 drone_turn[1,2]=2//rotatey -90
		 drone_turn[1,3]=2//rotatey -90
		 drone_turn[1,4]=2//rotatex -90
			
			
		
		 
		 drone_maker[1,1]=19
		 drone_maker[1,2]=1
		 drone_maker[1,3]=7
         drone_maker[1,4]=13
       
         
		 drones[2]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[2],bricks[61])
		
		MoveObjectLocaly(drones[2],0.08)
		RotateObjectLocalY(drones[2],180)
		
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocaly(drone_test_under[2],-0.08)
				
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)
				

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 drone_turn[2,1]=3//rotatex -90
		 drone_turn[2,2]=3//rotatey -90
		 drone_turn[2,3]=3//rotatey -90
		 drone_turn[2,4]=3//rotatex -90
			
			
		
		 
		 drone_maker[2,1]=55
		 drone_maker[2,2]=49
		 drone_maker[2,3]=67
         drone_maker[2,4]=61
		 
	


 drones[3]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[3],bricks[85])
		RotateObjectLocalx(drones[3],90)
		MoveObjectLocaly(drones[3],0.08)
	RotateObjectLocaly(drones[3],180)
		
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocaly(drone_test_under[3],-0.08)
				
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)
				

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 drone_turn[3,1]=3//rotatex -90
		 drone_turn[3,2]=3//rotatey -90
		 drone_turn[3,3]=3//rotatey -90
		 drone_turn[3,4]=3//rotatex -90
			
			
		
		 
		 drone_maker[3,1]=91
		 drone_maker[3,2]=73
		 drone_maker[3,3]=79
         drone_maker[3,4]=85

  
	
    drones[4]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[4],bricks[37])
		RotateObjectLocalx(drones[4],-90)
		MoveObjectLocaly(drones[4],0.08)
	RotateObjectLocaly(drones[4],180)
		
			
				drone_test_under[4]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[4],drones[4])
				MoveObjectLocaly(drone_test_under[4],-0.08)
				
				SetObjectCollisionMode(drone_test_under[4],0)
				SetObjectCollisionMode(drones[4],0)
				

		 
		 drone_time[4]=0
		 
		 drone_move[4]=1
		 drone_turn[4,1]=3//rotatex -90
		 drone_turn[4,2]=3//rotatey -90
		 drone_turn[4,3]=3//rotatey -90
		 drone_turn[4,4]=3//rotatex -90
			
			
		
		 
		 drone_maker[4,1]=31
		 drone_maker[4,2]=25
		 drone_maker[4,3]=43
         drone_maker[4,4]=37

    
    
    
    
    
     drones[5]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[5],bricks[127])
		RotateObjectLocalz(drones[5],-90)
		MoveObjectLocaly(drones[5],0.08)
			RotateObjectLocalY(drones[5],180)
    
    drone_test_under[5]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[5],drones[5])
				MoveObjectLocaly(drone_test_under[5],-0.08)
				
				SetObjectCollisionMode(drone_test_under[5],0)
				SetObjectCollisionMode(drones[5],0)
				

		 
		 drone_time[5]=0
		 
		 drone_move[5]=1
		 drone_turn[5,1]=3//rotatex -90
		 drone_turn[5,2]=3//rotatey -90
		 drone_turn[5,3]=3//rotatey -90
		 drone_turn[5,4]=3//rotatex -90
			
			
		
		 
		 drone_maker[5,1]=133
		 drone_maker[5,2]=139
		 drone_maker[5,3]=121
         drone_maker[5,4]=127
        
		 drones[6]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[6],bricks[115])
		RotateObjectLocalz(drones[6],90)
		MoveObjectLocaly(drones[6],0.08)
			RotateObjectLocalY(drones[6],180)
    
    drone_test_under[6]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[6],drones[6])
				MoveObjectLocaly(drone_test_under[6],-0.08)
				
				SetObjectCollisionMode(drone_test_under[6],0)
				SetObjectCollisionMode(drones[6],0)
				

		 
		 drone_time[6]=0
		 
		 drone_move[6]=1
		 drone_turn[6,1]=2//rotatex -90
		 drone_turn[6,2]=2//rotatey -90
		 drone_turn[6,3]=2//rotatey -90
		 drone_turn[6,4]=2//rotatex -90
			
			
		
		 
		 drone_maker[6,1]=109
		 drone_maker[6,2]=103
		 drone_maker[6,3]=97
         drone_maker[6,4]=115
         
         drone_amount=6
         for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
				PlayMusic(music,1)
				SetObjectVisible(pivot,0)
endfunction




function level9()
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music9.mp3")
pick_up=0
texture_1=LoadImage("\media\textures\LEV9.JPG") /// bricks


brick=0	
	
		opentoread(1,"\media\data\Level9.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
						SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],-0.08*3)
						MoveObjectLocaly(bricks[t],-0.08*5)
						next

		RotateObjectLocalY(pivot,180)
				
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[133])
				MoveObjectLocalY(me,0.08)
				RotateObjectLocalY(me,180)
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				
				
				
				
				
				
				
				
				for t=1 to 14
				rings[t]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[t],0.04,0.04,0.04)
				
				
				SetObjectCollisionMode(rings[t],0)
				
				next
			
			
			FixObjectToObject(rings[1],bricks[19])
			FixObjectToObject(rings[2],bricks[13])
			FixObjectToObject(rings[3],bricks[7])
			FixObjectToObject(rings[4],bricks[1])
			
			FixObjectToObject(rings[5],bricks[64])
			FixObjectToObject(rings[6],bricks[82])
			FixObjectToObject(rings[7],bricks[116])
			FixObjectToObject(rings[8],bricks[91])
			
			
			FixObjectToObject(rings[9],bricks[97])
			FixObjectToObject(rings[10],bricks[110])
			FixObjectToObject(rings[11],bricks[58])
			FixObjectToObject(rings[12],bricks[40])
			
			FixObjectToObject(rings[13],bricks[73])
			FixObjectToObject(rings[14],bricks[49])
			
			
			
			

			
				
				
			for t=1 to 14
			
			MoveObjectLocaly(rings[t],0.08)
			
			next
				
				
				
				
			rings_amount=14
			
			
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		
		
		
		drones[1]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[1],bricks[1])
		RotateObjectLocalY(drones[1],0)
		MoveObjectLocaly(drones[1],0.08)
		
		
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocaly(drone_test_under[1],-0.08)
				
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)
				

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=3//rotatex -90
		 drone_turn[1,2]=3//rotatey -90
		 drone_turn[1,3]=3//rotatey -90
		 drone_turn[1,4]=3//rotatex -90
			
			
		
		 
		 drone_maker[1,1]=7
		 drone_maker[1,2]=13
		 drone_maker[1,3]=19
         drone_maker[1,4]=1
       
         
		 drones[2]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[2],bricks[58])
		
		MoveObjectLocaly(drones[2],0.08)
		RotateObjectLocalY(drones[2],-90)
		
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocaly(drone_test_under[2],-0.08)
				
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)
				

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 drone_turn[2,1]=1//rotatex -90
		 drone_turn[2,2]=3//rotatey -90
		 drone_turn[2,3]=3//rotatey -90
		 drone_turn[2,4]=1//rotatex -90
		drone_turn[2,5]=3//rotatex -90
		drone_turn[2,6]=3//rotatex -90		
			
		
		 
		 drone_maker[2,1]=55
		 drone_maker[2,2]=110
		 drone_maker[2,3]=97
         drone_maker[2,4]=103
		 drone_maker[2,5]=40
		 drone_maker[2,6]=58
	


 drones[3]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[3],bricks[82])
		RotateObjectLocaly(drones[3],90)
		MoveObjectLocaly(drones[3],0.08)
	   
		
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocaly(drone_test_under[3],-0.08)
				
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)
				

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 drone_turn[3,1]=1//rotatex -90
		 drone_turn[3,2]=2//rotatey -90
		 drone_turn[3,3]=2//rotatey -90
		 drone_turn[3,4]=1//rotatex -90
		drone_turn[3,5]=2//rotatey -90
		 drone_turn[3,6]=2//rotatex -90
			
		
		 
		 drone_maker[3,1]=79
		 drone_maker[3,2]=116
		 drone_maker[3,3]=91
         drone_maker[3,4]=85
		 drone_maker[3,5]=64
         drone_maker[3,6]=82	
  
	
    drones[4]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[4],bricks[116])
		//RotateObjectLocaly(drones[4],90)
		MoveObjectLocaly(drones[4],0.08)
	
		
			
				drone_test_under[4]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[4],drones[4])
				MoveObjectLocaly(drone_test_under[4],-0.08)
				
				SetObjectCollisionMode(drone_test_under[4],0)
				SetObjectCollisionMode(drones[4],0)
				

		 
		 drone_time[4]=0
		 
		 drone_move[4]=1
		 drone_turn[4,1]=3//rotatex -90
		 drone_turn[4,2]=3//rotatey -90
		 drone_turn[4,3]=3//rotatey -90
		 drone_turn[4,4]=3//rotatex -90
			
			
		
		 
		 drone_maker[4,1]=91
		 drone_maker[4,2]=97
		 drone_maker[4,3]=110
         drone_maker[4,4]=116

    
    
    
    
    
         
         drone_amount=4
         for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
				PlayMusic(music,1)
				SetObjectVisible(pivot,0)
endfunction




function level10()
	if GetMusicExists(music):DeleteMusic(music):endif
	music=LoadMusic("\media\music\music9.mp3")
pick_up=0
texture_1=LoadImage("\media\textures\LEV10.JPG") /// bricks


brick=0	
	
		opentoread(1,"\media\data\Level10.data")
			repeat
				brick=brick+1
				get1=ReadInteger(1)
				get2=ReadInteger(1)
				get3=ReadInteger(1)
				bricks[brick]=CreateObjectBox(0.08,0.08,0.08)
				setobjectposition(bricks[brick],0.08*GET1/10,0.08*GET2/10,0.08*GET3/10)
				setObjectImage(bricks[brick],texture_1,0)
					x_pos[BRICK]=GET1
					y_pos[BRICK]=GET2
					z_pos[BRICK]=GET3

					until FileEOF(1)
					CloseFile(1)


						pivot=createobjectsphere(0.1,32,32)	
						SetObjectCollisionMode(pivot,0)
						for t=1 to brick
						FixObjectToObject(bricks[t],pivot)
						MoveObjectLocalX(bricks[t],-0.08*3)
						MoveObjectLocalz(bricks[t],-0.08*3)
						MoveObjectLocaly(bricks[t],-0.08*5)
						next

		RotateObjectLocalY(pivot,180)
				
				me=createobjectsphere(0.01,32,32)
				FixObjectToObject(me,bricks[187])
				MoveObjectLocalY(me,0.08)
			
				test_front=createobjectbox(0.08,0.08,0.08)
				test_under=createobjectbox(0.08,0.08,0.08)
				FixObjectToObject(test_front,me)
				FixObjectToObject(test_under,me)
				MoveObjectLocalY(test_under,-0.08)
			
				MoveObjectLocalz(test_front,0.08)
				SetObjectCollisionMode(test_front,0)
				SetObjectCollisionMode(test_under,0)
				SetObjectCollisionMode(me,0)
				
				SetObjectVisible(test_front,0)
				SetObjectVisible(test_under,0)
				
				
					loadimage(200,"\media\textures\ball.png")
				loadimage(201,"\media\textures\Arrow.png")
				arrow=CreateObjectplane(0.1,0.2)
				RotateObjectGlobalX(arrow,90)
				FixObjectToObject(arrow,me)
				FixObjectPivot(arrow)
				SetObjectCollisionMode(arrow,0)
				setobjectimage(arrow,201,0)
				MoveObjectLocalY(arrow,0.08)
				SetObjectAlphaMask(arrow,1)
				
				
				
				
				ball=CreateObjectSphere(0.1,32,32)
				FixObjectToObject(ball,me)
				SetObjectCollisionMode(ball,0)
				setobjectimage(ball,200,0)
				
				
				
				
				
				
				
				
				
				
				for t=1 to 24
				rings[t]=loadobject("\media\models\ring.obj")
				setobjectscale(rings[t],0.04,0.04,0.04)
				
				
				SetObjectCollisionMode(rings[t],0)
				
				next
			
			
			FixObjectToObject(rings[1],bricks[1])
			FixObjectToObject(rings[2],bricks[7])
			FixObjectToObject(rings[3],bricks[13])
			FixObjectToObject(rings[4],bricks[19])
			
			FixObjectToObject(rings[5],bricks[176])
			FixObjectToObject(rings[6],bricks[139])
			FixObjectToObject(rings[7],bricks[151])
			FixObjectToObject(rings[8],bricks[164])
			
			
			FixObjectToObject(rings[9],bricks[103]):MoveObjectLocalx(rings[9],0.08)
			FixObjectToObject(rings[10],bricks[97]):MoveObjectLocalx(rings[10],0.08)
			FixObjectToObject(rings[11],bricks[91]):MoveObjectLocalx(rings[11],-0.08)
			FixObjectToObject(rings[12],bricks[85]):MoveObjectLocalx(rings[12],-0.08)
			
		
			FixObjectToObject(rings[13],bricks[58]):MoveObjectLocalz(rings[13],0.08)
			FixObjectToObject(rings[14],bricks[64]):MoveObjectLocalz(rings[14],0.08)
			FixObjectToObject(rings[15],bricks[70]):MoveObjectLocalz(rings[15],-0.08)
			FixObjectToObject(rings[16],bricks[76]):MoveObjectLocalz(rings[16],-0.08)
			
			
			FixObjectToObject(rings[17],bricks[112]):MoveObjectLocalx(rings[17],0.08)
			FixObjectToObject(rings[18],bricks[118]):MoveObjectLocalx(rings[18],0.08)
			FixObjectToObject(rings[19],bricks[124]):MoveObjectLocalx(rings[19],-0.08)
			FixObjectToObject(rings[20],bricks[130]):MoveObjectLocalx(rings[20],-0.08)
			
			FixObjectToObject(rings[21],bricks[31]):MoveObjectLocalz(rings[21],0.08)
			FixObjectToObject(rings[22],bricks[37]):MoveObjectLocalz(rings[22],0.08)
			FixObjectToObject(rings[23],bricks[43]):MoveObjectLocalz(rings[23],-0.08)
			FixObjectToObject(rings[24],bricks[49]):MoveObjectLocalz(rings[24],-0.08)
				
			for t=1 to 8
			
			MoveObjectLocaly(rings[t],0.08)
			
			next
				for t=9 to 12
			rotateObjectLocalz(rings[t],90)
			rotateObjectLocalz(rings[t+8],90)
			next	
			
			for t=13 to 16
			rotateObjectLocalx(rings[t],90)
			rotateObjectLocalx(rings[t+8],90)
			next
			
				
			rings_amount=25
			
			
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		
		
		
		drones[1]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[1],bricks[29])
		
		RotateObjectLocalx(drones[1],90)
		RotateObjectLocaly(drones[1],180)
		MoveObjectLocaly(drones[1],0.08)
		
			
				drone_test_under[1]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[1],drones[1])
				MoveObjectLocaly(drone_test_under[1],-0.08)
				
				SetObjectCollisionMode(drone_test_under[1],0)
				SetObjectCollisionMode(drones[1],0)
				

		 
		 drone_time[1]=0
		 
		 drone_move[1]=1
		 drone_turn[1,1]=3//rotatex -90
		 drone_turn[1,2]=3//rotatey -90
		 drone_turn[1,3]=3//rotatey -90
		 drone_turn[1,4]=3//rotatex -90
		drone_turn[1,5]=5//rotatex -90
			
		
		 drone_turn[1,6]=2//rotatex -90
		 drone_turn[1,7]=2//rotatey -90
		 drone_turn[1,8]=2//rotatey -90
		 drone_turn[1,9]=2//rotatex -90
		drone_turn[1,10]=5//rotatex -90
		 
		 drone_maker[1,1]=31
		 drone_maker[1,2]=37
		 drone_maker[1,3]=43
         drone_maker[1,4]=49
		 drone_maker[1,5]=51
         
         
         drone_maker[1,6]=49
		 drone_maker[1,7]=43
		 drone_maker[1,8]=37
         drone_maker[1,9]=31
		 drone_maker[1,10]=29
         
         
         
		
		drones[2]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[2],bricks[29])
		
		RotateObjectLocalx(drones[2],-90)
		//RotateObjectLocaly(drones[2],180)
		MoveObjectLocaly(drones[2],0.08)
		
			
				drone_test_under[2]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[2],drones[2])
				MoveObjectLocaly(drone_test_under[2],-0.08)
				
				SetObjectCollisionMode(drone_test_under[2],0)
				SetObjectCollisionMode(drones[2],0)
				

		 
		 drone_time[2]=0
		 
		 drone_move[2]=1
		 drone_turn[2,1]=2//rotatex -90
		 drone_turn[2,2]=2//rotatey -90
		 drone_turn[2,3]=2//rotatey -90
		 drone_turn[2,4]=2//rotatex -90
		 drone_turn[2,5]=5//rotatex -90
			
		
		 drone_turn[2,6]=3//rotatex -90
		 drone_turn[2,7]=3//rotatey -90
		 drone_turn[2,8]=3//rotatey -90
		 drone_turn[2,9]=3//rotatex -90
		drone_turn[2,10]=5//rotatex -90
		 
		 drone_maker[2,1]=31
		 drone_maker[2,2]=37
		 drone_maker[2,3]=43
         drone_maker[2,4]=49
		 drone_maker[2,5]=51
         
         
         drone_maker[2,6]=49
		 drone_maker[2,7]=43
		 drone_maker[2,8]=37
         drone_maker[2,9]=31
		 drone_maker[2,10]=29
		 
		 
		 
		 
		 
		 
		 drones[3]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[3],bricks[56])
		
		RotateObjectLocalx(drones[3],90)
		RotateObjectLocaly(drones[3],180)
		MoveObjectLocaly(drones[3],0.08)
		
			
				drone_test_under[3]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[3],drones[3])
				MoveObjectLocaly(drone_test_under[3],-0.08)
				
				SetObjectCollisionMode(drone_test_under[3],0)
				SetObjectCollisionMode(drones[3],0)
				

		 
		 drone_time[3]=0
		 
		 drone_move[3]=1
		 drone_turn[3,1]=2//rotatex -90
		 drone_turn[3,2]=2//rotatey -90
		 drone_turn[3,3]=2//rotatey -90
		 drone_turn[3,4]=2//rotatex -90
		drone_turn[3,5]=5//rotatex -90
			
		
		 drone_turn[3,6]=3//rotatex -90
		 drone_turn[3,7]=3//rotatey -90
		 drone_turn[3,8]=3//rotatey -90
		 drone_turn[3,9]=3//rotatex -90
		drone_turn[3,10]=5//rotatex -90
		 
		 drone_maker[3,1]=58
		 drone_maker[3,2]=64
		 drone_maker[3,3]=70
         drone_maker[3,4]=76
		 drone_maker[3,5]=78
         
         
         drone_maker[3,6]=76
		 drone_maker[3,7]=70
		 drone_maker[3,8]=64
         drone_maker[3,9]=58
		 drone_maker[3,10]=56
		 
		 
		 
		 
		 
		 
		 
		drones[4]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[4],bricks[56])
		
		RotateObjectLocalx(drones[4],-90)
		//RotateObjectLocaly(drones[2],180)
		MoveObjectLocaly(drones[4],0.08)
		
			
				drone_test_under[4]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[4],drones[4])
				MoveObjectLocaly(drone_test_under[4],-0.08)
				
				SetObjectCollisionMode(drone_test_under[4],0)
				SetObjectCollisionMode(drones[4],0)
				

		 
		 drone_time[4]=0
		 
		 drone_move[4]=1
		 drone_turn[4,1]=3//rotatex -90
		 drone_turn[4,2]=3//rotatey -90
		 drone_turn[4,3]=3//rotatey -90
		 drone_turn[4,4]=3//rotatex -90
		 drone_turn[4,5]=5//rotatex -90
			
		
		 drone_turn[4,6]=2//rotatex -90
		 drone_turn[4,7]=2//rotatey -90
		 drone_turn[4,8]=2//rotatey -90
		 drone_turn[4,9]=2//rotatex -90
		drone_turn[4,10]=5//rotatex -90
		 
		 drone_maker[4,1]=58
		 drone_maker[4,2]=64
		 drone_maker[4,3]=70
         drone_maker[4,4]=76
		 drone_maker[4,5]=78
         
         
         drone_maker[4,6]=76
		 drone_maker[4,7]=70
		 drone_maker[4,8]=64
         drone_maker[4,9]=58
		 drone_maker[4,10]=56 
		 
		 
		 
		 
		 
		 
		 
		 
		 drones[5]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[5],bricks[110])
		
		RotateObjectLocalz(drones[5],90)
		
		MoveObjectLocaly(drones[5],0.08)
		RotateObjectLocaly(drones[5],90)
			
				drone_test_under[5]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[5],drones[5])
				MoveObjectLocaly(drone_test_under[5],-0.08)
				
				SetObjectCollisionMode(drone_test_under[5],0)
				SetObjectCollisionMode(drones[5],0)
				

		 
		 drone_time[5]=0
		 drone_move[5]=1
		 
		 
		 drone_turn[5,1]=3//rotatex -90
		 drone_turn[5,2]=3//rotatey -90
		 drone_turn[5,3]=3//rotatey -90
		 drone_turn[5,4]=3//rotatex -90
		 drone_turn[5,5]=5//rotatex -90
			
		
		 drone_turn[5,6]=2//rotatex -90
		 drone_turn[5,7]=2//rotatey -90
		 drone_turn[5,8]=2//rotatey -90
		 drone_turn[5,9]=2//rotatex -90
		drone_turn[5,10]=5//rotatex -90
		 
		 drone_maker[5,1]=112
		 drone_maker[5,2]=118
		 drone_maker[5,3]=124
         drone_maker[5,4]=130
		 drone_maker[5,5]=132
         
         
         drone_maker[5,6]=130
		 drone_maker[5,7]=124
		 drone_maker[5,8]=118
         drone_maker[5,9]=112
		 drone_maker[5,10]=110 
		 
		 
		 drones[6]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[6],bricks[110])
		
		RotateObjectLocalz(drones[6],-90)
		
		MoveObjectLocaly(drones[6],0.08)
		RotateObjectLocaly(drones[6],-90)
			
				drone_test_under[6]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[6],drones[6])
				MoveObjectLocaly(drone_test_under[6],-0.08)
				
				SetObjectCollisionMode(drone_test_under[6],0)
				SetObjectCollisionMode(drones[6],0)
				

		 
		 drone_time[6]=0
		 drone_move[6]=1
		 
		 
		 drone_turn[6,1]=2//rotatex -90
		 drone_turn[6,2]=2//rotatey -90
		 drone_turn[6,3]=2//rotatey -90
		 drone_turn[6,4]=2//rotatex -90
		 drone_turn[6,5]=5//rotatex -90
			
		
		 drone_turn[6,6]=3//rotatex -90
		 drone_turn[6,7]=3//rotatey -90
		 drone_turn[6,8]=3//rotatey -90
		 drone_turn[6,9]=3//rotatex -90
		drone_turn[6,10]=5//rotatex -90
		 
		 drone_maker[6,1]=112
		 drone_maker[6,2]=118
		 drone_maker[6,3]=124
         drone_maker[6,4]=130
		 drone_maker[6,5]=132
         
         
         drone_maker[6,6]=130
		 drone_maker[6,7]=124
		 drone_maker[6,8]=118
         drone_maker[6,9]=112
		 drone_maker[6,10]=110 
		 
		 
	 
		 drones[7]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[7],bricks[105])
		
		RotateObjectLocalz(drones[7],-90)
		
		MoveObjectLocaly(drones[7],0.08)
		RotateObjectLocaly(drones[7],-90)
			
				drone_test_under[7]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[7],drones[7])
				MoveObjectLocaly(drone_test_under[7],-0.08)
				
				SetObjectCollisionMode(drone_test_under[7],0)
				SetObjectCollisionMode(drones[7],0)
				

		 
		 drone_time[7]=0
		 drone_move[7]=1
		 
		 
		 drone_turn[7,1]=3//rotatex -90
		 drone_turn[7,2]=3//rotatey -90
		 drone_turn[7,3]=3//rotatey -90
		 drone_turn[7,4]=3//rotatex -90
		 drone_turn[7,5]=5//rotatex -90
			
		
		 drone_turn[7,6]=2//rotatex -90
		 drone_turn[7,7]=2//rotatey -90
		 drone_turn[7,8]=2//rotatey -90
		 drone_turn[7,9]=2//rotatex -90
		drone_turn[7,10]=5//rotatex -90
		 
		 drone_maker[7,1]=103
		 drone_maker[7,2]=97
		 drone_maker[7,3]=91
         drone_maker[7,4]=85
		 drone_maker[7,5]=83
         
         
         drone_maker[7,6]=85
		 drone_maker[7,7]=91
		 drone_maker[7,8]=97
         drone_maker[7,9]=103
		 drone_maker[7,10]=105 
		 	 
		 
		 
		 drones[8]=createobjectsphere(0.01,32,32)
		FixObjectToObject(drones[8],bricks[105])
		
		RotateObjectLocalz(drones[8],90)
		
		MoveObjectLocaly(drones[8],0.08)
		RotateObjectLocaly(drones[8],90)
			
				drone_test_under[8]=createobjectbox(0.08,0.08,0.08)
				
				FixObjectToObject(drone_test_under[8],drones[8])
				MoveObjectLocaly(drone_test_under[8],-0.08)
				
				SetObjectCollisionMode(drone_test_under[8],0)
				SetObjectCollisionMode(drones[8],0)
				

		 
		 drone_time[8]=0
		 drone_move[8]=1
		 
		 
		 drone_turn[8,1]=2//rotatex -90
		 drone_turn[8,2]=2//rotatey -90
		 drone_turn[8,3]=2//rotatey -90
		 drone_turn[8,4]=2//rotatex -90
		 drone_turn[8,5]=5//rotatex -90
			
		
		 drone_turn[8,6]=3//rotatex -90
		 drone_turn[8,7]=3//rotatey -90
		 drone_turn[8,8]=3//rotatey -90
		 drone_turn[8,9]=3//rotatex -90
		drone_turn[8,10]=5//rotatex -90
		 
		 drone_maker[8,1]=103
		 drone_maker[8,2]=97
		 drone_maker[8,3]=91
         drone_maker[8,4]=85
		 drone_maker[8,5]=83
         
         
         drone_maker[8,6]=85
		 drone_maker[8,7]=91
		 drone_maker[8,8]=97
         drone_maker[8,9]=103
		 drone_maker[8,10]=105 		 
		 
		 
		 
		 
         drone_amount=8
         for t=1 to 100
				if GetObjectExists(drone_skin[t])=1:deleteobject(drone_skin[t]):endif
					next
			loadimage(202,"\media\textures\ball2.png")
			for t=1 to drone_amount
				//SetObjectVisible(drone_test_under[t],0)
				drone_skin[t]=createobjectsphere(0.1,32,32)
				FixObjectToObject(drone_skin[t],drones[t])
				setobjectimage(drone_skin[t],202,0)
				SetObjectCollisionMode(drone_skin[t],0)
				next
				PlayMusic(music,1)
				SetObjectVisible(pivot,0)
				setobjectposition(pivot,0,1,-2.5)
				RotateObjectLocalY(PIVOT,0)
				 drone_amount=8
				
endfunction


