예제 #1
0
        private void DebugDrawSegment(SpriteBatch spriteBatch, ISnakeSegment segment)
        {
            var rotation = DirectionHelper.GetRotation(segment.Direction);

            spriteBatch.DrawRectangle(segment.Bounds, Color.Red, 2);
            spriteBatch.DrawLine(segment.Bounds.Center.ToVector2(), segment.Bounds.Width / 2f, rotation, Color.Red);
            spriteBatch.DrawString(_graphicsSystem.DebugSpriteFont, segment.Position.ToString(), segment.Position, Color.Red);
        }
예제 #2
0
        private Vector2 CalculateScale(ISnakeSegment segment, TextureRegion2D selectedTexture)
        {
            Vector2 scale;

            // Hack of scaling, for cases when TileWidth != TileHeight
            if (segment.Direction == Direction.Right ||
                segment.Direction == Direction.Left)
            {
                scale = new Vector2(segment.Size.Width / selectedTexture.Bounds.Width, segment.Size.Height / selectedTexture.Bounds.Height);
            }
            else
            {
                scale = new Vector2(segment.Size.Height / selectedTexture.Bounds.Height, segment.Size.Width / selectedTexture.Bounds.Width);
            }

            return(scale);
        }
예제 #3
0
        private TextureRegion2D SelectTexture(ISnakeSegment segment)
        {
            TextureRegion2D selectedTexture;

            if (segment.Equals(_snake.Head))
            {
                selectedTexture = _graphicsSystem.TextureManager.TextureRegions["Head"];
            }
            else if (_snake.Tail.Any() && segment.Equals(_snake.Tail.Last()))
            {
                selectedTexture = _graphicsSystem.TextureManager.TextureRegions["Tail"];
            }
            else
            {
                selectedTexture = _graphicsSystem.TextureManager.TextureRegions["Part"];
            }

            return(selectedTexture);
        }
예제 #4
0
        private void DrawSegment(SpriteBatch spriteBatch, ISnakeSegment segment)
        {
            var selectedTexture = SelectTexture(segment);

            var rotation = DirectionHelper.GetRotation(segment.Direction);
            var origin   = new Vector2(selectedTexture.Bounds.Width / 2f, selectedTexture.Bounds.Height / 2f);

            var scale = CalculateScale(segment, selectedTexture);

            spriteBatch.Draw(
                texture: selectedTexture.Texture,
                position: segment.Position,
                sourceRectangle: selectedTexture.Bounds,
                color: Color.White,
                rotation: rotation,
                scale: scale,
                origin: origin,
                effects: SpriteEffects.None,
                layerDepth: LayerDepths.Snake
                );
        }