Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Two Player Same Keyboard?
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
Armalite




PostPosted: Wed Jan 25, 2006 5:03 pm   Post subject: Two Player Same Keyboard?

Hey guys, i'm having problems making a game that uses two players on the same keyboard.

My problem is that I can only have one player moving at a time if they are holding the key down.

One player can hold up and move constantly but the second player cannot.

They can both however, frequently press a button and move in smaller, slower, increments.

I've looked at other sources and I just can't find a solution.

Right now a sample of my movement looks like this:

Select Case KeyCode

code:
Case vbKeyUp
If playerOne.Top > 0 Then
playerOne.Top = playerOne.Top - 10
Else
End If

Case vbKeyDown
If playerOne.Top < 900 Then
playerOne.Top = playerOne.Top + 10
Else
End If
End Select

Select Case KeyCode
Case vbKeyW
If playerTwo.Top > 0 Then
playerTwo.Top = playerTwo.Top - 10
Else
End If

Case vbKeyS
If playerTwo.Top < 900 Then
playerTwo.Top = playerTwo.Top + 10
Else
End If
End Select


That is just for the first player moving up and down using arrow keys and the second player moving up and down using W and S.

Any help would be appreciated.
 
Sponsor
Sponsor
Sponsor
sponsor
GlobeTrotter




PostPosted: Wed Jan 25, 2006 5:19 pm   Post subject: (No subject)

Maybe you could have an array 0 .. 255 of boolean representing which keys are being pressed.

In the keyDown event, loop through and update any keys that are pressed.

Then in a timer event, use your boolean array to move your characters.
 
Armalite




PostPosted: Wed Jan 25, 2006 5:33 pm   Post subject: (No subject)

Err...could you show me a simple example?

Sorry, but my VB skills are lacking.
 
codemage




PostPosted: Thu Jan 26, 2006 1:43 pm   Post subject: (No subject)

Doing it in case might mean that only one key can be pressed at a time. (Not quite sure, since I can't see your whole setup).

Do it case independently.

As well, be aware that most cheap keyboards will only record about 4 keys pressed at the same time.
 
wargamer17




PostPosted: Fri May 11, 2007 7:25 pm   Post subject: Re: Two Player Same Keyboard?

Hey, i know this was a topic from about a year ago, but i have the same problem. I am trying to get two player working in my game, but i can't seem to follow what is being said here. My teacher had the same idea as the post above with the use of a timer, but it doesn't make sense to me. Can someone please help me with this two player thing? i need this in about 3 days max.

thanks in advance!
 
cool dude




PostPosted: Fri May 11, 2007 10:31 pm   Post subject: Re: Two Player Same Keyboard?

In the case of the topic being so old you should just start a new topic. Now i know exactly what your teacher meant by using a timer and i attached sample code to show you an example.


FIGHT_~1.FRM
 Description:

Download
 Filename:  FIGHT_~1.FRM
 Filesize:  1.93 KB
 Downloaded:  227 Time(s)

 
wargamer17




PostPosted: Sun May 13, 2007 5:46 pm   Post subject: Re: Two Player Same Keyboard?

Thank you so much for this help!! it is greatly appreciated! The only reason why i asked in this topic was because usually when i create a new topic and that topic was already asked i get yelled at and told to put it in one that had the same topic, so that is why i put it in this one. But yes, thank you for the help. Very Happy
 
cool dude




PostPosted: Sun May 13, 2007 7:55 pm   Post subject: Re: Two Player Same Keyboard?

no problem mate. glad i can help. Don't pay attention to the idiots that yell at you for starting a new topic instead of posting in a really old one.

If you have anymore questions feel free to ask
 
Sponsor
Sponsor
Sponsor
sponsor
wargamer17




PostPosted: Sun May 13, 2007 10:44 pm   Post subject: Re: Two Player Same Keyboard?

Alright, i won't worry about them. I will hopefully post my program in the submission forum when the project is done.
 
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: