Example #1
0
        private bool PixelCollides(Vector2 center, float ray, bool erase = false)
        {
            bool collision = false;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Vector2 pixelPos        = new Vector2(position.X - (Width / 2) + x, position.Y - (Height / 2) + y);
                    float   pixToBulletDist = pixelPos.Sub(center).GetLength();

                    if (pixToBulletDist <= ray)
                    {
                        //obtains index of current pixel's alpha
                        int pixelAlfaIndex = (y * Width + x) * 4 + 3;

                        if (erase)
                        {//must erase pixels inside the explosion's circle
                            sprite.GetSprite().bitmap[pixelAlfaIndex] = 0;
                            collision = true;
                        }
                        else
                        {
                            if (sprite.GetSprite().bitmap[pixelAlfaIndex] != 0)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(collision);
        }
Example #2
0
 public void Draw()
 {
     GfxTools.DrawSprite(sprite.GetSprite(), (int)(Position.X - Width / 2), (int)(Position.Y - Height / 2));
 }