'–
'This textbox is a way to get the keyboard input
'for the game becuase:
' 1. When you hit the "START" button, it get's the focus
'(so the form no longer gets keydown events)
' 2. The Start Button does not get key-down events
'–
If (m_playfieldManager Is Nothing) Then
Return
End If
Dim i As Integer
i = e.KeyValue
Const PocketPC_BUTTON_PUSHED = 134
Const Keyboard_SPACE_PUSHED = 32
Const PocketPC_UP = 38
Const PocketPC_DOWN = 40
Const PocketPC_LEFT = 37
Const PocketPC_RIGHT = 39
Dim hank As HankTheWonderCaveman = _
m_playfieldManager.HankTheWonderCaveman
Const D_MOVEMENT = 14
Const D_MOVEMENT_UP = 70
If (i = PocketPC_BUTTON_PUSHED) Or _
(i = Keyboard_SPACE_PUSHED) Then
hank.MakeHankJump()
e.Handled = True
ElseIf (i = PocketPC_RIGHT) Then
hank.NudgeHanksDirection(D_MOVEMENT, 0)
ElseIf (i = PocketPC_LEFT) Then
hank.NudgeHanksDirection(-D_MOVEMENT, 0)
ElseIf (i = PocketPC_UP) Then
hank.NudgeHanksDirection(0, -D_MOVEMENT_UP)
ElseIf (i = PocketPC_DOWN) Then
hank.NudgeHanksDirection(0, D_MOVEMENT)
End If
TextBox1.Text = ""
End Sub
Дважды щёлкаем по значку для таймера Timer (или в панели Properties, для этого компонента, на вкладке Events дважды щёлкаем по имени соответствующего события). Появившийся шаблон метода после записи нашего кода принимает следующий вид.
Листинг 22.8. Метод, вызываемый таймером через каждый интервал Interval времени.
Private Sub timerGame_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles timerGame.Tick
' '–
' 'This timer is the heartbeat if the game.
' 'Every time it gets called we
' 'allow all of the game characters to move,
' 'we check for collisions beween objects,
' 'and we render the board to the screen.
' '–
'–
'If we are not running, exit the sub