dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] VB6 Collision detection help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Resolved [RESOLVED] VB6 Collision detection help

    Hi,
    I am currently making a 2D side-scrolling game as part of my A-level computing project, but i cannot figure out how to make collision detection.

    This is the code i have at the moment,
    I have an array of lines to outline the ground, called line and an image of the character, called character.

    Public Function Collision() As Boolean
    For i = 0 To 50
    If (Charcater.Top + Charcater.Height) >= Line(i).Top Then
    Collision = True
    Else
    Collision = False
    End If
    Next i
    End Function

    This function is then used in the games main timer

    If Collision = True Then
    Charcater.Top = Charcater.Top
    Else
    Do
    Charcater.Top = Character.Top + 10 + Screen.TwipsPerPixelY
    Loop Until (Charcater.Top + Charcater.Height) >= Line(i).Top

    my problem is that every time i try to run the game i get 'Argument not Optional' and it highlights 'Line' in the function
    can someone please solve this, I am fairly new to VB so forgive me if this is a stupid question.

    Thanks in advance

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: VB6 Collision detection help

    Quote Originally Posted by cozzeh View Post
    my problem is that every time i try to run the game i get 'Argument not Optional' and it highlights 'Line' in the function
    Line is a method of the Form.

    Quote Originally Posted by MSDN
    If object is omitted, the Form with the focus is assumed to be object.
    Rename your Line array to something else.

    Quote Originally Posted by cozzeh View Post
    ... and an image of the character, called character.

    Code:
             If (Charcater.Top + Charcater.Height) >= Line(i).Top Then
    
        Charcater.Top = Charcater.Top
    
         Charcater.Top = Character.Top + 10 + Screen.TwipsPerPixelY  '<-- Should be (10 * Screen.TwipsPerPixelY)
       Loop Until (Charcater.Top + Charcater.Height) >= Line(i).Top
    Obviously, you don't have Option Explicit enabled. Just do a search on Option Explicit to see why it's very important.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: VB6 Collision detection help

    Cozzeh

    Just to enhance upon Bonnie's observations ..

    1. Line .. Line is a "reserved word" in VB6. Using it for an array name "confuses" VB
    2. Character .. You seem to have a spelling error .. Character and Charcater.

    Spoo

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 Collision detection help

    thanks for your replies, you've just saved my coursework.

  5. #5
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,256

    Re: VB6 Collision detection help

    If you need more advanced collision techniques let me know. I got a nice one in my signature based on rigid body kinematics. Also note its never wise to use a Timer when making games

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width