![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 8
Rep Power: 0
![]() |
Using keyboard buttons in VB 6.0 Prog
I'm writing a game which currently has a moving road and a stationary car. the road has obsticles which I would like to able to avoid using the up/down buttons on my keyboard. Can anyone help me to code this in? All help and any sample code is appreciated.
|
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Welcome!
This is from an RPG that a made last year in VB back when I started learning how to program. Hopefully this helps. It was just ripped out of my game. -> Private Sub Form_KeyDown(KeyCode As Integer, shift As Integer)
Randomize
'lblTips.ZOrder 1000
If intCharacterCurrentXp <> 0 Then
'''''''''''''''''''''' up key ''''''''''''''''''''
If KeyCode = vbKeyUp Then
Character.Top = Character.Top - 900
If blnFight = True Then
Call FightRandomization
End If
End If
'''''''''''''''''''''''' down key '''''''''''''''''''''
If KeyCode = vbKeyDown Then
Character.Top = Character.Top + 900
If blnFight = True Then
Call FightRandomization
End If
End If
''''''''''''''''''''''' left key '''''''''''''''''''
If KeyCode = vbKeyLeft Then
Character.Picture = LoadPicture(App.Path & "\character1.gif")
Character.Left = Character.Left - 840
If blnFight = True Then
Call FightRandomization
End If
End If
'''''''''''''''''''''''right key ''''''''''''
If KeyCode = vbKeyRight Then
Character.Picture = LoadPicture(App.Path & "\character2.gif")
Character.Left = Character.Left + 840
If blnFight = True Then
Call FightRandomization
End If
End If
'**************************************** Collision detection *********************
If Character.Left < 0 Then
Character.Left = 0
ElseIf Character.Left > Me.ScaleWidth - 800 Then
Character.Left = Me.ScaleWidth - 800
End If
If Character.Top < 0 Then
Character.Top = 0
ElseIf Character.Top > Me.ScaleHeight - 1000 Then
Character.Top = Me.ScaleHeight - 1000
End If
'Print intFight
End If
'************************************** end of collision detection ******************8
End Sub
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2006
Posts: 8
Rep Power: 0
![]() |
thanks a lot Eric. I have it working now, except for the part where I'm having trouble setting boundaries. How can I get the character to stop moving up (while I continue to push the up button) when it reaches the edge of the road? Is there a way to disable the button?
|
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Quote:
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
|
#5 | |
|
Newbie
Join Date: May 2006
Posts: 8
Rep Power: 0
![]() |
Quote:
Oh, haha ... duh! Stupid me. Thanks again. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|