Results 1 to 2 of 2

Thread: Could anyone please help me with my game.........

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Unhappy

    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:

    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]
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Junior Member
    Join Date
    Oct 2000
    Posts
    29

    Exclamation Take this !!

    Please use this cleaned code for Your game !!

    Code:
    Option Explicit
    
    Private Hs As Integer
    Private RndGenCoord As Integer
    
    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
    
      If Line2.Visible Then
        Line2.Y1 = Line2.Y1 + 120
        Line2.Y2 = Line2.Y2 + 120
      End If
    
      If CheckCatch 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
        Line2.Visible = False
      End If
    
      If Line2.Y1 > Line1.Y1 And Line2.Visible = True And CheckCatch = False Then
        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
        Line2.Visible = False
      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
    Greetings, MAJA.

    [Edited by majasoft on 11-06-2000 at 10:29 AM]
    VB and Java are great - ja, so ist es !! To my software programming site: http://www.majasoft-games.de .

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