Results 1 to 3 of 3

Thread: Players?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Question

    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

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Guest
    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)

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width