
SetErrorMode(2)

// set window properties
SetWindowTitle( "GUTITAR" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts


DIM ALPHA[26]

SetPrintSize(60)
FOR T=1 TO 26
	PRINT(CHR(T+64))
	Render()
	ALPHA[T]=GETIMAGE(1,1,30,60)
	ClearScreen()
	SYNC()
	NEXT
   
global InitError as integer
global RightEyeImg As Integer
global LeftEyeImg As Integer
global hand

global Right_Hand as integer

global Right_Hand_PosX AS INTEGER
global Right_Hand_PosY AS INTEGER
global Right_Hand_PosZ AS INTEGER

GLOBAL Right_Hand_AngleX AS INTEGER
GLOBAL Right_Hand_AngleY AS INTEGER
GLOBAL Right_Hand_AngleZ AS INTEGER

global Left_Hand as integer

GLOBAL Left_Hand_PosX as integer
GLOBAL Left_Hand_Posy as integer
GLOBAL Left_Hand_Posz as integer

GLOBAL Left_Hand_AngleX AS INTEGER
GLOBAL Left_Hand_AngleY AS INTEGER
GLOBAL Left_Hand_AngleZ AS INTEGER

global HMDPosX as float
global HMDPosY as float
global HMDPosZ as float
global HMDAngleX as float
global HMDAngleY as float
global HMDAnglez as float

global PlayerPosX as float
global PlayerPosY as float
global PlayerPosZ as float
GLOBAL PlayerAngleX AS FLOAT
GLOBAL PlayerAngleY AS FLOAT
GLOBAL PlayerAngleZ AS FLOAT

global LeftPosX as float
global LeftPosY as float
global LeftPosZ as float

global LeftAngleX as float
global LeftAngleY as float
global LeftAngleZ as float

global LeftButton1 as integer
global LeftButton2 as integer
global LeftButton3 as integer
global LeftTrigger as float

global LeftJoyX as float
global LeftJoyY as float

global RightPosX as float
global RightPosY as float
global RightPosZ as float

global RightAngleX as float
global RightAngleY as float
global RightAngleZ as float

global RightButton1 as integer
global RightButton2 as integer
global RightButton3 as integer
global RightTrigger as float

global RightJoyX as float
global RightJoyY as float


global dim strings[6,21] as integer
global dim pick[6,21]

global dim LINES[6]
GLOBAL DIM N[6]
global dim dis[21] as float
global dim dis1[6] as float
GLOBAL DIM CHORD[40]
global dim Rays[6,2]
global dim Pick_Rays[21,2]
global dim st[6]
global banjo


global right_finger as integer
global right_finger1 as integer
global right_finger2 as integer
global right_finger3 as integer
global left_finger as integer
global left_finger_tip as integer





box_d=loadimage("bottom.png")
box_u=loadimage("top.png")

box_b=loadimage("back.png")
box_f=loadimage("front.png")

box_r=loadimage("left.png")
box_l=loadimage("right.png")

CreateObjectPlane(1,1000,1000)
setobjectimage(1,box_b,0)

CreateObjectPlane(2,1000,1000)
setobjectimage(2,box_f,0)

MoveObjectLocalZ(2,-500)
MoveObjectLocalZ(1,500)
RotateObjectLocalY(1,180)

CreateObjectPlane(3,1000,1000)
setobjectimage(3,box_d,0)

CreateObjectPlane(4,1000,1000)
setobjectimage(4,box_u,0)

MoveObjectLocaly(3,-500)
MoveObjectLocaly(4,500)
RotateObjectLocalX(3,-90)
RotateObjectLocalX(4,90)


CreateObjectPlane(5,1000,1000)
setobjectimage(5,box_l,0)

CreateObjectPlane(6,1000,1000)
setobjectimage(6,box_r,0)

MoveObjectLocalx(5,-500)
MoveObjectLocalx(6,500)
RotateObjectLocaly(5,-90)
RotateObjectLocaly(6,90)

SetObjectLightMode(1,0)

SetObjectLightMode(2,0)
SetObjectLightMode(3,0)
SetObjectLightMode(4,0)
SetObjectLightMode(5,0)
SetObjectLightMode(6,0)

SetObjectCollisionMode(1,0)
SetObjectCollisionMode(2,0)
SetObjectCollisionMode(3,0)
SetObjectCollisionMode(4,0)
SetObjectCollisionMode(5,0)
SetObjectCollisionMode(6,0)



	#import_plugin AGKVR 
	RightEyeImg = 500
	LeftEyeImg  = 501
	InitError = AGKVR.Init( RightEyeImg, LeftEyeImg )
	
	AGKVR.LockPlayerTurn( 0 )
	AGKVR.LockPlayerPitch( 0 )
	AGKVR.SetWorldScale( 100 )
	hand=loadimage("\media\Hand.png")
	AGKVR.SetWorldScale(70 )
	
	hand=loadimage("\media\Hand.png")
	right_hand=LoadObjectWithChildren("RHand.fbx")
		SetObjectPosition(right_hand,0.0,0.0,-0.07)
		SetObjectRotation(right_hand,0.0,180.0,90.0)
		FixObjectPivot(right_hand)
		SetObjectVisible(right_hand,1)
		SetObjectCollisionMode(right_hand,0)

	left_Hand=LoadObjectWithChildren("\media\LHand.FBX")
		SetObjectPosition(left_hand,0.0,0.0,-0.07)
		SetObjectRotation(left_hand,0.0,180.0,270.0)
		FixObjectPivot(left_hand)
		SetObjectAnimationSpeed(left_hand,20)
		SetObjectVisible(left_hand,1)
		SetObjectCollisionMode(left_hand,0)


		left_finger=CreateObjectCylinder(3,1,43)
		ROTATEOBJECTLOCALZ(left_finger,90)
		FixObjectPivot(left_finger)
		
		
		

	right_finger=CreateObjectCylinder(2,0.3,32)
		FixObjectToBone( RIGHT_finger, RIGHT_Hand, 19 )
		RotateObjectGlobalZ(right_finger,90)
		FixObjectPivot(right_finger)
		MoveObjectLocalx(right_finger,1)
		MoveObjectLocaly(right_finger,0.3)
	
	right_finger1=CreateObjectCylinder(2,0.3,32)
		FixObjectToBone( RIGHT_finger1, RIGHT_Hand, 20 )
		RotateObjectGlobalZ(right_finger1,90)
		FixObjectPivot(right_finger1)
		MoveObjectLocalx(right_finger1,1)
		MoveObjectLocalz(right_finger1,-0.3)
	
	
	right_finger2=CreateObjectCylinder(2,0.3,32)
		FixObjectToBone( RIGHT_finger2, RIGHT_Hand, 21 )
		RotateObjectGlobalZ(right_finger2,90)
		FixObjectPivot(right_finger2)
		MoveObjectLocalx(right_finger2,1)
		MoveObjectLocaly(right_finger2,0.3)
	
	right_finger3=CreateObjectCylinder(2,0.3,32)
		FixObjectToBone( RIGHT_finger3, RIGHT_Hand, 22 )
		RotateObjectGlobalZ(right_finger3,90)
		FixObjectPivot(right_finger3)
		MoveObjectLocalx(right_finger3,1)
		MoveObjectLocaly(right_finger3,0.3)	
		SetObjectScalePermanent(left_hand,45,45,45)
		SetObjectScalePermanent(right_hand,45,45,45)
		
		


vid=LoadVideo("Spiral_FlowVga.mp4")
PlayVideoToImage(100)


ground=CreateObjectPlane(500,500)
RotateObjectLocalX(ground,90)
SetObjectImage(ground,100,0)

load_sounds()
make_guitar()
SetCameraRotation(1,0,0,0)
MoveCameraLocalZ(1,-130)
MoveCameraLocalx(1,30)

SetObjectScale(banjo,0.15,0.15,0.15)
FixObjectPivot(banjo)

CHOR=1
dim contackt[6]
GOSUB _POS0
RotateObjectLocalX(banjo,45)
RotateObjectLocalZ(banjo,45)
FixObjectPivot(BANJO)

RotateObjectLocalz(banjo,180)
RotateObjectLocalX(banjo,160)
RotateObjectLocaly(banjo,40)
FixObjectPivot(banjo)

chor=2

dim sequence[100]




INPUT= CreateEditBox()
SetEditBoxSize(INPUT,200,40)
SetEditBoxTextSize(INPUT,38)

SetEditBoxText(INPUT,"ABC")
POSCHOR=1


CARD=CreateObjectPlane(100,100)

do 
	
	
	
	A$=GetEditBoxText(INPUT)
	LENTH=LEN(A$)
	
			if GetVideoPlaying()=0
				PlayVideoToImage(100)
				endif
			
			PRINT(CHOR)
		
		
		
		
		IF RightButton3=1 
			POSCHOR=1
	
				CHANGE=20		
			
				B$=MID(A$,POSCHOR,1)
				CHOR=ASC(B$)-63
				ENDIF
			
		
		
		
		if change=0
			
			IF RightButton1=1 AND CHANGE=0 
				INC POSCHOR
				CHANGE=20		
				IF POSCHOR>LENTH THEN POSCHOR=1
				B$=MID(A$,POSCHOR,1)
				CHOR=ASC(B$)-63
				ENDIF
				endif
		IF CHANGE>0 THEN DEC CHANGE,1
		
	PRINT(CHOR)
	SetObjectImage(CARD,ALPHA[CHOR-1],0)
		VR()
	
			 
	   SELECT CHOR
			
	   CASE 1 /// OPEN
			 N[1]=1
			 N[2]=1
			 N[3]=1
			 N[4]=1
			 N[5]=1
			 N[6]=1
			 ENDCASE	 
	   CASE 2   /// Am
			 N[1]=0
			 N[2]=1
			 N[3]=3
			 N[4]=1
			 N[5]=3
			 N[6]=1 
			 ENDCASE
	   CASE 3  ///' b
			 N[1]=0
			 N[2]=0
			 N[3]=5
			 N[4]=5
			 N[5]=5
			 N[6]=3
			 ENDCASE
	   CASE 4  ///' c
			 N[1]=0
			 N[2]=4
			 N[3]=3
			 N[4]=1
			 N[5]=2
			 N[6]=1	
			 ENDCASE	 
	   CASE 5  ///' d
			 N[1]=0
			 N[2]=0
			 N[3]=1
			 N[4]=3
			 N[5]=4
			 N[6]=3
			 ENDCASE		
	   CASE 6  ///' e
			 N[1]=1
			 N[2]=3
			 N[3]=3
			 N[4]=2
			 N[5]=1
			 N[6]=1
			 ENDCASE
	   CASE 7  ///' f
			 N[1]=0
			 N[2]=0
			 N[3]=4
			 N[4]=3
			 N[5]=2
			 N[6]=2
			 ENDCASE

		CASE 8  ///' g
			 N[1]=4
			 N[2]=3
			 N[3]=1
			 N[4]=1
			 N[5]=1
			 N[6]=4
			 ENDCASE
		ENDSELECT
	
		SetObjectPosition(banjo,PlayerPosX-5,PlayerPosY,PlayerPosZ)
		SetObjectRotation(banjo,0,PlayerAngleY,0)
		if LeftJoyY>0.5 then up#=up#+0.1
		if LeftJoyY<-0.5 then up#=up#-0.1
		MoveObjectLocalY(banjo,30+up#)
		MoveObjectLocalX(banjo,0)
		MoveObjectLocalz(banjo,5)

	
	
		SetObjectPosition(CARD,PlayerPosX-5,PlayerPosY,PlayerPosZ)
		SetObjectRotation(CARD,0,PlayerAngleY,0)
		MoveObjectLocalY(CARD,30+up#)
		MoveObjectLocalX(CARD,0)
		MoveObjectLocalz(CARD,100)

	
	
	
		x1#=GetObjectWorldX(Left_Hand)
		y1#=GetObjectWorldy(Left_Hand)
		z1#=GetObjectWorldz(Left_Hand)
     
		x2#=GetObjectWorldAngleX(Left_Hand)
		y2#=GetObjectWorldAngleY(Left_Hand)
		z2#=GetObjectWorldAngleZ(Left_Hand)
		SetObjectPosition(left_finger,x1#,y1#,z1#)
		SetObjectRotation(left_finger,x2#,y2#,z2#)
		MoveObjectLocalX(left_finger,2.5)
		MoveObjectLocalz(left_finger,4.3)
		MoveObjectLocaly(left_finger,-1)
	
	picking=0
	V=20
	for t=1 to 20
		x1#=GetObjectWorldX(Pick_Rays[t,1])
		y1#=GetObjectWorldY(Pick_Rays[t,1])
		z1#=GetObjectWorldZ(Pick_Rays[t,1])	
					
		x2#=GetObjectWorldX(Pick_Rays[t,2])
		y2#=GetObjectWorldY(Pick_Rays[t,2])
		z2#=GetObjectWorldZ(Pick_Rays[t,2])	
		
		HIT1=ObjectSPHERECast(0,X1#,Y1#,Z1#,X2#,Y2#,Z2#,0.2)
					
				   if hit1= left_finger
						along=V
						picking=1
						
					endif
					V=V-1
			NEXT
		PRINT(ALONG)
	this=6
	FOR P=1 to 6 
		
		x1#=GetObjectWorldX(rayS[p,1])
		y1#=GetObjectWorldy(rayS[p,1])
		z1#=GetObjectWorldz(rayS[p,1])
     
		x2#=GetObjectWorldX(rayS[p,2])
		y2#=GetObjectWorldy(rayS[p,2])
		z2#=GetObjectWorldz(rayS[p,2]) 

		hit=ObjectSphereCast(0,x1#,y1#,z1#,x2#,y2#,z2#,0.2)
		
		IF  contackt[this]=1 and hit=0 then contackt[this]=0
		SetObjectCollisionMode(Right_Hand,0)
		
		
		
				if hit=right_finger
					IF  N[this]>0 and contackt[this]=0
						contackt[this]=1
						PLAY=N[this]
						
						IF PICKING=1 THEN PLAY =ALONG
						if PICKING=1 and LeftButton3=1 then PLAY=N[this]+along
						if play>0
						playsound(strings[this,PLAY],100,0,p)
						endif
						endif
						ENDIF
		
				if hit=right_finger1
					IF  N[this]>0 and contackt[this]=0
						
						contackt[this]=1
						PLAY=N[this]
						IF PICKING=1 THEN PLAY =ALONG
						if PICKING=1 and LeftButton3=1 then PLAY=N[this]+along
						if play>0
						playsound(strings[this,PLAY],100,0,p)
						endif
						endif
						ENDIF
	
				if hit=right_finger2
					IF  N[this]>0 and contackt[this]=0
						contackt[this]=1
						PLAY=N[this]
						IF PICKING=1 THEN PLAY =ALONG
						if PICKING=1 and LeftButton3=1 then PLAY=N[this]+along
						if play>0
						playsound(strings[this,PLAY],100,0,p)
						endif
						endif
						ENDIF
		
		
				if hit=right_finger3
					IF  N[P]>0 and contackt[this]=0
						contackt[this]=1
						PLAY=N[this]
						IF PICKING=1 THEN PLAY =ALONG
						if PICKING=1 and LeftButton3=1 then PLAY=N[this]+along
						if play>0
						playsound(strings[this,PLAY],100,0,p)
						endif
						endif
		ENDIF
	
	this=this-1
	NEXT
	
		
	Sync()	
loop



function load_sounds()

	v=1
	for t=1 to 21
	strings[1,v]=loadsound("\media\e\"+str(t)+".wav")
	strings[2,v]=loadsound("\media\a\"+str(t)+".wav")
	strings[3,v]=loadsound("\media\d\"+str(t)+".wav")
	strings[4,v]=loadsound("\media\g\"+str(t)+".wav")
	strings[5,v]=loadsound("\media\b\"+str(t)+".wav")
	strings[6,v]=loadsound("\media\eb\"+str(t)+".wav")
	INC v
	next
endfunction


Function make_guitar()
		dis[1]=28
		dis[2]=34
		dis[3]=41
		dis[4]=47
		dis[5]=55
		dis[6]=63
		dis[7]=70
		dis[8]=79
		dis[9]=88
		dis[10]=98
		dis[11]=108
		dis[12]=120
		dis[13]=131
		dis[14]=143
		dis[15]=157
		dis[16]=170
		dis[17]=185
		dis[18]=200
		dis[19]=215
		dis[20]=232
		
		dis1[1]=8.5
		
		
		banjo=loadobject("\media\Gibson\guitar.FBX")
		SetObjectCollisionMode(banjo,0)
		loadimage(1,"\media\Gibson\diffuse.jpg"	)
		loadimage(2,"\media\Gibson\bump.jpg"	)
		SETOBJECTIMAGE(BANJO,1,1)
		SETOBJECTIMAGE(BANJO,2,2)
		SetObjectCollisionMode(banjo,0)
	   
	

	
	
	
		 z=1 
		 y#=8
		 b#=13.5
			z=1 
			for t=1 to 20
				pick[z,t]=createobjectbox(5,28,2)
				SetObjectVisible(pick[z,t],0)
				Pick_Rays[t,1]=createobjectsphere(1,32,32)
				Pick_Rays[t,2]=createobjectsphere(1,32,32)
				
				FixObjectToObject(Pick_Rays[t,1],pick[1,t])
				FixObjectToObject(Pick_Rays[t,2],pick[1,t])
				SetObjectCollisionMode(Pick_Rays[t,1],0)
				SetObjectCollisionMode(Pick_Rays[t,2],0)
				
				MoveObjectLocaly(Pick_Rays[t,1],-14.5)
				MoveObjectLocaly(Pick_Rays[t,2],14.5)
				FixObjectToObject(pick[z,t],banjo)
				MoveObjectLocalZ(pick[z,t],-b#)	
				MoveObjectLocalx(pick[z,t],dis[t])
				MoveObjectLocaly(pick[z,t],y#)
				RotateObjectLocalY(pick[z,t],-1)
				SetObjectColor(pick[z,t],45,32,238,255)
				SetObjectCollisionMode(pick[z,t],0)
				b#=b#-0.4
				next
				
			

			
	DOWN#=-2.3
	for p=1 to 6
		LINES[P]=CREATEOBJECTbox(100,1,1)
		SetObjectCollisionMode(LINES[P],0)
		rays[p,1]=CreateObjectSphere(0.3,32,32)
		rays[p,2]=CreateObjectSphere(0.3,32,32)
		fixobjecttoobject(rays[p,1],lines[p])
		fixobjecttoobject(rays[p,2],lines[p])
		
		MoveObjectLocalX(rays[p,1],-50)
		MoveObjectLocalX(rays[p,2],50)
		SetObjectCollisionMode(rays[p,1],0)
		SetObjectCollisionMode(rays[p,2],0)
			FixObjectToObject(LINES[P],BANJO)
			MoveObjectLocalx(LINES[P],-50)
			MoveObjectLocalY(LINES[P],DOWN#)
			DOWN#=DOWN#+4.7
			MoveObjectLocalZ(LINES[P],-13)
			SetObjectColor(lines[p],0,255,0,255)
			RotateObjectLocalY(lines[p],-2)
			NEXT	
				

endfunction

	
FUNCTION VR()

	AGKVR.UpdatePlayer( )

	HMDPosX = AGKVR.GetHMDX() 
	HMDPosY = AGKVR.GetHMDY()
	HMDPosZ = AGKVR.GetHMDZ()
	
	HMDAngleX = AGKVR.GetHMDAngleX()
	HMDAngleY = AGKVR.GetHMDAngleY()
	HMDAngleZ = AGKVR.GetHMDAngleZ()	
	
	PlayerPosX = AGKVR.GetPlayerX()
	PlayerPosY = AGKVR.GetPlayerY()
	PlayerPosZ = AGKVR.GetPlayerZ()
	
	PlayerAngleX=AGKVR.GetPlayerAngleX() 
	PlayerAngleY=AGKVR.GetPlayerAngleY()
	PlayerAngleZ=AGKVR.GetPlayerAngleZ()
	
	LeftPosX=AGKVR.GetLeftHandX()
	LeftPosY=AGKVR.GetLeftHandY()
	LeftPosZ=AGKVR.GetLeftHandZ()
	
	LeftAngleX =AGKVR.GetLeftHandAngleX()
	LeftAngleY =AGKVR.GetLeftHandAngleY()
	LeftAngleZ =AGKVR.GetLeftHandAngleZ()
	
	LeftButton1=AGKVR.LeftController_Button1()
	LeftButton2=AGKVR.LeftController_Button2()
	LeftButton3=AGKVR.LeftController_Grip()
	LeftTrigger=AGKVR.LeftController_Trigger( )
    
	LeftJoyX= AGKVR.LeftController_JoyX( )
	LeftJoyY= AGKVR.LeftController_JoyY( )	

	RightPosX=AGKVR.GetRightHandX()
	RightPosY=AGKVR.GetRightHandY()
	RighpPosZ=AGKVR.GetRightHandZ()
	
	RightAngleX =AGKVR.GetRightHandAngleX()
	RightAngleY =AGKVR.GetRightHandAngleY()
	RightAngleZ =AGKVR.GetRightHandAngleZ()
	
	RightButton1=AGKVR.RightController_Button1()
	RightButton2=AGKVR.RightController_Button2()
	RightButton3=AGKVR.RightController_Grip() 
	RightTrigger=AGKVR.RightController_Trigger( )
	
	RightJoyX= AGKVR.RightController_JoyX( )
	RightJoyY= AGKVR.RightController_JoyY( )

	if  AGKVR.RightControllerFound( ) = 1
		SetObjectPosition( right_hand, AGKVR.GetRightHandX(), AGKVR.GetRightHandY(), AGKVR.GetRightHandZ())
		SetObjectRotation( right_hand, AGKVR.GetRightHandAngleX(), AGKVR.GetRightHandAngleY(), AGKVR.GetRightHandAngleZ())
		SetObjectAnimationFrame(Right_hand, GetObjectAnimationName( Right_hand, 1 ), GetObjectAnimationDuration(Right_hand,GetObjectAnimationName( Right_hand, 1 ))*RightTrigger,0)
		endif

	if  AGKVR.LeftControllerFound( ) = 1
		SetObjectPosition( left_hand, AGKVR.GetLeftHandX(), AGKVR.GetLeftHandY(), AGKVR.GetLeftHandZ())
		SetObjectRotation( left_hand, AGKVR.GetLeftHandAngleX(), AGKVR.GetLeftHandAngleY(), AGKVR.GetLeftHandAngleZ())
		SetObjectAnimationFrame(left_hand, GetObjectAnimationName( left_hand, 1 ), GetObjectAnimationDuration(left_hand,GetObjectAnimationName( left_hand, 1 ))*LeftTrigger,0)	
		
		
		
		
		endif


	Left_Hand_PosX=getobjectworldx(Left_Hand)
	Left_Hand_PosY=getobjectworldy(Left_Hand)
	Left_Hand_PosZ=getobjectworldz(Left_Hand)
	
	Left_Hand_AngleX=GetObjectWorldAngleX(Left_Hand)
	Left_Hand_Angley=GetObjectWorldAngley(Left_Hand)
	Left_Hand_Anglez=GetObjectWorldAnglez(Left_Hand)
	
	Right_Hand_PosX=getobjectworldX(Right_Hand)
	Right_Hand_PosY=getobjectworldY(Right_Hand)
	Right_Hand_PosZ=getobjectworldZ(Right_Hand)
	
	Right_Hand_AngleX=GetObjectWorldAngleX(Right_Hand)
	Right_Hand_AngleY=GetObjectWorldAngleY(Right_Hand)
	Right_Hand_AngleZ=GetObjectWorldAngleZ(Right_Hand)
	
	AGKVR.Render(  )
	
	SetCameraPosition( 1, AGKVR.GetHMDX(), AGKVR.GetHMDY(), AGKVR.GetHMDZ())
	SetCameraRotation( 1, AGKVR.GetHMDAngleX(), AGKVR.GetHMDAngleY(), AGKVR.GetHMDAngleZ())	
 	MoveCameraLocalZ(1,-1)

   ENDFUNCTION
   
_pos0:
SetObjectAnimationFrame(LEFT_HAND,"",1,0)
RotateObjectBoneLocaly(LEFT_HAND,10,-51)
return
