Results 1 to 8 of 8

Thread: collision detection helpp!!!!!!!

  1. #1

    Thread Starter
    Hyperactive Member dflw's Avatar
    Join Date
    Apr 2001
    Location
    ct, usa
    Posts
    412

    collision detection helpp!!!!!!!

    ok, say i have a picture that moves around a form using the arrow keys. I also have another fixed picture in the center of the form. They are both rectangular....how do i detect a collision between the two images? and how do i make the picture that moves stop when it hits the other fixed picture???

    thanks in advance
    Visual Basic 6, HTML, JavaScript, learning C++

  2. #2
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    You could say:

    Code:
    If KeyCode = vbKeyLeft Then
       If Picture1.Left > Picture2.Left + Picture2.Width Then
          Picture1.Left = Picture1.Left - 5
       End If
    End If
    
    If KeyCode = vbKeyRight Then
       If Picture1.Left + Picture1.Width < Picture2.Left Then
          Picture1.Left = Picture1.Left + 5
       End If
    End If
    
    If KeyCode = vbKeyUp Then
       If Picture1.Top > Picture2.Top + Picture2.Height Then
          Picture1.Top = Picture1.Top - 5
       End If
    End If
    
    If KeyCode = vbKeyDown Then
       If Picture1.Top + Picture1.Height < Picture2.Top Then
          Picture1.Top = Picture1.Top + 5
       End If
    End If
    I am assuming that picture2 is the static picture box
    Last edited by hypnos; Jul 26th, 2001 at 02:54 PM.

  3. #3

    Thread Starter
    Hyperactive Member dflw's Avatar
    Join Date
    Apr 2001
    Location
    ct, usa
    Posts
    412
    thankssss!!!! now how do i move a picture using the arrow keys? i used to have the code but its lost in my hdd....
    Visual Basic 6, HTML, JavaScript, learning C++

  4. #4
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    do you mean move a picture inside the picture box?

  5. #5
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    BTW, that collision code is in no way fit for use. I just typed it up really quickly while in this forum. It should give you the idea though, which is what I was intending to do.

  6. #6

    Thread Starter
    Hyperactive Member dflw's Avatar
    Join Date
    Apr 2001
    Location
    ct, usa
    Posts
    412
    well, i get the idea.....but how do you move a picture with arrow keys?
    Visual Basic 6, HTML, JavaScript, learning C++

  7. #7
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    If you want to move a picture box with the arrow keys add this code:

    Code:
    Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyLeft Then Picture1.Left = Picture1.Left - 20
        If KeyCode = vbKeyRight Then Picture1.Left = Picture1.Left + 20
        If KeyCode = vbKeyUp Then Picture1.Top = Picture1.Top - 20
        If KeyCode = vbKeyDown Then Picture1.Top = Picture1.Top + 20
    End Sub

    is that what you wanted?

  8. #8

    Thread Starter
    Hyperactive Member dflw's Avatar
    Join Date
    Apr 2001
    Location
    ct, usa
    Posts
    412
    yep, i had something like that but it didnt work..thanks for the help
    Visual Basic 6, HTML, JavaScript, learning C++

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