CyberCarsten
Nov 5th, 2000, 04:53 AM
Hi guys!
Can anyone please help me with my game........???
My game is a sort of pingpong, where a dropping line from the top of the screen(Line2) falls down, and the player has to catch it with a
line that lies down in the bottom of the screen(Line1), and add 1 to the variable HS(Highscore) when there is a successful catch, or reduce it by 1 if the player doesn't cath the falling line.
I have gotten this far, but when the timer, which makes line2 drop, has looped about 2 or 3 times, the line stays away for a few seconds,
and the HS variable is reduced by 1!!! Why is that??????
Here is the source code:
Dim Hs
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyRight: GoRight
Case vbKeyLeft: GoLeft
Case vbKeyEscape: End
End Select
End Sub
Sub GoRight()
Line1.X1 = Line1.X1 + 120
Line1.X2 = Line1.X2 + 120
End Sub
Sub GoLeft()
Line1.X1 = Line1.X1 - 120
Line1.X2 = Line1.X2 - 120
End Sub
Private Sub Timer1_Timer()
RndGenCoord = Int((12000 * Rnd) + 240) 'Generate random coordinates for line2
Line2.Y1 = Line2.Y1 + 120
Line2.Y2 = Line2.Y2 + 120
If CheckCatch = True Then
Hs = Hs + 1
Score.Caption = "Score: " & Hs
Timer1.Interval = 0
Timer1.Enabled = False
Line2.X1 = Line1.X1 + RndGenCoord
Line2.X2 = Line1.X1 + RndGenCoord
Line2.Y1 = 2280
Line2.Y2 = 2280
If Line2.X1 >= Me.ScaleWidth Or Line2.X1 <= 0 Then
Line2.X2 = Int(Me.ScaleWidth / 2)
Line2.X2 = Line2.X1
End If
Timer1.Interval = 25
Timer1.Enabled = True
End If
If Line2.Y1 > Line1.Y1 Then
'This is where the problem is.....
'Even if Line2.Y1 isn't greather than Line1.Y1 the followng code is executed
Hs = Hs - 1
Score.Caption = "Score: " & Hs
Timer1.Interval = 0
Timer1.Enabled = False
Line2.X1 = 4800
Line2.X2 = 4800
Line2.Y1 = 2280
Line2.Y2 = 2280
Timer1.Interval = 25
Timer1.Enabled = True
End If
End Sub
Private Function CheckCatch() As Boolean
If Line2.Y1 >= Line1.Y1 Then
If Line2.Y1 > Line1.Y1 Then
CheckCatch = False
Exit Function
End If
If (Line2.X1 >= Line1.X1 And Line2.X1 <= Line1.X2) Or _
(Line2.X2 >= Line1.X1 And Line2.X2 <= Line1.X2) Then _
CheckCatch = True
End If
End Function
Private Sub TitleTim1_Timer()
Title.ForeColor = &HFFFF&
TitleTim1.Enabled = False
TitleTim2.Enabled = True
End Sub
Private Sub TitleTim2_Timer()
Title.ForeColor = &HFF&
TitleTim1.Enabled = True
TitleTim2.Enabled = False
End Sub
[Edited by CyberCarsten on 11-05-2000 at 05:59 AM]
Can anyone please help me with my game........???
My game is a sort of pingpong, where a dropping line from the top of the screen(Line2) falls down, and the player has to catch it with a
line that lies down in the bottom of the screen(Line1), and add 1 to the variable HS(Highscore) when there is a successful catch, or reduce it by 1 if the player doesn't cath the falling line.
I have gotten this far, but when the timer, which makes line2 drop, has looped about 2 or 3 times, the line stays away for a few seconds,
and the HS variable is reduced by 1!!! Why is that??????
Here is the source code:
Dim Hs
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyRight: GoRight
Case vbKeyLeft: GoLeft
Case vbKeyEscape: End
End Select
End Sub
Sub GoRight()
Line1.X1 = Line1.X1 + 120
Line1.X2 = Line1.X2 + 120
End Sub
Sub GoLeft()
Line1.X1 = Line1.X1 - 120
Line1.X2 = Line1.X2 - 120
End Sub
Private Sub Timer1_Timer()
RndGenCoord = Int((12000 * Rnd) + 240) 'Generate random coordinates for line2
Line2.Y1 = Line2.Y1 + 120
Line2.Y2 = Line2.Y2 + 120
If CheckCatch = True Then
Hs = Hs + 1
Score.Caption = "Score: " & Hs
Timer1.Interval = 0
Timer1.Enabled = False
Line2.X1 = Line1.X1 + RndGenCoord
Line2.X2 = Line1.X1 + RndGenCoord
Line2.Y1 = 2280
Line2.Y2 = 2280
If Line2.X1 >= Me.ScaleWidth Or Line2.X1 <= 0 Then
Line2.X2 = Int(Me.ScaleWidth / 2)
Line2.X2 = Line2.X1
End If
Timer1.Interval = 25
Timer1.Enabled = True
End If
If Line2.Y1 > Line1.Y1 Then
'This is where the problem is.....
'Even if Line2.Y1 isn't greather than Line1.Y1 the followng code is executed
Hs = Hs - 1
Score.Caption = "Score: " & Hs
Timer1.Interval = 0
Timer1.Enabled = False
Line2.X1 = 4800
Line2.X2 = 4800
Line2.Y1 = 2280
Line2.Y2 = 2280
Timer1.Interval = 25
Timer1.Enabled = True
End If
End Sub
Private Function CheckCatch() As Boolean
If Line2.Y1 >= Line1.Y1 Then
If Line2.Y1 > Line1.Y1 Then
CheckCatch = False
Exit Function
End If
If (Line2.X1 >= Line1.X1 And Line2.X1 <= Line1.X2) Or _
(Line2.X2 >= Line1.X1 And Line2.X2 <= Line1.X2) Then _
CheckCatch = True
End If
End Function
Private Sub TitleTim1_Timer()
Title.ForeColor = &HFFFF&
TitleTim1.Enabled = False
TitleTim2.Enabled = True
End Sub
Private Sub TitleTim2_Timer()
Title.ForeColor = &HFF&
TitleTim1.Enabled = True
TitleTim2.Enabled = False
End Sub
[Edited by CyberCarsten on 11-05-2000 at 05:59 AM]