Exemplo n.º 1
0
        private Sprite SetSprite(Point point, int offsetIndex)
        {
            if (_terrain == null) return null;

            var tileset = TilesetManager.Instance.GetTileset(_terrain.Tileset);
            if (tileset == null) return null;

            if (point == null) return null;

            var x = destX * tileset.TileWidth;
            var y = destY * tileset.TileHeight;

            var srcX = (_terrain.X * tileset.TileWidth) + point.X;
            var srcY = (_terrain.Y * tileset.TileHeight) + point.Y;

            var xoffset = tileset.TileWidth / 2;
            var yoffset = tileset.TileHeight / 2;

            switch (offsetIndex)
            {
                // NW
                case 0:
                    break;
                // NE
                case 1:
                    x += xoffset;
                    break;
                // SW
                case 2:
                    y += yoffset;
                    break;
                // SE
                case 3:
                    x += xoffset;
                    y += yoffset;
                    break;
            }

            var sprite = new Sprite
            {
                Texture = ResourceManager.Instance.LoadTexture(tileset.Image),
                Position = new Vector2f(x, y),
                TextureRect = new IntRect(srcX, srcY, tileset.TileWidth / 2, tileset.TileHeight / 2)
            };

            return sprite;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Checks if a point is in the <see cref="Points"/> list.
 /// </summary>
 /// <param name="point">Point to check for.</param>
 /// <returns>Returns true if the point is found, false if not.</returns>
 public bool ContainsPoint(Point point)
 {
     foreach (Point tmp in _points)
     {
         if (tmp.X == point.X && tmp.Y == point.Y)
             return true;
     }
     return false;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Toggles the inclusion of a specific point.
        /// </summary>
        /// <param name="point">Point to toggle.</param>
        public void TogglePoint(Point point)
        {
            if (point.X > (_objectWidth / _tileWidth) - 1) return;
            if (point.Y > (_objectHeight / _tileHeight) - 1) return;

            if (!ContainsPoint(point))
            {
                _points.Add(point);
                CalculateOffset();
                return;
            }

            foreach (var tmp in _points.ToList())
            {
                if (tmp.X == point.X && tmp.Y == point.Y)
                    _points.Remove(tmp);
            }

            CalculateOffset();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculates which points appear between the <see cref="Start"/> and <see cref="End"/> points.
        /// </summary>
        public void CalculatePoints()
        {
            _points.Clear();

            int x1; int x2; int y1; int y2;

            if (Start.X < End.X)
            {
                x1 = Start.X;
                x2 = End.X;
            }
            else
            {
                x1 = End.X;
                x2 = Start.X;
            }
            if (Start.Y < End.Y)
            {
                y1 = Start.Y;
                y2 = End.Y;
            }
            else
            {
                y1 = End.Y;
                y2 = Start.Y;
            }

            if (x1 < 0) x1 = 0;
            if (y1 < 0) y1 = 0;
            if (x2 < 0) x2 = 0;
            if (y2 < 0) y2 = 0;
            if (x1 > (_objectWidth / _tileWidth) - 1) x1 = (_objectWidth / _tileWidth) - 1;
            if (y1 > (_objectHeight / _tileHeight) - 1) y1 = (_objectHeight / _tileHeight) - 1;
            if (x2 > (_objectWidth / _tileWidth) - 1) x2 = (_objectWidth / _tileWidth) - 1;
            if (y2 > (_objectHeight / _tileHeight) - 1) y2 = (_objectHeight / _tileHeight) - 1;

            for (int x = x1; x <= x2; x++)
            {
                for (int y = y1; y <= y2; y++)
                {
                    _points.Add(new Point(x, y));
                }
            }

            _offset = new Point(x1, y1);
        }