public void ManagePlayerCollision(CollisionNode node1, CollisionNode node2)
 {
     if (node1.HitBoxComponent.tag == CollisionTag.ENEMY || node2.HitBoxComponent.tag == CollisionTag.ENEMY)
     {
         ManageEnemyPlayerCollision(node1, node2);
     }
     else
     {
         ManageMissilePlayerColision(node1, node2);
     }
 }
 public void ManageEnemyPlayerCollision(CollisionNode node1, CollisionNode node2)
 {
     if (node1.HitBoxComponent.tag == CollisionTag.PLAYER)
     {
         ((SpaceInvaders.Entities.Player)node1.HitBoxComponent.entity).Life = 0;
     }
     else if (node2.HitBoxComponent.tag == CollisionTag.PLAYER)
     {
         ((SpaceInvaders.Entities.Player)node2.HitBoxComponent.entity).Life = 0;
     }
 }
 public void ManageMissilePlayerColision(CollisionNode node1, CollisionNode node2)
 {
     if (node1.HitBoxComponent.tag == CollisionTag.PLAYER)
     {
         DecreasePlayerLife(node1);
         Engine.instance.RemoveEntity(node2.HitBoxComponent.entity);
     }
     else if (node2.HitBoxComponent.tag == CollisionTag.PLAYER)
     {
         DecreasePlayerLife(node2);
         Engine.instance.RemoveEntity(node1.HitBoxComponent.entity);
     }
 }
        public void ManageAccurateCollision(CollisionNode bunkerCollisionNode, CollisionNode missileCollisionNode)
        {
            Box intersection = GetIntersection(bunkerCollisionNode.HitBoxComponent.HitBox, missileCollisionNode.HitBoxComponent.HitBox);

            Box relativeHitBox = new Box
            {
                X = Clamp(intersection.X - bunkerCollisionNode.HitBoxComponent.HitBox.X - EnlargedWidthHitbox, 0, bunkerCollisionNode.RenderComponent.sprite.Width),
                Y = Clamp(intersection.Y - bunkerCollisionNode.HitBoxComponent.HitBox.Y, 0, bunkerCollisionNode.RenderComponent.sprite.Height),

                XPlusWidth  = Clamp(intersection.XPlusWidth - bunkerCollisionNode.HitBoxComponent.HitBox.X + EnlargedWidthHitbox, 0, bunkerCollisionNode.RenderComponent.sprite.Width),
                YPlusHeight = Clamp(intersection.YPlusHeight - bunkerCollisionNode.HitBoxComponent.HitBox.Y, 0, bunkerCollisionNode.RenderComponent.sprite.Height)
            };

            if (ManagePixelCollisionsBunker(bunkerCollisionNode.RenderComponent, relativeHitBox, missileCollisionNode))
            {
                if (missileCollisionNode.HitBoxComponent.tag != CollisionTag.ENEMY)
                {
                    Engine.instance.RemoveEntity(missileCollisionNode.HitBoxComponent.entity);
                }
            }
        }
        public static bool ManagePixelCollisionsBunker(RenderComponent renderComponent, Box rectToColor, CollisionNode missileCollisionNode)
        {
            Color      actualColor;
            MissileAbs missileEntity = missileCollisionNode.HitBoxComponent.entity as MissileAbs;

            for (int i = (int)rectToColor.X; i < (int)rectToColor.XPlusWidth; i++)
            {
                for (int j = (int)rectToColor.Y; j < (int)rectToColor.YPlusHeight; j++)
                {
                    actualColor = ((Bitmap)renderComponent.sprite).GetPixel(i, j);

                    if (missileEntity.NbPixelToDestroy > 0)
                    {
                        if (actualColor.A == 255 && actualColor.R == 0 && actualColor.B == 0 && actualColor.G == 0)
                        {
                            ((Bitmap)renderComponent.sprite).SetPixel(i, j, Color.FromArgb(0, 0, 0, 0));
                            missileEntity.NbPixelToDestroy--;
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
 public void DecreasePlayerLife(CollisionNode nodePlayer)
 {
     ((SpaceInvaders.Entities.Player)nodePlayer.HitBoxComponent.entity).Life--;
 }