コード例 #1
0
        public static bool pixelperfect(RenderedEntity entityA, RenderedEntity entityB)
        {         //(Entity entityA, Entity entityB)
            Rectangle rectA = new Rectangle((int)entityA.X, (int)entityA.Y, entityA.Texture.Width, entityA.Texture.Height);
            Rectangle rectB = new Rectangle((int)entityB.X, (int)entityB.Y, entityB.Texture.Width, entityB.Texture.Height);

            if (!rectA.Intersects(rectB))
            {
                return(false);
            }
            Color[] pixsA = new Color[entityA.Texture.Width * entityA.Texture.Height];
            Color[] pixsB = new Color[entityB.Texture.Width * entityB.Texture.Height];
            entityA.Texture.GetData(pixsA);
            entityB.Texture.GetData(pixsB);

            Rectangle intersect = Rectangle.Intersect(rectA, rectB);

            for (int y = intersect.Top; y < intersect.Bottom; y++)
            {
                for (int x = intersect.Left; x < intersect.Right; x++)
                {
                    Color colorA = pixsA [(x - rectA.Left) + (y - rectA.Top) * rectA.Width];
                    Color colorB = pixsB [(x - rectB.Left) + (y - rectB.Top) * rectB.Width];
                    if (colorA.A != 0 && colorB.A != 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        public void HandleSpriteSheet(string entityID, Rectangle rect)
        {
            RenderedEntity rendered = (RenderedEntity)entities.Find(e => e.ID.Equals(entityID));

            rendered.Rect = rect;
        }
コード例 #3
0
        /* Casts to RenderedEntity and applies the new texture. */
        public void AddTextureOnEntity(string textureName, string entityID)
        {
            RenderedEntity rendered = (RenderedEntity)entities.Find(e => e.ID.Equals(entityID));

            rendered.Texture = gameContent.Find(t => t.Name.Equals(textureName));
        }