/// <summary>
 /// Adds the animation to the list of animations.
 /// </summary>
 /// <param name="animation">The animation to add.</param>
 public virtual void AddAnimation(Animation animation)
 {
     Animations.Add(animation.ID, animation);
 }
 /// <summary>
 /// Overrides the entity's animation.
 /// </summary>
 /// <param name="component">The component that's to be in charge of the animation.</param>
 /// <param name="animation">The animation to use as the override.</param>
 public virtual void OverrideAnimation(Component component, Animation animation)
 {
     IsAnimationOverridden = true;
     ComponentInControl = component;
     CurrentAnimation = animation;
 }
        /// <summary>
        /// Handles the animation derived from state.
        /// </summary>
        protected virtual void HandleDerivedAnimation()
        {
            //We're going to use a string builder for this.
            StringBuilder idbuilder = new StringBuilder();

            //First we want to start with the raw state...
            switch (MovingState)
            {
                case MovingState.Standing:
                    idbuilder.Append("stand");
                    break;
                case MovingState.Walking:
                    idbuilder.Append("walk");
                    break;
                case MovingState.Running:
                    idbuilder.Append("run");
                    break;
            }

            idbuilder.Append("_");

            //Then we'll add direction...
            switch (Facing)
            {
                case FacingState.North:
                    idbuilder.Append("n");
                    break;
                case FacingState.Northeast:
                    idbuilder.Append("ne");
                    break;
                case FacingState.East:
                    idbuilder.Append("e");
                    break;
                case FacingState.Southeast:
                    idbuilder.Append("se");
                    break;
                case FacingState.South:
                    idbuilder.Append("s");
                    break;
                case FacingState.Southwest:
                    idbuilder.Append("sw");
                    break;
                case FacingState.West:
                    idbuilder.Append("w");
                    break;
                case FacingState.Northwest:
                    idbuilder.Append("nw");
                    break;
            }

            //Now we get the string...
            string expectedid = idbuilder.ToString();

            //If the current animation doesn't exist...
            if (CurrentAnimation == null)
            {
                //We need to change it!
                CurrentAnimation = AnimationCache.GetAnimation(expectedid).Clone();
            }

            //If the expected ID doesn't match the current animation's ID...
            if (CurrentAnimation.ID != expectedid)
            {
                //We need to change it!
                CurrentAnimation = AnimationCache.GetAnimation(expectedid).Clone(CurrentAnimation.CurrentFrame, CurrentAnimation.TimingIndex);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Tile" /> class.
 /// </summary>
 /// <param name="animation">The tile's animation.</param>
 public Tile(Animation animation)
 {
     Animation = animation;
 }
Beispiel #5
0
        /// <summary>
        /// Loads the tile.
        /// </summary>
        /// <param name="textureid">The texture's ID.</param>
        /// <param name="x">The X position of the tile.</param>
        /// <param name="y">The Y position of the tile.</param>
        /// <param name="tilesize">The size of tiles.</param>
        /// <param name="element">The element used for loading the tile.</param>
        protected virtual void LoadTile(string textureid, int x, int y, Vector tilesize, XElement element)
        {
            FloorEffects = new List<Effect<Tile>>();
            CheckEffects = new List<Effect<Tile>>();

            int numframes = 1;
            float animrate = 1;

            if (element != null) //If there's a data element with the tile...
            {
                var properties = element.Element("properties");

                if (properties != null) //Ensure it actually has properties first.
                {
                    foreach (var property in properties.Elements("property")) //Check the properties.
                    {
                        var name = property.Attribute("name");
                        var value = property.Attribute("value");

                        if (name == null || value == null)
                        {
                            continue;
                        }

                        if (name.Value.Equals("animframes", StringComparison.OrdinalIgnoreCase)) //The number of frames the animation has, stacked vertically directly below.
                        {
                            int.TryParse(value.Value, out numframes);
                            continue;
                        }

                        if (name.Value.Equals("animrate", StringComparison.OrdinalIgnoreCase)) //The rate at which the animation goes.
                        {
                            float.TryParse(value.Value, out animrate);
                        }

                        if (name.Value.Equals("passable", StringComparison.OrdinalIgnoreCase)) //Whether or not you can pass through the tile.
                        {
                            bool.TryParse(value.Value, out Passable);
                        }

                        if (name.Value.Equals("flooreffect", StringComparison.OrdinalIgnoreCase)) //Denotes an effect that happens when you step on the tile.
                        {
                            LoadEffect(value.Value, "floor");
                        }

                        if (name.Value.Equals("checkeffect", StringComparison.OrdinalIgnoreCase)) //Denotes an effect that happens when you check the tile.
                        {
                            LoadEffect(value.Value, "check");
                        }
                    }
                }
            }

            //Get the list of frames.
            var frames = new List<Frame>();

            for (int i = 0; i < numframes; i++)
            {
                frames.Add(CreateTileFrame(textureid, x, y, tilesize, animrate));

                y++;
            }

            Animation = new Animation("tile_" +  textureid + "_" + x + "," + y, true, false, frames);

            //Create the hitbox.
            CreateHitbox(tilesize, element);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="XnaAnimation" /> class.
        /// </summary>
        /// <param name="anim">The animation to use the data to load.</param>
        /// <param name="texturecache">The texture cache used to load the textures..</param>
        public XnaAnimation(Animation anim, TextureCache texturecache)
            : base(anim.ID, anim.IsLooping, anim.ResetIndex, new List<Frame>(), anim.CurrentFrame, anim.TimingIndex)
        {
            foreach (var frame in anim.GetFramesList()) //Convert SOL Frame to XNA Frame.
            {
                AddFrame(frame.ToXnaFrame());
            }

            if (texturecache != null)
            {
                LoadContent(texturecache);
            }
        }