Sub Process_Globals
Private timer1 As Timer
Private smiley As BitmapData
Private boxSize As Int = 50dip
Private StartTime As Long
Private Const Duration As Int = 5000
Private Const NumberOfLoops As Float = 5
Private smileyX, smileyY As Float
Private centerX, centerY As Float
Private radiusStart As Float
Private angleOffset As Float
End Sub
Sub Globals
Private gv As GameView
End Sub
Sub Activity_Create(FirstTime As Boolean)
gv.Initialize("gv")
If FirstTime Then
timer1.Initialize("timer1", 16)
smiley.Bitmap = LoadBitmap(File.DirAssets, "smiley.png")
centerX = 50%x
centerY = 50%y
smileyX = centerX
smileyY = centerY
smiley.DestRect.Initialize(0, 0, 0, 0)
End If
Activity.AddView(gv, 0, 0, 100%x, 100%y)
gv.BitmapsData.Add(smiley)
timer1.Enabled = True
End Sub
Sub gv_Touch (Action As Int, X As Float, Y As Float)
smileyX = X
smileyY = Y
If Action = Activity.ACTION_MOVE Then
StartTime = 0
Else If Action = Activity.ACTION_UP Then
StartTime = DateTime.Now
Dim dx As Float = smileyX - centerX
Dim dy As Float = smileyY - centerY
radiusStart = Sqrt(Power(dx, 2) + Power(dy, 2))
angleOffset = ATan2(dy, dx)
End If
End Sub
Sub Timer1_Tick
If StartTime > 0 And DateTime.Now < StartTime + Duration Then
Dim t As Float = (DateTime.Now - StartTime) / Duration
Dim angle As Float = angleOffset + NumberOfLoops * 2 * cPI * t
Dim radius As Float = radiusStart - radiusStart * t
smileyX = centerX + radius * Cos(angle)
smileyY = centerY + radius * Sin(angle)
smiley.Rotate = angle * 180 / cPI
End If
smiley.DestRect.Left = smileyX - boxSize
smiley.DestRect.Right = smileyX + boxSize
smiley.DestRect.Top = smileyY - boxSize
smiley.DestRect.Bottom = smileyY + boxSize
gv.Invalidate
End Sub