Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void RepairBarrier()
        {
            repairCooldown -= Game.DeltaTime;
            if (repairCooldown <= 0)
            {
                for (int y = 0; y < Height; y++)
                {
                    int random = RandomGenerator.GetRandom(0, 100);
                    if (random < 50)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            repairCooldown2 -= Game.DeltaTime;
                            random           = RandomGenerator.GetRandom(0, 100);
                            if (random < 50)
                            {
                                continue;
                            }
                            int pixelAlfaIndex = (y * Width + x) * 4 + 3;

                            if (sprite.GetSprite().bitmap[pixelAlfaIndex] == 0)
                            {
                                if (!(sprite.GetSprite().bitmap[pixelAlfaIndex - 1] == 255 && sprite.GetSprite().bitmap[pixelAlfaIndex - 2] == 255 && sprite.GetSprite().bitmap[pixelAlfaIndex - 3] == 255))
                                {
                                    if (repairCooldown2 <= 0)
                                    {
                                        sprite.GetSprite().bitmap[pixelAlfaIndex] = 255;
                                    }
                                    repairCooldown2 = repairTempo;
                                }
                            }
                        }
                    }
                }
                repairCooldown = repairTempo;
            }
        }