need help for hit detection , urgent!!!!!!! - Programmers Heaven

Howdy, Stranger!

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

Categories

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.