Пример #1
0
 protected void MoveToClosestPlaceBeforeCollision(GameObject gameObject)
 {
     if (BoundingBoxesIntersect(gameObject))
     {
         Vector2? minimumTransportVector = this.CollisionPolygon.Intersects(gameObject.CollisionPolygon);
         if (minimumTransportVector != null)
         {
             //Adjust Position
             Position += (Vector2)minimumTransportVector;
         }
         //This needs to make the object move in the outward normal direction of the contact surface
         //if (BBoxLeft == gameObject.BBoxRight + 1 && Velocity.X < 0) { Position += Vector2.UnitX; velocity.X = 0; }
         //if (BBoxRight == gameObject.BBoxLeft && Velocity.X > 0) { Position -= Vector2.UnitX; velocity.X = 0; }
         //if (BBoxBottom == gameObject.BBoxTop + 1 && Velocity.Y > 0) { Position -= Vector2.UnitY; velocity.Y = 0; }
         //if (BBoxTop == gameObject.BBoxBottom && Velocity.Y < 0) { Position += Vector2.UnitX; velocity.Y = 0; }
     }
 }
Пример #2
0
 protected bool BoundingBoxesIntersect(GameObject gameObject)
 {
     if (gameObject == this) return false;
     return BoundingBox.Intersects(gameObject.BoundingBox);
 }