Ping Pong


Public counter As Integer, direction As String

 
Private Sub cmdDown_Click()
cmdDown.Tag
End Sub

Private Sub Form_Load()
For T = Line1.LBound To Line1.UBound
    Let Line1(T).X1 = Main.Width / 2
    Let Line1(T).X2 = Main.Width / 2
Next T
counter = 0

End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Const Inc = 1

If KeyCode = Asc(“A”) Or KeyCode = Asc(“a”) Then
    Let Shape2.Top = Shape2.Top – Inc
    If Shape2.Top < 0 Then Let Shape2.Top = 0
End If
If KeyCode = Asc(“Z”) Or KeyCode = Asc(“z”) Then
    Let Shape2.Top = Shape2.Top + Inc
    If Shape2.Top > 4920 Then Let Shape2.Top = 4920
End If
If KeyCode = Asc(“P”) Or KeyCode = Asc(“p”) Then
    Let Shape1.Top = Shape1.Top – Inc
    If Shape1.Top < 0 Then Let Shape1.Top = 0
End If
If KeyCode = Asc(“L”) Or KeyCode = Asc(“l”) Then
    Let Shape1.Top = Shape1.Top + Inc
    If Shape1.Top > 4920 Then Let Shape1.Top = 4920
End If
If KeyCode = Asc(“q”) Or KeyCode = Asc(“Q”) Then
End
End If
If KeyCode = Asc(“c”) Or KeyCode = Asc(“C”) Then
frmCredits.Show
Timer1.Enabled = False

End If

Let Text1.Text = “”
counter = 0
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
counter = -1
End Sub

Private Sub Timer1_Timer()
Let speed = Val(Shape3.Tag)
Let Vspeed = Val(Text1.Tag)
Const Vmax = 220

If speed = 0 Then Let speed = 250
If Vspeed = 0 Then Let Vspeed = 110

Let Shape3.Left = Shape3.Left + speed
Let Shape3.Top = Shape3.Top + Vspeed

If ((Shape3.Left + Shape3.Width) > Shape1.Left) And (Shape3.Top > Shape1.Top) And (Shape1.Top + Shape1.Height > Shape3.Top) Then
    If (Shape3.Left > (Shape1.Left + Shape1.Width)) Then
        Let Label2.Caption = Val(Label2.Caption) + 1
        Let Shape3.Left = Main.Width / 2
        Shape1.Top = Main.Height / 2
        Shape2.Top = Main.Height / 2
        counter = -1
        MsgBox “You lose, but it was close”
    End If
    Let speed = -speed
   
    If Vspeed > 0 Then Let Vspeed = -Int(Rnd * Vmax)
    If Vspeed < 0 Then Let Vspeed = Int(Rnd * Vmax)
End If

If ((Shape3.Left) < (Shape2.Left + Shape2.Width)) And Shape3.Top > Shape2.Top And Shape2.Top + Shape2.Height > Shape3.Top Then
    If (Shape3.Left < (Shape2.Left)) Then
   
        Let Label1.Caption = Val(Label1.Caption) + 1
        Let Shape3.Left = Main.Width / 2
        Shape2.Top = Main.Height / 2
        Shape1.Top = Main.Height / 2
        counter = -1
        MsgBox “You lose, but it was close”
    End If
    Let speed = -speed
   
    If Vspeed > 0 Then Let Vspeed = -Int(Rnd * Vmax)
    If Vspeed < 0 Then Let Vspeed = Int(Rnd * Vmax)
End If

If Shape3.Left > Main.Width Then
    Let Label2.Caption = Val(Label2.Caption) + 1
    Let Shape3.Left = Main.Width / 2
    MsgBox “Another Point For The guy on the Left”
    Let Shape3.Left = Main.Width / 2
        Shape2.Top = Main.Height / 2
        Shape1.Top = Main.Height / 2
End If

If Shape3.Left < 0 Then
    Let Label1.Caption = Val(Label1.Caption) + 1
    Let Shape3.Left = Main.Width / 2
    MsgBox “Another Point For The guy on the Right”
    Let Shape3.Left = Main.Width / 2
        Shape2.Top = Main.Height / 2
        Shape1.Top = Main.Height / 2
End If

If Shape3.Top < 0 Then
    Let Vspeed = -Vspeed
    Let Shape3.Top = 0
End If

If Shape3.Top > 5400 Then
    Let Vspeed = -Vspeed
    Let Shape3.Top = 5400
End If

Let Shape3.Tag = speed
Let Text1.Tag = Vspeed

Inc = 245

If (speed > 0) Then
    direction = “Right”
ElseIf (speed < 0) Then
    direction = “Left”
End If

 

If (counter <> -1) Then
    If (direction = “Left”) Then
        If Text1.Text = “A” Or Text1.Text = “a” Then
            Let Shape2.Top = Shape2.Top – Inc
            If Shape2.Top < 0 Then Let Shape2.Top = 0
        End If
        If Text1.Text = “Z” Or Text1.Text = “z” Then
            Let Shape2.Top = Shape2.Top + Inc
            If Shape2.Top > 4920 Then Let Shape2.Top = 4920
        End If
    ElseIf (direction = “Right”) Then
        If Text1.Text = “P” Or Text1.Text = “p” Then
            Let Shape1.Top = Shape1.Top – Inc
            If Shape1.Top < 0 Then Let Shape1.Top = 0
        End If
        If Text1.Text = “L” Or Text1.Text = “l” Then
            Let Shape1.Top = Shape1.Top + Inc
            If Shape1.Top > 4920 Then Let Shape1.Top = 4920
        End If
    End If
End If
End Sub

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s