Пример #1
0
        /// <summary>
        /// Loads a tile map from a bitmap.
        /// </summary>
        /// <param name="bitmap">The bitmap to create a tile map from.</param>
        public static void LoadTileMap(Bitmap image, int tileWidth, int tileHeight)
        {
            // Get the columns and row amount for the tile grid.
            int cols = image.Width / tileWidth;
            int rows = image.Height / tileHeight;

            // Create a new texture grid.
            ResTexture[,] map = new ResTexture[cols, rows];

            // Iterate through columns.
            for (int col = 0; col < cols; col++)
            {
                // Iterate through rows.
                for (int row = 0; row < rows; row++)
                {
                    // Copy image part rectangle.
                    Rectangle rect = new Rectangle(col * tileWidth, row * tileHeight, tileWidth, tileHeight);

                    // Create tile texture.
                    map[col, row] = new ResTexture(image.Clone(rect, image.PixelFormat));
                }
            }

            // Paint tile map.
            _tileMaps.Add(map);
        }
Пример #2
0
        /// <summary>
        /// Constructs a new quad.
        /// </summary>
        /// <param name="textureId"></param>
        /// <param name="vertices"></param>
        /// <param name="textureCoordinates"></param>
        /// <param name="color"></param>
        public Quad(ResTexture texture, PointF position, PointF scale, float angle, Color color)
        {
            _textureId = texture.TextureId;
            _color     = color;

            _angle        = angle;
            _spriteWidth  = texture.Width;
            _spriteHeight = texture.Height;

            // Set vertices.
            _vertices[0] = new PointF(position.X, position.Y);
            _vertices[1] = new PointF(texture.TextureSize + _vertices[0].X, position.Y);
            _vertices[2] = new PointF(texture.TextureSize + _vertices[0].X, texture.TextureSize + _vertices[0].Y);
            _vertices[3] = new PointF(position.X, texture.TextureSize + _vertices[0].Y);

            // Set texture coordinates.
            //_textureCoordinates[0] = new PointF(0.0f, 0.0f);
            //_textureCoordinates[1] = new PointF(scale.X, 0.0f);
            //_textureCoordinates[2] = new PointF(scale.X, scale.Y);
            //_textureCoordinates[3] = new PointF(0.0f, scale.Y);
            _textureCoordinates[0] = new PointF(0.0f, 0.0f);
            _textureCoordinates[1] = new PointF(1.0f, 0.0f);
            _textureCoordinates[2] = new PointF(1.0f, 1.0f);
            _textureCoordinates[3] = new PointF(0.0f, 1.0f);

            this.scale = scale;
        }
Пример #3
0
        /// <summary>
        /// Loads a texture to the texture list.
        /// </summary>
        /// <param name="image">The bitmap image used as a texture.</param>
        /// <param name="id">The id of the texture.</param>
        public static void LoadTexture(string name, Bitmap image /*, int id*/)
        {
            // If the key already exists.
            if (_sprites.ContainsKey(name))
            {
                // Dispose of old texture
                _sprites[name].Dispose();

                // Create a new texture
                _sprites[name] = new ResTexture(image);
            }
            else
            {
                // Paint a texture to the list.
                _sprites.Add(name, new ResTexture(image));
            }
        }
Пример #4
0
        /// <summary>
        /// Draws a sprite.
        /// </summary>
        /// <param name="id">The texture resource id.</param>
        /// <param name="x">The horizontal coordinate.</param>
        /// <param name="y">The vertical coordinate.</param>
        /// <param name="color">The blend color.</param>
        public static void DrawSprite(string id, int x, int y, float scaleX, float scaleY, float angle, Color color)
        {
            // If the sprite does not exist, return.
            if (_sprites.ContainsKey(id) == false)
            {
                return;
            }

            // Get the resource.
            ResTexture texture = _sprites[id];

            // If the texture is empty return.
            if (texture == null)
            {
                return;
            }

            // Paint a textured quad.
            _quads.Add(new Quad(texture, new PointF(x, y), new PointF(scaleX, scaleY), angle, color));
        }
Пример #5
0
 /// <summary>
 /// Draws a part of an image resource with the desired, scale, rotation, and blend colors.
 /// </summary>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 public static void DrawTile(ResTexture texture, int x, int y, float scaleX, float scaleY, float rotation, Color color)
 {
     // Paint a textured quad.
     _quads.Add(new Quad(texture, new PointF(x, y), new PointF(scaleX, scaleY), 0, color));
 }