'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim cursor As Rect 'rect we can move around
Dim target As Rect 'rect to collide with
Dim can1 As Canvas
End Sub
Sub Activity_Create(FirstTime As Boolean)
'activity.LoadLayout("main")
can1.Initialize(activity)
target.Initialize((activity.Width/2) - 30dip,(activity.height/2) - 30dip,(activity.Width/2) + 30dip,(activity.height/2) + 30dip)
cursor.Initialize((activity.Width/2) - 10dip,(activity.height/2) - 10dip,(activity.Width/2) + 10dip,(activity.height/2) + 10dip)
can1.DrawRect(target,Colors.White,False,2dip)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
If action = activity.ACTION_MOVE Then
'position cursor rect on move event
cursor.Left = x - 25dip
cursor.Right = x + 25dip
cursor.Top = y - 25dip
cursor.Bottom = y + 25dip
'clear and draw
can1.DrawColor(Colors.black)
can1.DrawRect(cursor,Colors.Green,False,2dip)
col = collision_check(cursor,target)
If col = True Then
target.Left = x - 30dip
target.Right = x + 30dip
target.Top = y - 30dip
target.Bottom = y + 30dip
can1.DrawRect(target,Colors.Red,True,2dip)
End If
can1.DrawRect(target,Colors.White,False,2dip)
activity.Invalidate
End If
End Sub
Sub Activity_Click
End Sub
Sub Activity_LongClick
End Sub
Sub collision_check(obj1 As Rect,obj2 As Rect) As Boolean
'simple box collision check
'all 4 checks have to occur to return True
If obj1.Bottom < obj2.Top Then
Return(False)
End If
If obj1.Top > obj2.Bottom Then
Return(False)
End If
If obj1.Right < obj2.Left Then
Return(False)
End If
If obj1.Left > obj2.Right Then
Return(False)
End If
Return(True)
End Sub