0 Replies - 1072 Views - Last Post: 10 January 2014 - 06:36 AM Rate Topic: -----

#1 flare123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-January 14

Need help with Pong game

Posted 10 January 2014 - 06:36 AM

So, I'm making a pong game with the ball as Shape1.shape , the pedals as shape2.shape and shape3.shape. There is a problem with my 3rd bounce which the ball doesn't need to touch the pedal to bounce then goes through the pedal.Here are the codes.

Dim wkey As Boolean
Dim skey As Boolean
Dim ukey As Boolean
Dim dkey As Boolean
Dim xspeed As Integer
Dim yspeed As Integer


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyW
wkey = True
Case vbKeyS
skey = True
Case vbKeyUp
ukey = True
Case vbKeyDown
dkey = True
End Select
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyW
wkey = False
Case vbKeyS
skey = False
Case vbKeyUp
ukey = False
Case vbKeyDown
dkey = False
End Select
End Sub

Private Sub Form_Load()
MsgBox "2 Player Pong game. W and S for player 1, Up and Down for player 2."
xspeed = 75
yspeed = 75
End Sub

Private Sub Timer1_Timer()
If wkey Then Shape2.Top = Shape2.Top - 100
If skey Then Shape2.Top = Shape2.Top + 100

If Shape2.Top <= 0 Then Shape2.Top = 0
If Shape2.Top + Shape2.Height >= Form1.Height Then Shape2.Top = Form1.Height - Shape2.Height
End Sub

Private Sub Timer2_Timer()
If ukey Then Shape3.Top = Shape3.Top - 100
If dkey Then Shape3.Top = Shape3.Top + 100

If Shape3.Top <= 0 Then Shape3.Top = 0
If Shape3.Top + Shape3.Height >= Form1.Height Then Shape3.Top = Form1.Height - Shape3.Height
End Sub

Private Sub Timer4_Timer()
Shape1.Top = Shape1.Top + yspeed
Shape1.Left = Shape1.Left + xspeed

If Shape2.Left <= Shape1.Left + Shape1.Width Then "this is the problem."
If Shape2.Left + Shape2.Width >= Shape1.Left Then
If Shape2.Top <= Shape1.Left + Shape1.Width Then
If Shape2.Top + Shape2.Height >= Shape1.Top Then

xspeed = xspeed * -1
yspeed = yspeed * Rnd

End If
End If
End If
End If


If Shape3.Left <= Shape1.Left + Shape1.Width Then
If Shape3.Left + Shape3.Width >= Shape1.Left Then
If Shape3.Top <= Shape1.Left + Shape1.Width Then
If Shape3.Top + Shape3.Height >= Shape1.Top Then

xspeed = xspeed * -1
yspeed = yspeed * Rnd

End If
End If
End If
End If

If Shape1.Top <= 0 Then
yspeed = yspeed * -1
End If

If Shape1.Top + Shape1.Height >= Form1.Height Then
yspeed = yspeed * -1
End If

If Shape1.Left <= 0 Then
MsgBox "Player 2 win!"
End
End If

If Shape1.Left + Shape1.Width >= Form1.Width Then
MsgBox "Player 1 win!"
End
End If
End Sub



Is This A Good Question/Topic? 0
  • +

Page 1 of 1