|
-
Jan 19th, 2000, 03:46 AM
#1
Thread Starter
Hyperactive Member
I made the old version of pong just one problem. When player one clicks a key to move his bar and then player two hits his key player one's stops moving. Is there a way to make vb detect to keycodes or keyascii and do them both. I have tried many ways so please help. Here is my code just in case it can help.
Code:
Option Explicit
Dim a As Integer
Dim f As Integer
Dim speed As Integer
Dim g As Integer
Dim b As Integer
Private Sub bottom_Timer()
If Shape1.Top > 7960 Then
If Timer1.Enabled = True Then
Timer3.Enabled = True
Timer1.Enabled = False
End If
If Timer6.Enabled = True Then
Timer7.Enabled = True
Timer6.Enabled = False
End If
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
a = KeyCode
Select Case a
Case 16
If Shape2.Top < 185 Then
Shape2.Move Shape2.Left + 0, Shape2.Top + 0
Else
Shape2.Move Shape2.Left, Shape2.Top - 300
End If
Case 17
If Shape2.Top > 5870 Then
Shape2.Move Shape2.Left + 0, Shape2.Top + 0
Else
Shape2.Move Shape2.Left, Shape2.Top + 300
End If
End Select
b = KeyCode
Select Case b
Case 38
If Shape3.Top < 185 Then
Shape3.Move Shape3.Left + 0, Shape3.Top + 0
Else
Shape3.Move Shape3.Left, Shape3.Top - 300
End If
Case 40
If Shape3.Top > 5870 Then
Shape3.Move Shape3.Left + 0, Shape3.Top + 0
Else
Shape3.Move Shape3.Left, Shape3.Top + 300
End If
End Select
End Sub
Private Sub Form_Load()
g = 200
f = 200
speed = 10
Label2.Caption = speed
End Sub
Private Sub Left_Timer()
If Shape1.Left < 480 And Shape1.Top > (Shape2.Top - Shape1.Height) And Shape1.Top < (Shape2.Top + Shape2.Height) Then
If Shape1.Left > 0 Then
If Timer7.Enabled = True Then
Timer3.Enabled = True
Timer7.Enabled = False
f = f + 10
g = g + 10
speed = speed + 10
End If
If Timer6.Enabled = True Then
Timer1.Enabled = True
Timer6.Enabled = False
f = f + 10
g = g + 10
speed = speed + 10
End If
End If
Label2.Caption = speed
End If
End Sub
Private Sub Right_Timer()
If Shape1.Left > 12100 And Shape1.Top > (Shape3.Top - Shape1.Height) And Shape1.Top < (Shape3.Top + Shape3.Height) Then
If Shape1.Left < 12500 Then
If Timer3.Enabled = True Then
Timer7.Enabled = True
Timer3.Enabled = False
f = f + 10
g = g + 10
speed = speed + 10
End If
If Timer1.Enabled = True Then
Timer6.Enabled = True
Timer1.Enabled = False
f = f + 10
g = g + 10
speed = speed + 10
End If
End If
Label2.Caption = speed
End If
End Sub
Private Sub Timer1_Timer()
Shape1.Move Shape1.Left + f, Shape1.Top + g
End Sub
Private Sub Timer3_Timer()
Shape1.Move Shape1.Left + f, Shape1.Top - g
End Sub
Private Sub Timer6_Timer()
Shape1.Move Shape1.Left - f, Shape1.Top + g
End Sub
Private Sub Timer7_Timer()
Shape1.Move Shape1.Left - f, Shape1.Top - g
End Sub
Private Sub Top_Timer()
If Shape1.Top < 300 Then
If Timer3.Enabled = True Then
Timer1.Enabled = True
Timer3.Enabled = False
End If
If Timer7.Enabled = True Then
Timer6.Enabled = True
Timer7.Enabled = False
End If
End If
End Sub
Thanks
------------------
Sincerely,
Chris
:-) ;-)
Email [email protected]
-
Jan 19th, 2000, 04:08 AM
#2
Use a Timer Control with the GetAsyncKeyState API, which can register Multiple Keystrokes.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 19th, 2000, 04:10 AM
#3
Thread Starter
Hyperactive Member
How would I go about doing that? I am not good with api coding. Please help!!!!!!!!!!
------------------
Sincerely,
Chris
:-) ;-)
Email [email protected]
-
Jan 19th, 2000, 04:24 AM
#4
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(16) Then
If Shape2.Top < 185 Then
Shape2.Move Shape2.Left + 0, Shape2.Top + 0
Else
Shape2.Move Shape2.Left, Shape2.Top - 300
End If
End If
If GetAsyncKeyState(17) Then
If Shape2.Top > 5870 Then
Shape2.Move Shape2.Left + 0, Shape2.Top + 0
Else
Shape2.Move Shape2.Left, Shape2.Top + 300
End If
End If
If GetAsyncKeyState(38) Then
If Shape3.Top < 185 Then
Shape3.Move Shape3.Left + 0, Shape3.Top + 0
Else
Shape3.Move Shape3.Left, Shape3.Top - 300
End If
End If
If GetAsyncKeyState(40) Then
If Shape3.Top > 5870 Then
Shape3.Move Shape3.Left + 0, Shape3.Top + 0
Else
Shape3.Move Shape3.Left, Shape3.Top + 300
End If
End If
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 20th, 2000, 03:14 AM
#5
Thread Starter
Hyperactive Member
Thank You it worked great!!!
------------------
Sincerely,
Chris
:-) ;-)
Email [email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|