PDA

Click to See Complete Forum and Search --> : Players?


Arie
Sep 11th, 2000, 02:15 PM
And one more thing, guys:
Is there any way to do many players playing?
I mean for example:
Player one holds the right arrow to move,
and Player two holds his move key.
Does this possible in VB?
In my way it shows that it can't be.
If you have a way, tell me, please...

Thank you anyway,
Arie.

Visit: http://www.nip.to/camel2000

HarryW
Sep 12th, 2000, 11:30 AM
I haven't seen your way, so I'm going to make some assumptions about this.

If each player is an object, you can add the players to a collection, and then have a For Each...Next loop inside/outside your main game loop, so that each player is given a turn. Assign the player's control keys as true or false in an array of booleans (a member variable of the player object, or somewhere within the object model of a player) which flag each of the player's control keys as up or down. Set them to true on the KeyDown event and False on the KeyUp Event.

How's that? I haven't actually done anything like this before but I'm guessing that would work :)

Sep 12th, 2000, 03:12 PM
If you are referring to multiple keypresses, then GetAsyncKeyState will do the trick.

Add the following code to a Form with 2 PictureBoxes and a Timer. (I am assuming that player1 uses the Up Arrow key to move and player2 uses W to move)


Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Form_Load()
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
'Move player1
If GetAsyncKeyState(vbKeyUp) Then Picture1.Top = Picture1.Top - 10
'Move player2
If GetAsyncKeyState(vbKeyW) Then Picture2.Top = Picture2.Top - 10
End Sub