Esempio n. 1
0
        public void Generate(int textureID, Point frame, float threshold)
        {
            threshold = MathHelper.Clamp(threshold, 0, 1);

            Texture2D texture = Assetmanager.GetTexture(textureID);

            Color[] data = new Color[tilesize * tilesize];
            texture.GetData(0, new Rectangle(frame.X, frame.Y, tilesize, tilesize), data, 0, data.Length);
            float[,] translation = new float[tilesize, tilesize];
            for (int y = 0; y < tilesize; y++)
            {
                for (int x = 0; x < tilesize; x++)
                {
                    translation[x, y] = data[x + y * tilesize].A / 255f;
                }
            }

            bool[] collides = new bool[16];
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    collides[x + y * 4] = translation.SubArray(x * quarterTileSize, quarterTileSize, y * quarterTileSize, quarterTileSize).Median() > threshold;
                }
            }

            for (int i = 0; i < collides.Length; i++)
            {
                if (collides[i])
                {
                    value = value | Parts[i];
                }
            }
            Recalculate();
        }
Esempio n. 2
0
 public void Draw(SpriteBatch spriteBatch)
 {
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             Tile t = tiles[y * width + x];
             spriteBatch.Draw(Assetmanager.GetTexture(t.Texture), new Rectangle(x * tileSize.X, y * tileSize.Y, tileSize.X, tileSize.Y), t.Frame, Color.White);
         }
     }
 }
Esempio n. 3
0
        public override void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color)
        {
            int width  = (bounds.Width < this.bounds.Width) ? this.bounds.Width : bounds.Width;
            int height = (bounds.Height < this.bounds.Height) ? this.bounds.Height : bounds.Height;

            int centerWidth  = width - left - rightWidth;
            int centerHeight = height - top - bottomHeight;

            Texture2D tex = Assetmanager.GetTexture(texture);

            spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top, left, top), source[(int)Handle.TopLeft], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top, centerWidth, top), source[(int)Handle.TopCenter], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top, rightWidth, top), source[(int)Handle.TopRight], color);

            spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top + top, left, centerHeight), source[(int)Handle.MiddleLeft], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top + top, centerWidth, centerHeight), source[(int)Handle.Center], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top + top, rightWidth, centerHeight), source[(int)Handle.MiddleRight], color);

            spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top + top + centerHeight, left, bottomHeight), source[(int)Handle.BottomLeft], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top + top + centerHeight, centerWidth, bottomHeight), source[(int)Handle.BottomCenter], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top + top + centerHeight, rightWidth, bottomHeight), source[(int)Handle.BottomRight], color);
        }
Esempio n. 4
0
 /// <summary>
 /// Draws the sprite in a given area and with a given frame
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="bounds">the rendered area</param>
 /// <param name="color">the color of the sprite</param>
 /// <param name="frame">the frame that should be rendered (defaults to 0)</param>
 public void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color, int frame = 0)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), bounds, frames[frame], color, rotation, origin, SpriteEffects.None, 0);
 }
Esempio n. 5
0
 /// <summary>
 /// Draws the sprite at a given location and with a given frame
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="position">the position of the sprite</param>
 /// <param name="color">the color of the sprite</param>
 /// <param name="frame">the frame that should be rendered (defaults to 0)</param>
 public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, int frame = 0)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), position, frames[frame], Color.White, rotation, origin, 1, SpriteEffects.None, 0);
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a new Sprite with the given values.
 /// </summary>
 /// <param name="name">The name of the sprite. Used to retrieve other data from memory.</param>
 /// <param name="texture">The name of the Texture2D that can be processed via the ContentManager.</param>
 /// <param name="frameSize">The size of one single frame within a spritesheet.</param>
 public Sprite(string name, string texture)
 {
     this.name    = name;
     this.texture = Assetmanager.AquireTexture(texture);
     bounds       = Assetmanager.GetTexture(this.texture).Bounds;
 }
Esempio n. 7
0
 /// <summary>
 /// Draws the sprite in a given area
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="bounds">the rendered area</param>
 /// <param name="color">the color of the sprite</param>
 public virtual void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), bounds, null, color, rotation, origin, SpriteEffects.None, 0);
 }
Esempio n. 8
0
 /// <summary>
 /// Draws the sprite at a given location
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="position">the position of the sprite</param>
 /// <param name="color">the color of the sprite</param>
 public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), new Rectangle((int)position.X, (int)position.Y, bounds.Width, bounds.Height), null, color, rotation, origin, SpriteEffects.None, 0);
 }