Ejemplo n.º 1
0
        /// <summary>
        /// Add an animation to the animation list
        /// </summary>
        /// <param name="i">index of the animation</param>
        /// <param name="ani">animation to add</param>
        /// <remarks>
        ///
        /// </remarks>
        public bool AddAnimation(AnimationIndex i, Animation ani)
        {
            //Console.WriteLine("Trying to load animation " + i.Value + ": " + i);
            if (i is PlayerDeathAnimationIndex)
            {
                DeathAnimations.Add(ani);
                // TODO remap on the fly, reduce death remapping
                ani.Remap(RemapInfo);
            }
            else if (i is TilesetAnimationIndex)
            {
                // enlarge array as required
                if (i.Value >= TilesetAnimations.Length)
                {
                    Animation[] newAnis = new Animation[i.Value + 1];
                    Array.Copy(TilesetAnimations, newAnis, TilesetAnimations.Length);
                    TilesetAnimations = newAnis;
                }

                if (TilesetAnimations[i.Value] != null)
                {
                    throw new InvalidOperationException("Cannot add existing animation " + i.Value + ": " + i);
                }
                else
                {
                    TilesetAnimations[i.Value] = ani;
                    //Console.WriteLine("Successfully added " + i.Value + ": " + i);
                }
            }
            else if (i.Value >= Animations.Length)
            {
                throw new InvalidOperationException("There is no space for animation " + i.Value + ": " + i + " - Animations.Length is " + Animations.Length);
            }
            else if (Animations[i.Value] != null)
            {
                //throw new InvalidOperationException("Cannot add existing animation " + i.Value + ": " + i);
                Console.WriteLine("Not adding existing animation " + i.Value + ": " + i);
                return(false);
            }
            else if (i is PlayerAnimationIndex || i is PlayerDirectionAnimationIndex)
            {
                Animations[i.Value] = ani;
                ani.Remap(RemapInfo);
            }
            else
            {
                //Console.WriteLine("Successfully added " + i.Value + ": " + i);
                Animations[i.Value] = ani;
            }
            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="i"></param>
 /// <returns></returns>
 public Animation this[AnimationIndex i]
 {
     get
     {
         if (i is PlayerDeathAnimationIndex)
         {
             PlayerDeathAnimationIndex di = (PlayerDeathAnimationIndex)i;
             return(DeathAnimations[di.Type]);
         }
         else if (i is TilesetAnimationIndex)
         {
             // TRYTRY: catch invalid tileset number?
             return(TilesetAnimations[i.Value]);
         }
         else
         {
             return(Animations[i.Value]);
         }
     }
 }