Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

need help for hit detection , urgent!!!!!!!

DSYLTDSYLT Posts: 1Member
im making a shooting program for my exam , and i need to know how to detect collitions between 2 images i have this code :

If imgBullet.Left = imgTarget.Left 'to' (imgTarget.left + imgTarget.Width) & imgBullet.Top = imgTarget.Top 'to' (imgTarget.Top + imgTarget.Height) Then
score = score + 1
Me.Caption = score
Timer3.Enabled = True



im trying to give parameters , so that the hit counts if the bullet passes on any part of the picture and the 'to' 's represent that part in the code for i don't know how to do it , if any body knows or has an other solution to my problem , plz let me know as soon as posible, thanks

Comments

  • Mike_AB1Mike_AB1 Posts: 49Member
    : im making a shooting program for my exam , and i need to know how to detect collitions between 2 images i have this code :
    :
    : If imgBullet.Left = imgTarget.Left 'to' (imgTarget.left + imgTarget.Width) & imgBullet.Top = imgTarget.Top 'to' (imgTarget.Top + imgTarget.Height) Then
    : score = score + 1
    : Me.Caption = score
    : Timer3.Enabled = True
    :
    :
    :
    : im trying to give parameters , so that the hit counts if the bullet passes on any part of the picture and the 'to' 's represent that part in the code for i don't know how to do it , if any body knows or has an other solution to my problem , plz let me know as soon as posible, thanks
    :


    Try this:

    Private Sub Mod_HitDetect()

    Dim fBulletRight As Single
    Dim fBulletBottom As Single
    Dim fTargetRight As Single
    Dim fTargetBottom As Single

    '''Determine bullet boundaries.
    fBulletRight = imgBullet.Left + imgBullet.Width
    fBulletBottom = imgBullet.Top + imgBullet.Height

    '''Determine target boundaries.
    fTargetRight = imgTarget.Left + imgTarget.Width
    fTargetBottom = imgTarget.Top + imgTarget.Height


    '''Check horisontal
    If (fBulletRight >= imgTarget.Left) And (imgBullet.Left <= fTargetRight) Then
    '''Check vertical
    If (fBulletBottom >= imgTarget.Top) And (imgBullet.Top <= fTargetBottom) Then
    '''Here is a hit
    End If
    End If

    End Sub

    '''Mike.

Sign In or Register to comment.