jmfmarques
Messages postés
7666
Date d'inscription
samedi 5 novembre 2005
Statut
Membre
Dernière intervention
22 août 2014
27
19 févr. 2007 à 14:07
Plus là !!!
Bon ...
Tiens donc, ami :
Si tu es capable de comprendre ce mécanisme (que tu dois lancer et attendre la sortie de la boule....),
tu es apte à traiter de collisions et de confinements...
Si tel n'est pas le cas, laisse tomber...
Private versgauche As Integer, versdroite As Integer, sensx As Single, sensy As Single, kx As Single, ky As Single
Private Sub Form_Activate()
Randomize
Me.Move Screen.Width / 3, Screen.Height / 3, Screen.Width / 3, Screen.Height / 3
With Picture1
.Move 0, 0, 5000, 5000
.BackColor = RGB(255, 255, 254)
.AutoRedraw = True
.FillColor = RGB(255, 255, 255)
.FillStyle = 0
End With
Timer1.Enabled = True
Picture1.Circle (2000, 2000), 1500, RGB(255, 0, 0), , , 1.5
boule.Move 2100, 700, 300, 300
Timer1.Interval = 20
versgauche = 120
vershaut = 120
sensx = -1
sensy = 1
kx = 1.3
ky = 1.5
End Sub
Private Sub Timer1_Timer()
boule.Move boule.Left + (versgauche + kx) * sensx, boule.Top + (vershaut + ky) * sensy
DoEvents
If boum(Picture1, boule, vbWhite) Then
While boum(Picture1, boule, vbWhite)
boule.Move boule.Left - Int((versgauche + kx) * sensx / 10), boule.Top - Int((vershaut + ky) * sensy / 10)
DoEvents
Wend
sensx = -sensx
sensy = sensy
kx = Int((2 * Rnd) + 1) / 10
ky = Int((20 * Rnd) + 1) ' / 3
End If
End Sub
Private Function boum(controle As PictureBox, maboule As Shape, couleur As Long) As Boolean
X1 = maboule.Left + (maboule.Width / 2)
Y1 = maboule.Top
X2 = maboule.Left + maboule.Width
Y2 = maboule.Top + (maboule.Height / 2)
X3 = X1
Y3 = Y1 + maboule.Height
X4 = maboule.Left
Y4 = Y2
If controle.Point(X1, Y1) <> couleur Then boum = True: Exit Function
If controle.Point(X2, Y2) <> couleur Then boum = True: Exit Function
If controle.Point(X3, Y3) <> couleur Then boum = True: Exit Function
If controle.Point(X4, Y4) <> couleur Then boum = True
End Function