'AccelBall
Sub Process_Globals
Dim Accelerometer As PhoneAccelerometer
Dim timer1 As Timer
Dim speed As Float
Dim position As Int
Dim positionY As Int
End Sub
Sub Globals
Dim can As Canvas
Dim rect1 As Rect
End Sub
Sub Activity_Create(FirstTime As Boolean)
If firstTime Then
timer1.Initialize("Timer1",30)
End If
positionY = 100%y - 100dip
can.Initialize(Activity)
can.DrawLine(0,positionY + 21dip, 100%x, positionY + 21dip,Colors.Red,1.0)
position = 50%x
rect1.Initialize(0, positionY - 20dip, 40dip, positionY + 20dip)
End Sub
Sub Activity_Resume
Accelerometer.StartListening("Accelerometer")
timer1.Enabled = True
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Accelerometer.StopListening
timer1.Enabled = False
End Sub
Sub Timer1_Tick
can.DrawCircle(position, positionY, 20dip, Colors.Black, True, 0)
activity.Invalidate2(rect1)
position = position + speed
If position > 100%x + 20dip Then position = -18dip
If position < -20dip Then position = 100%x + 18dip
rect1.Left = position - 20dip
rect1.Right = position + 40dip
can.DrawCircle(position, positionY, 20dip, Colors.White, True, 0)
activity.Invalidate2(rect1)
End Sub
Sub Accelerometer_AccelerometerChanged (X As Float, Y As Float, Z As Float)
speed = speed + Y * 0.5
End Sub