Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Collision detection...
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00769784
Message ID:
00769819
Vues:
20
>In an application I have a form in which you can move shapes around.
>I need to know when two shape was in contact to each other.
>

OK, I have the solution :-)

I added a IsCollision Method in the shape class and this method was called from the MouseUp event.

The method use a revert logic (?) to detect cases when the collision can NOT occur and return .F. in that case.
Only 4 small test by shape in the parent.
x1=this.Left
x2=this.Left+this.Width
y1=this.Top
y2=this.Top+this.Height
FOR i=1 TO this.parent.ControlCount
	lTouch=.F.
	oPan=this.parent.Controls(i)
	IF oPan.Class=this.Class AND oPan <> this
		lTouch=.T.
		DO CASE 
			*too low
			CASE oPan.Top>=y2
				lTouch=.F.
			*too far right
			CASE oPan.Left>=x2
				lTouch=.F.
			*too high
			CASE oPan.Top+oPan.Height<=y1
				lTouch=.F.
			*too far left
			CASE oPan.Left+oPan.Width<=x1
				lTouch=.F.		
		ENDCASE 	
	ENDIF
	oPan=.NULL.
	IF lTouch
		RETURN .T.
	ENDIF 
ENDFOR 
RETURN .F.
:-)
If we exchange an apple, we both get an apple.
But if we exchange an idea, we both get 2 ideas, cool...


Gérald Santerre
Independant programmer - internet or intranet stuff - always looking for contracts big or small :)
http://www.siteintranet.qc.ca
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform