وفي 16 كانون الثاني 2011 01:50 ص، قال انس متحمساً:
يقوم باخذ مرجع الكائن(ما يقابله مؤشر على حسب فهمي)، ثم يقوم بالبحث في اللائخة خانة خانة، مع مقارنة كل معلومة من معلومات الكائن أ مع المعلومة المقابلة لها في الكائن ب.class MyClass
{
public int Number;
public MyClass(int i)
{
Number = i;
}
}
void Test()
{
MyClass a = new MyClass(1);
MyClass b = new MyClass(2);
MyClass c = new MyClass(1);
MyClass d = a;
Console.WriteLine(a.Equals(b)); // Prints false
Console.WriteLine(a.Equals(c)); // Prints false!
Console.WriteLine(a.Equals(d)); // Prints true
}
static public void Update ( )
{
/*
* We use maximumXDistance to define the limite betwen the sprite on the X axi
* the Sprite are sorted on the X axie, by Ascending, this mean that the result of
* : Sprite[j].X-Sprite[i].X will never be negative
*
* We use maximumYDistance to define the limite betwen the sprite on the Y axi
* We use maximumYDistanceSquared, because the sprite are not sorted on
* the Y axie(because they are alredy sorted on the X axie
* and the diffirence betwen to sprite Y coordinate, can be negative
*/
float maximumXDistance;
float maximumYDistance;
float maximumYDistanceSquared;
// Sort all Entity on the X axis
m_GameEntityList.SortXInsertionAscending( 0, m_GameEntityList.Count );
// reset all colors outside of the collision loop : just for coloration
for ( int i = 0 ; i < m_GameEntityList.Count ; i++ )
{
m_GameEntityList[ i ].Sprite.Green = 0;
}
int j;
float xDistance;
float yDistance;
for ( int i = 0 ; i < m_GameEntityList.Count - 1 ; i++ )
{
maximumXDistance = m_GameEntityList[ i ].Sprite.ScaleX * 2;
maximumYDistance = m_GameEntityList[ i ].Sprite.ScaleY * 2;
maximumYDistanceSquared = maximumYDistance * maximumYDistance;
for (j = i + 1 ; j < m_GameEntityList.Count ; j++ )
{
xDistance = m_GameEntityList[j].Position.X - m_GameEntityList[i].Position.X;
if (xDistance < maximumXDistance)
{
// The two are close enough on the X to perform collision, so check the
// distance between the two.
yDistance = m_GameEntityList[j].Position.Y - m_GameEntityList[i].Position.Y;
if( yDistance*yDistance < maximumYDistanceSquared )
{
// to see that the collision is On
m_GameEntityList[i].Sprite.Green = 1;
m_GameEntityList[j].Sprite.Green = 1;
}
}
else
{
// the two are too far away, so move on to the next Sprite
break;
}
}
}
}
بتاريخ 02 فبراير 2011 05:23 م، قطب عبد اللطيف حاجي علي حاجبيه بشدة وهو يقول:
وما هي حسابات كشف التصادم؟ xDistance = m_GameEntityList[j].Position.X - m_GameEntityList[i].Position.X;
if (xDistance < maximumXDistance)
{
// The two are close enough on the X to perform collision, so check the
// distance between the two.
yDistance = m_GameEntityList[j].Position.Y - m_GameEntityList[i].Position.Y;
if( yDistance*yDistance < maximumYDistanceSquared )
{
// هناك تصادم
}
}