Collision

Résolu
tinux Messages postés 244 Date d'inscription mercredi 13 avril 2005 Statut Membre Dernière intervention 21 octobre 2013 - 4 nov. 2007 à 01:17
zavier666 Messages postés 266 Date d'inscription mardi 7 septembre 2004 Statut Membre Dernière intervention 30 avril 2009 - 4 nov. 2007 à 16:34
Bonjour, j'ai deux billes dans deux rectangles

    '***************** LE PACMAN ****************'
    Public PacMan_X As Integer' << Position en X
    Public PacMan_Y As Integer' << Position en Y
    Public PacMan_W As Integer' << Largeur en Px
    Public PacMan_H As Integer' << Hauteur en Px

    '**************** LE MONSTRE ****************'
    Public Monstre_X As Integer' << Position en X
    Public Monstre_Y As Integer' << Position en Y
    Public Monstre_W As Integer ' << Largeur en Px
    Public Monstre_H As Integer' << Hauteur en Px

Je souhaite déterminer la collision entre les deux rectangles : si un point de l'un vient heurter l'une des bordures de l'autre...
Voici ce que j'ai commencé à faire... (sans trop de succès, ça marche pas très précisement, du coup j'ai peur de ne pas suivre la bonne voie.. qq chose de plus simple ?) :

        'Cas Généraux        If Monstre_X (PacMan_X + PacMan_W) And Monstre_Y PacMan_Y Then
            Timer1.Stop()
            MsgBox.ShowDialog()
        End If        If Monstre_X PacMan_X And Monstre_Y (PacMan_Y + PacMan_H) Then
            Timer1.Stop()
            MsgBox.ShowDialog()
        End If
        'Par La Gauche
        If (Monstre_Y <= PacMan_Y) And (PacMan_Y <= (Monstre_Y + Monstre_H)) Then
            If (Monstre_X <= PacMan_X) And (PacMan_X <=  Monstre_X ) Then
                Timer1.Stop()
                MsgBox.ShowDialog()
            End If
        End If

        'Par La Droite
        If (Monstre_Y <= PacMan_Y) And (PacMan_Y <= (Monstre_Y + Monstre_H)) Then
            If ((Monstre_X + Monstre_W) <= PacMan_X) And (PacMan_X <= (Monstre_X + Monstre_W)) Then
                Timer1.Stop()
                MsgBox.ShowDialog()
            End If
         End If

Merci de votre aide ;)

4 réponses

zavier666 Messages postés 266 Date d'inscription mardi 7 septembre 2004 Statut Membre Dernière intervention 30 avril 2009 1
4 nov. 2007 à 13:33
Hello,


Nous sommes plus dans un problème de trigo que de prgrammation!! : )


La distance entre deux points dans l'espace est la suivante:


d = racine [(YB-YA)² + (XB-XA)²]


je partirais sur cette base car au lieu de bosser en 1D tu bosses directement en 2D

--------------------------------------------------
Toujours + de VB et d'API => APi @ le Loupe
http://apialaloupe.free.fr
3
tinux Messages postés 244 Date d'inscription mercredi 13 avril 2005 Statut Membre Dernière intervention 21 octobre 2013
4 nov. 2007 à 16:00
Bon Bah voilà comment je suis sorti, ça marche plus ou moins bien..

        Dim d As Integer
        Dim i_PX As Integer
        Dim i_PY As Integer

        For i_PX = PacMan_X To (PacMan_X + PacMan_W)
            For i_PY = PacMan_Y To (PacMan_Y + PacMan_H)
                d = Sqrt((i_PY - Monstre_Y) ^ 2 + (i_PX - Monstre_X) ^ 2)
                If d = 0 Then
                    Timer1.Stop()
                    MsgBox.ShowDialog()
                    Exit For
                End If
            Next
        Next

        Dim i_MX As Integer
        Dim i_MY As Integer

        For i_MX = Monstre_X To (Monstre_X + Monstre_W)
            For i_MY = Monstre_Y To (Monstre_Y + Monstre_H)
                d = Sqrt((i_MY - PacMan_Y) ^ 2 + (i_MX - PacMan_X) ^ 2)
                If d = 0 Then
                    Timer1.Stop()
                    MsgBox.ShowDialog()
                    Exit For
                End If
            Next
        Next
3
tinux Messages postés 244 Date d'inscription mercredi 13 avril 2005 Statut Membre Dernière intervention 21 octobre 2013
4 nov. 2007 à 13:57
héhé, j'avais oublié ce petit détail... :p
0
zavier666 Messages postés 266 Date d'inscription mardi 7 septembre 2004 Statut Membre Dernière intervention 30 avril 2009 1
4 nov. 2007 à 16:34
ben si ca marche, valide ma réponse : )

--------------------------------------------------
Toujours + de VB et d'API => APi @ le Loupe
http://apialaloupe.free.fr
0
Rejoignez-nous