#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
Sub Process_Globals
Private restart As Boolean = False
End Sub
Sub Globals
'BLUE PANEL
Private pMain As Panel
'RED PANEL
Private pLeft As Panel
Private pRight As Panel
'EYES
Private pRightEye As Panel
Private pLeftEye As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub pMain_Touch (Action As Int, X As Float, Y As Float)
Select Action
Case Activity.ACTION_DOWN
Case Activity.ACTION_MOVE
If restart Then Return 'IF IS RESTARTING TO CENTER, WAIT FOR IT
Private positionXPercentage As Int = x / pMain.Width * 100 'GET %x OF TOUCH
Private positionYPercentage As Int = y / pMain.Height * 100 'GET %y OF TOUCH
If positionXPercentage >= 0 And positionXPercentage <= 100 Then 'SEND THE % TOUCH AS X
MoveHorizontal(pLeft,pRight,positionXPercentage)
End If
If positionYPercentage >= 0 And positionYPercentage <= 100 Then 'SEND THE % TOUCH AS Y
MoveVertical(pLeft,pRight,positionYPercentage)
End If
Case Activity.ACTION_UP 'RESTART THE EYES TO CENTER POSITION
moveBack(pLeft,pRight,50,50)
End Select
End Sub
Sub MoveHorizontal(p1 As Panel, p2 As Panel,x As Int)
Private positionx1 As Int = x * p1.Width / 100 'CONVERT % TO FLOAT
Private positionx2 As Int = x * p2.Width / 100 'CONVERT % TO FLOAT
pLeftEye.Left = positionx1 - (pLeftEye.Width/2)
pRightEye.Left = positionx2 - (pRightEye.Width/2)
End Sub
Sub MoveVertical(p1 As Panel, p2 As Panel ,y As Int)
Private positionY1 As Int = Y * p1.Height / 100 'CONVERT % TO FLOAT
Private positionY2 As Int = Y * p2.Height / 100 'CONVERT % TO FLOAT
pLeftEye.Top = positionY1 - (pLeftEye.Height/2)
pRightEye.Top = positionY2 - (pRightEye.Height/2)
End Sub
Sub moveBack(p1 As Panel, p2 As Panel,x As Int, y As Int) 'RESTART TO ORIGINAL POSITION (CENTER)
restart = True
Private positionx1 As Int = x * p1.Width / 100 'CONVERT % TO FLOAT
Private positionx2 As Int = x * p2.Width / 100 'CONVERT % TO FLOAT
Private positionY1 As Int = Y * p1.Height / 100 'CONVERT % TO FLOAT
Private positionY2 As Int = Y * p2.Height / 100 'CONVERT % TO FLOAT
pLeftEye.SetLayoutAnimated(500,positionx1 - (pLeftEye.Width/2), positionY1 - (pLeftEye.Height/2),pLeftEye.Width,pLeftEye.Height)
pRightEye.SetLayoutAnimated(500,positionx2 - (pRightEye.Width/2), positionY2 - (pRightEye.Height/2),pRightEye.Width,pRightEye.Height)
Sleep(500)
restart = False
End Sub