Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 17th, 2006, 5:53 PM   #1
Rath72
Newbie
 
Join Date: May 2006
Posts: 8
Rep Power: 0 Rath72 is on a distinguished road
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.
Rath72 is offline   Reply With Quote
Old May 17th, 2006, 6:20 PM   #2
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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.
Eric the Red is offline   Reply With Quote
Old May 18th, 2006, 4:27 PM   #3
Rath72
Newbie
 
Join Date: May 2006
Posts: 8
Rep Power: 0 Rath72 is on a distinguished road
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?
Rath72 is offline   Reply With Quote
Old May 18th, 2006, 5:25 PM   #4
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by Rath72
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?
Well.. in the code I gave you it includes collision detection. So you shouldn't have any problems if you bothered to read the code.
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 18th, 2006, 10:19 PM   #5
Rath72
Newbie
 
Join Date: May 2006
Posts: 8
Rep Power: 0 Rath72 is on a distinguished road
Quote:
Originally Posted by Eric the Red
Well.. in the code I gave you it includes collision detection. So you shouldn't have any problems if you bothered to read the code.

Oh, haha ... duh! Stupid me. Thanks again.
Rath72 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC