Пример #1
0
        /// <summary>
        /// Perfect pixel test collision
        /// </summary>
        /// <param name="entityA">Sprite 1</param>
        /// <param name="entityB">Sprite 2</param>
        /// <returns></returns>
        public static bool PerfectPixelCollide(IColladable2PerfectPixel entityA, IColladable2PerfectPixel entityB)
        {
            int top    = Math.Max(entityA.Rectangle.Top, entityB.Rectangle.Top);
            int bottom = Math.Min(entityA.Rectangle.Bottom, entityB.Rectangle.Bottom);
            int left   = Math.Max(entityA.Rectangle.Left, entityB.Rectangle.Left);
            int right  = Math.Min(entityA.Rectangle.Right, entityB.Rectangle.Right);

            for (int y = top; y < bottom; y++)     // De haut en bas
            {
                for (int x = left; x < right; x++) // de gauche à droite
                {
                    int index_A = (x - entityA.Rectangle.Left) + (y - entityA.Rectangle.Top) * entityA.Rectangle.Width;
                    int index_B = (x - entityB.Rectangle.Left) + (y - entityB.Rectangle.Top) * entityB.Rectangle.Width;

                    Color[] colorsSpriteA = YnGraphics.GetTextureColors(entityA.Texture);
                    Color[] colorsSpriteB = YnGraphics.GetTextureColors(entityB.Texture);

                    Color colorSpriteA = colorsSpriteA[index_A];
                    Color colorSpriteB = colorsSpriteB[index_B];

                    if (colorSpriteA.A != 0 && colorSpriteB.A != 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Create a new <see cref="Yna.Engine.Graphics.YnEntity"/> with a procedural texture.
 /// </summary>
 /// <param name='rectangle'>Rectangle of the texture</param>
 /// <param name='color'>Color of the texture</param>
 public YnEntity(Rectangle rectangle, Color color)
     : this()
 {
     _rectangle   = rectangle;
     _position    = rectangle.ToVector2();
     _texture     = YnGraphics.CreateTexture(color, rectangle.Width, rectangle.Height);
     _assetLoaded = true;
 }
Пример #3
0
 /// <summary>
 /// Create a sprite without asset
 /// </summary>
 /// <param name="rectangle">Size of the sprite</param>
 /// <param name="color">Color of the sprite</param>
 public YnSprite(Rectangle rectangle, Color color)
     : this()
 {
     Rectangle    = rectangle;
     _texture     = YnGraphics.CreateTexture(color, rectangle.Width, rectangle.Height);
     _assetLoaded = true;
     _position    = new Vector2(rectangle.X, rectangle.Y);
     _rectangle   = rectangle;
 }