public void AfterAllDetection() { if (CollidedList.Count > 0) { foreach (Entity one in CollidedList) { Intersection = Rectangle.Intersect(FutureBox, one.BoundBox); if (one.EntityCollision.FirstContact < min.EntityCollision.FirstContact) { third = two; two = min; min = one; } one.EntityCollision.Response(this); CurrentSprite.CollisionResponse(true); //tint sprite one.Sprite.CollisionResponse(true); //tint sprite } Intersection = Rectangle.Intersect(FutureBox, min.BoundBox); Response(min.EntityCollision); if (two != null && FutureBox.Intersects(two.BoundBox) && two != min) { Intersection = Rectangle.Intersect(FutureBox, two.BoundBox); Response(two.EntityCollision); } if (third != null && FutureBox.Intersects(third.BoundBox) && third != two && third != min) { Intersection = Rectangle.Intersect(FutureBox, third.BoundBox); Response(third.EntityCollision); } CollidedList.Clear(); } }
public virtual void Detection(GameTime gameTime, ICollision collideObject) //detect IF it will collide. { if (FutureBox.Intersects(collideObject.CurrentEntity.BoundBox) && !collideObject.CurrentEntity.Dead) { third = two; two = min; collideObject.FirstContact = gameTime.ElapsedGameTime.Milliseconds; min = collideObject.CurrentEntity; CollidedList.Add(min); Intersection = Rectangle.Intersect(FutureBox, collideObject.CurrentSprite.BoundBox); } _elapsed += gameTime.ElapsedGameTime.Milliseconds; if (_elapsed >= Delay)//To show a black color for collision response. { CurrentSprite.CollisionResponse(false); collideObject.CurrentSprite.CollisionResponse(false); _elapsed = 0; } }