Beispiel #1
0
        /// <summary>
        /// Uses the layer type and direction to determine the draw order. A lower draw order gets drawn first (behind), while a higher draw
        /// order gets drawn last (on top).
        /// </summary>
        static int GetLayerOrder(PaperDollLayerType layerType, Direction heading)
        {
            switch (heading)
            {
            case Direction.North:
            case Direction.NorthWest:
            case Direction.NorthEast:
                switch (layerType)
                {
                case PaperDollLayerType.Hat: return(30);

                case PaperDollLayerType.Body: return(20);

                case PaperDollLayerType.Weapon: return(10);
                }
                break;

            case Direction.South:
            case Direction.SouthWest:
            case Direction.SouthEast:
                switch (layerType)
                {
                case PaperDollLayerType.Weapon: return(30);

                case PaperDollLayerType.Hat: return(20);

                case PaperDollLayerType.Body: return(10);
                }
                break;

            case Direction.East:
                switch (layerType)
                {
                case PaperDollLayerType.Weapon: return(30);

                case PaperDollLayerType.Body: return(20);

                case PaperDollLayerType.Hat: return(10);
                }
                break;

            case Direction.West:
                switch (layerType)
                {
                case PaperDollLayerType.Body: return(30);

                case PaperDollLayerType.Weapon: return(20);

                case PaperDollLayerType.Hat: return(10);
                }
                break;
            }

            return(0);
        }
Beispiel #2
0
 /// <summary>
 /// Gets the drawing position offset to use for a paper doll layer. The offset is relative to the original drawing position (0,0).
 /// </summary>
 /// <param name="layerType">The paper doll layer.</param>
 /// <returns>The drawing offset</returns>
 static Vector2 GetPaperDollLayerOffset(PaperDollLayerType layerType)
 {
     // No offsets defined by default
     return(Vector2.Zero);
 }
        /// <summary>
        /// Uses the layer type and direction to determine the draw order. A lower draw order gets drawn first (behind), while a higher draw
        /// order gets drawn last (on top).
        /// </summary>
        static int GetLayerOrder(PaperDollLayerType layerType, Direction heading)
        {
            switch (heading)
            {
                case Direction.North:
                case Direction.NorthWest:
                case Direction.NorthEast:
                    switch (layerType)
                    {
                        case PaperDollLayerType.Hat: return 30;
                        case PaperDollLayerType.Body: return 20;
                        case PaperDollLayerType.Weapon: return 10;
                    }
                    break;

                case Direction.South:
                case Direction.SouthWest:
                case Direction.SouthEast:
                    switch (layerType)
                    {
                        case PaperDollLayerType.Weapon: return 30;
                        case PaperDollLayerType.Hat: return 20;
                        case PaperDollLayerType.Body: return 10;
                    }
                    break;

                case Direction.East:
                    switch (layerType)
                    {
                        case PaperDollLayerType.Weapon: return 30;
                        case PaperDollLayerType.Body: return 20;
                        case PaperDollLayerType.Hat: return 10;
                    }
                    break;

                case Direction.West:
                    switch (layerType)
                    {
                        case PaperDollLayerType.Body: return 30;
                        case PaperDollLayerType.Weapon: return 20;
                        case PaperDollLayerType.Hat: return 10;
                    }
                    break;
            }

            return 0;
        }
Beispiel #4
0
        /// <summary>
        /// Draws the <see cref="ICharacterSprite"/>.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw with.</param>
        /// <param name="position">The position to draw the sprite.</param>
        /// <param name="heading">The character's heading.</param>
        /// <param name="color">The color of the sprite.</param>
        public void Draw(ISpriteBatch spriteBatch, Vector2 position, Direction heading, Color color)
        {
            // If we have a body modifier being used, invalidate it if:
            // 1. The heading has changed.
            // 2. The animation has ended.
            //
            // If we don't have a body modifier being used, just ensure we have the correct Set being used.
            //
            // If we are moving, always use the walking animation.

            _currentHeading = heading;

            // If the body modifier is set, check if it needs to be unset
            if (_currentBodyModifier != null)
            {
                if (_bodyGrh.AnimType == AnimType.None || _bodyModifierDirection != heading)
                {
                    _currentBodyModifier = null;
                }
            }

            // If we are moving, the body modifier is not set, or the sprite is invalid, use the non-modifier set
            if (Character.Velocity != Vector2.Zero || _currentBodyModifier == null || _bodyGrh.GrhData == null)
            {
                var prefix          = (Character.Velocity == Vector2.Zero ? string.Empty : "Walk ");
                var directionSuffix = GetDirectionSetName(heading);

                _currentBodyModifier = null;
                InternalSetSet(prefix + directionSuffix);
            }

            // Ensure the sprite is valid before trying to update and draw it
            if (_bodyGrh.GrhData == null)
            {
                return;
            }

            // Update
            _bodyGrh.Update(_currentTime);

            position += new Vector2(Character.Size.X / 2f, Character.Size.Y - _bodyGrh.Size.Y);

            // Get the GrhDatas to draw, along with their draw order
            List <Tuple <int, GrhData, PaperDollLayerType> > grhDatas = new List <Tuple <int, GrhData, PaperDollLayerType> >();

            grhDatas.Add(new Tuple <int, GrhData, PaperDollLayerType>(GetLayerOrder(PaperDollLayerType.Body, heading), _bodyGrh.GrhData, PaperDollLayerType.Body));

            if (Paperdoll)
            {
                string setSuffix = !string.IsNullOrEmpty(_currentSet) ? "." + _currentSet : "";
                if (_layers != null)
                {
                    foreach (var layerName in _layers)
                    {
                        GrhData gd = GrhInfo.GetData(new SpriteCategorization("Character." + layerName + setSuffix));
                        if (gd == null)
                        {
                            continue;
                        }

                        PaperDollLayerType layerType = GetPaperDollLayerType(layerName);
                        int layerOrder = GetLayerOrder(layerType, heading);
                        grhDatas.Add(new Tuple <int, GrhData, PaperDollLayerType>(layerOrder, gd, layerType));
                    }
                }
            }

            // Sort by layer order
            grhDatas = grhDatas.OrderBy(x => x.Item1).ToList();

            // Draw in order
            var drawingGrh = _bodyGrh.DeepCopy();

            for (int i = 0; i < grhDatas.Count; i++)
            {
                GrhData gd = grhDatas[i].Item2;

                // Set frame
                GrhData gdFrame = gd.GetFrame((int)Math.Floor(_bodyGrh.Frame)) ?? gd.Frames.LastOrDefault();
                if (gdFrame == null)
                {
                    continue;
                }

                drawingGrh.SetGrh(gdFrame);

                // Get offset
                Vector2 sizeXOffset = new Vector2(drawingGrh.Size.X / -2f, 0);
                Vector2 layerOffset = GetPaperDollLayerOffset(grhDatas[i].Item3);

                // Draw
                drawingGrh.Draw(spriteBatch, position + layerOffset + sizeXOffset, color);
            }
        }
 /// <summary>
 /// Gets the drawing position offset to use for a paper doll layer. The offset is relative to the original drawing position (0,0).
 /// </summary>
 /// <param name="layerType">The paper doll layer.</param>
 /// <returns>The drawing offset</returns>
 static Vector2 GetPaperDollLayerOffset(PaperDollLayerType layerType)
 {
     // No offsets defined by default
     return Vector2.Zero;
 }