
-----------------------------------
Armalite
Wed Jan 25, 2006 5:03 pm

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

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.

-----------------------------------
GlobeTrotter
Wed Jan 25, 2006 5:19 pm


-----------------------------------
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
Wed Jan 25, 2006 5:33 pm


-----------------------------------
Err...could you show me a simple example?

Sorry, but my VB skills are lacking.

-----------------------------------
codemage
Thu Jan 26, 2006 1:43 pm


-----------------------------------
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
Fri May 11, 2007 7:25 pm

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
Fri May 11, 2007 10:31 pm

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.

-----------------------------------
wargamer17
Sun May 13, 2007 5:46 pm

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.  :D

-----------------------------------
cool dude
Sun May 13, 2007 7:55 pm

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

-----------------------------------
wargamer17
Sun May 13, 2007 10:44 pm

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.
