Пример #1
0
 protected bool IsTouchingBottom(MmtStaticSprite sprite)
 {
     return(Rectangle.Top + this.Velocity.Y < sprite.Rectangle.Bottom &&
            Rectangle.Bottom > sprite.Rectangle.Bottom &&
            Rectangle.Right > sprite.Rectangle.Left &&
            Rectangle.Left < sprite.Rectangle.Right);
 }
Пример #2
0
        private bool PerPixelCollision(MmtStaticSprite target)
        {
            var sourceColors = new Color[_texture.Width * _texture.Height];

            _texture.GetData(sourceColors);

            var targetColors = new Color[target._texture.Width * target._texture.Height];

            target._texture.GetData(targetColors);

            var left   = Math.Max(Rectangle.Left, target.Rectangle.Left);
            var top    = Math.Max(Rectangle.Top, target.Rectangle.Top);
            var width  = Math.Min(Rectangle.Right, target.Rectangle.Right) - left;
            var height = Math.Min(Rectangle.Bottom, target.Rectangle.Bottom) - top;

            var intersectingRectangle = new Rectangle(left, top, width, height);

            for (var x = intersectingRectangle.Left; x < intersectingRectangle.Right; x++)
            {
                for (var y = intersectingRectangle.Top; y < intersectingRectangle.Bottom; y++)
                {
                    var sourceColor = sourceColors[(x - Rectangle.Left) + (y - Rectangle.Top) * _texture.Width];
                    var targetColor = targetColors[(x - target.Rectangle.Left) + (y - target.Rectangle.Top) * target._texture.Width];

                    if (sourceColor.A != 0 && targetColor.A != 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #3
0
 protected bool IsTouchingRight(MmtStaticSprite sprite)
 {
     return(Rectangle.Left + this.Velocity.X < sprite.Rectangle.Right &&
            Rectangle.Right > sprite.Rectangle.Right &&
            Rectangle.Bottom > sprite.Rectangle.Top &&
            Rectangle.Top < sprite.Rectangle.Bottom);
 }