Example #1
0
        private void onCollidedWithBarrier(ICollidable i_Collidable)
        {
            Barrier         barrier       = i_Collidable as Barrier;
            Texture2DPixels barrierPixels = barrier.TexturePixels;
            Rectangle       intersectedRect;

            r_CollisionsManager.GetIntersectedRect(barrier, this, out intersectedRect);

            for (int y = 0; y < intersectedRect.Height; y++)
            {
                for (int x = 0; x < intersectedRect.Width; x++)
                {
                    int currY = intersectedRect.Y + y;
                    int currX = intersectedRect.X + x;

                    if (currY >= 0 && currY < barrierPixels.Rows &&
                        currX >= 0 && currX < barrierPixels.Cols)
                    {
                        barrierPixels[currY, currX] = new Color(barrierPixels[currY, currX], 0);
                    }
                }
            }

            barrier.Texture.SetData(barrierPixels.Pixels);
        }
Example #2
0
        private void handleBarrierCollision(Barrier i_Barrier)
        {
            this.Enabled = false;

            Texture2DPixels barrierPixels         = i_Barrier.TexturePixels;
            int             maxYPixelsToDestroy   = (int)(this.Height * k_DestroyBarrierPercentage);
            int             yDirection            = this.MoveDirection == Sprite.Down ? (int)Sprite.Down.Y : (int)Sprite.Up.Y;
            int             bulletStartPixelY     = this.MoveDirection == Sprite.Down ? (int)this.Position.Y - 2 : (int)this.Position.Y + 2;
            int             bulletStartPixelX     = (int)this.Position.X;
            int             barrierStartPixelY    = (int)i_Barrier.Position.Y;
            int             barrierStartPixelX    = (int)i_Barrier.Position.X;
            int             maxXPixelsToDestory   = bulletStartPixelX + (int)this.Width;
            int             pixelsToDestroyIfUp   = bulletStartPixelY - maxYPixelsToDestroy;
            int             pixelsToDestroyIfDown = bulletStartPixelY + maxYPixelsToDestroy;

            for (int currY = bulletStartPixelY; currY < pixelsToDestroyIfDown && currY >= pixelsToDestroyIfUp; currY += yDirection)
            {
                for (int currX = bulletStartPixelX; currX < maxXPixelsToDestory; currX++)
                {
                    int barrierY = currY - barrierStartPixelY;
                    int barrierX = currX - barrierStartPixelX;

                    barrierX = barrierX < 0 ? barrierX + (int)this.Width - 1 : barrierX;

                    if (this.MoveDirection == Sprite.Down)
                    {
                        barrierY = barrierY + (int)this.Height - 1;
                    }

                    barrierY = (int)MathHelper.Clamp(barrierY, 0, i_Barrier.Height - 1);
                    barrierX = (int)MathHelper.Clamp(barrierX, 0, i_Barrier.Width - 1);

                    if (barrierPixels[barrierY, barrierX].A != 0)
                    {
                        barrierPixels[barrierY, barrierX] = new Color(barrierPixels[barrierY, barrierX], 0);
                    }
                }
            }

            i_Barrier.Texture.SetData(i_Barrier.TexturePixels.Pixels);
            this.Visible = false;
        }
        public void LevelReset()
        {
            if (m_SampleBarrierPixels == null)
            {
                m_SampleBarrierPixels = m_BarrierTexture.GetPixels(m_BarrierTexture.Bounds);
            }

            foreach (Barrier barrier in r_Barriers)
            {
                for (int row = 0; row < barrier.TexturePixels.Rows; row++)
                {
                    for (int col = 0; col < barrier.TexturePixels.Cols; col++)
                    {
                        barrier.TexturePixels[row, col] = m_SampleBarrierPixels[row, col];
                    }
                }

                barrier.Texture.SetData(barrier.TexturePixels.Pixels);
            }
        }