public AnimatedSprite(Animation animation, Vector2 position, Anchor anchor)
        {
            this.animation = animation;
            int width = animation.FrameWidth;
            int height = animation.FrameHeight;

            switch (anchor)
            {
                case Anchor.TOPLEFT:
                    this.mCenter.X = position.X + width / 2;
                    this.mCenter.Y = position.Y + height / 2;
                    break;
                case Anchor.TOPRIGHT:
                    this.mCenter.X = position.X - width / 2;
                    this.mCenter.Y = position.Y + height / 2;
                    break;
                case Anchor.CENTER:
                    this.mCenter = position;
                    break;
                case Anchor.BOTTOMLEFT:
                    this.mCenter.X = position.X + width / 2;
                    this.mCenter.Y = position.Y - height / 2;
                    break;
                case Anchor.BOTTOMRIGHT:
                    this.mCenter.X = position.X - width / 2;
                    this.mCenter.Y = position.Y - height / 2;
                    break;
            }
        }
        public Enemy(Animation animation, Vector2 position, Anchor a, float maxHealth, int value, float move_speed)
            : base(animation, position, a)
        {
            this.maxHealth = maxHealth;
            //this.setDifficulty(difficulty);

            this.value = value;
            this.alive = true;

            this.mSpeed = move_speed;
            this.health = maxHealth;
            this.at_end = false;
            this.layer_depth = 0.6f;
        }
示例#3
0
 /// <summary>
 /// Create the event used an animation has been wrapped up in something.
 /// </summary>
 /// <param name="animation">The animation.</param>
 public AnimationEventArgs(Animation animation)
 {
     //Pass along the data.
     _Animation = animation;
 }
 public AxeMan(Animation animation, Vector2 position, Anchor a)
     : base(animation, position, a, MAX_HEALTH, VALUE, MOVE_SPEED)
 {
     deathSound = DEATH_SOUND;
 }
示例#5
0
        /// <summary>
        /// Update the list of animations to accurately reflect the loaded list of animations.
        /// This also updates the animation bars scattered around the screen.
        /// </summary>
        private void UpdateAnimationLists()
        {
            //Clear the lists.
            _AnimationList.Items.Clear();
            foreach (AnimationBar bar in _AnimationBars) { _GUI.RemoveItem(bar); }
            _AnimationBars.Clear();
            _SelectedAnimation = (_Character.Skeleton.Animations.Count == 0) ? new Animation() : GetAnimation(0);

            //Go through all the skeleton's animations and add them as entries in the list.
            foreach (Animation animation in _Character.Skeleton.Animations)
            {
                //Add an entry.
                _AnimationList.AddItem();
                if (_GUI.ContentManager != null) { _AnimationList[_AnimationList.Items.Count - 1].LoadContent(); }
                _GUI.AddItem(new AnimationBar(_GUI, animation, new Vector2(50, (600 + _AnimationBars.Count * 22)), 800, 20));
                _AnimationBars.Add(_GUI.LastItem as AnimationBar);
                if (_GUI.ContentManager != null) { _AnimationBars[_AnimationBars.Count - 1].LoadContent(); }

                //Hook up some events.
                _AnimationBars[_AnimationBars.Count - 1].MouseClick += OnAnimationBarClick;
                _AnimationBars[_AnimationBars.Count - 1].PlayStateChange += OnPlayStateChange;
                _AnimationBars[_AnimationBars.Count - 1].SelectedFrameChange += OnSelectedFrameChange;

                //Edit the label.
                _AnimationList[_AnimationList.Items.Count - 1].Checkbox.Text = animation.Name;
            }
        }
示例#6
0
 /// <summary>
 /// Save the animation.
 /// </summary>
 /// <param name="animation">The animation to save.</param>
 /// <param name="name">The name of the animation.</param>
 private void SaveAnimation(Animation animation, string name)
 {
     //Change the name of the animation.
     animation.Name = name;
     //Save the animation.
     Helper.SaveAnimation(animation, (_ContentManager.RootDirectory + @"\Editor\"));
 }
示例#7
0
 /// <summary>
 /// Remove an animation from both the editor and the skeleton.
 /// </summary>
 /// <param name="animation">The animation to delete.</param>
 private void RemoveAnimation(Animation animation)
 {
     //Remove the animation from the skeleton.
     _Character.Skeleton.RemoveAnimation(animation);
     //Update the animaion lists.
     UpdateAnimationLists();
 }
示例#8
0
 /// <summary>
 /// An already loaded animation has been selected.
 /// </summary>
 /// <param name="obj">The object that fired the event.</param>
 /// <param name="e">The event arguments.</param>
 private void OnAnimationSelected(object obj, ListItemSelectEventArgs e)
 {
     //Change the selected animation.
     _SelectedAnimation = GetAnimation(_AnimationList.Items.IndexOf(e.Item));
 }
示例#9
0
        /// <summary>
        /// Modify a frame in a given animation.
        /// </summary>
        /// <param name="animation">The animation to modify.</param>
        /// <param name="frameNumber">The index of the frame to modify.</param>
        private void ModifyFrame(Animation animation, int frameNumber)
        {
            //If there is any bone that has been modified.
            if (_ModifiedBone.Exists(flag => (flag)))
            {
                //If the currently selected frame isn't a keyframe, create it.
                if (!animation.Keyframes.Exists(kf => (kf.FrameNumber == frameNumber))) { AddKeyframe(frameNumber); }

                //Add the bones that have had their properties modified since the last keyframe to the selected keyframe, thus altering the animation.
                for (int i = 0; i < animation.Skeleton.Bones.Count; i++)
                {
                    //If the list have enough items, continue.
                    if (_ModifiedBone.Count >= (i + 1))
                    {
                        //If the bone have been modified, add it to the new keyframe.
                        if (_ModifiedBone[i])
                        {
                            //The new bone.
                            Bone bone = animation.Skeleton.Bones[i].DeepClone();

                            //If the copied bone already exists at the keyframe, remove it.
                            animation.GetKeyframe(frameNumber).RemoveBone(bone.Index);
                            //Add the copied bone to the selected keyframe.
                            animation.GetKeyframe(frameNumber).AddBone(bone);
                        }
                    }
                    //Otherwise break this party up.
                    else { break; }
                }
            }

            //Set up the list of modified bones.
            _ModifiedBone = new List<bool>(animation.Skeleton.Bones.Count);
            //Reset the modify bone list.
            for (int i = 0; i < _ModifiedBone.Capacity; i++) { _ModifiedBone.Add(false); }
        }
示例#10
0
 /// <summary>
 /// Get the index of the specified animation.
 /// </summary>
 /// <param name="animation">The animation in question.</param>
 /// <returns>The index of the animation.</returns>
 private int GetAnimationIndex(Animation animation)
 {
     //Return the animation's index.
     return _Character.Skeleton.Animations.IndexOf(animation);
 }
示例#11
0
        /// <summary>
        /// Get the animation bar that houses the specified animation.
        /// </summary>
        /// <param name="animation">The animation in question.</param>
        /// <returns>The animation bar.</returns>
        private AnimationBar GetAnimationBar(Animation animation)
        {
            //Go through each animation bar.
            foreach (AnimationBar bar in _AnimationBars)
            {
                //If the bar houses the animation, return it.
                if (bar.Animation == animation) { return bar; }
            }

            //Sorry, no animation bar has any records of that animation.
            return null;
        }
示例#12
0
        /// <summary>
        /// Transform the skeleton according to a state of one of its animations, ie. a certain keyframe.
        /// </summary>
        /// <param name="animation">The animation in focus.</param>
        /// <param name="frameNumber">The index of the frame.</param>
        public void TransformSkeleton(Animation animation, int frameNumber)
        {
            //Loop through all bones in the skeleton.
            for (int boneIndex = 0; boneIndex < _Character.Skeleton.BoneUpdateOrder.Count; boneIndex++)
            {
                //Current bone.
                Bone bone = _Character.Skeleton.BoneUpdateOrder[boneIndex];

                //If the frame happens to be a keyframe.
                if (animation.Keyframes.Exists(kf => (kf.FrameNumber == frameNumber)))
                {
                    //Get the keyframe.
                    Keyframe keyframe = animation.Keyframes.Find(kf => (kf.FrameNumber == frameNumber));

                    //If the bone is involved in any key changes in the not so distant future.
                    if (keyframe.ExistsBone(bone.Index))
                    {
                        //Get the correct bone in the next keyframe's list of bones to update, that is the one that's currently being updated.
                        Bone boneToBe = keyframe.GetBone(bone.Index);

                        //Perform the linear interpolation between the last and next keyframe bone states.
                        bone.Rotation = MathHelper.Lerp(bone.Rotation, boneToBe.Rotation, 1);
                    }
                }
            }
        }
示例#13
0
        /// <summary>
        /// Initialize the animation controller.
        /// </summary>
        public void Initialize(AnimationEditorScreen screen, Character character)
        {
            //Initialize some variables.
            _Screen = screen;
            _Character = character;
            _SelectedAnimation = ((_Character != null) && (_Character.Skeleton.Animations.Count != 0)) ? GetAnimation(0) : null;
            _AnimationBars = new List<AnimationBar>();
            _SelectedBoneIndex = 0;
            _ModifiedBone = new List<bool>();
            _GUI = new GraphicalUserInterface();
            _IsGUIClicked = false;

            //Create the character.
            _Character = new Character(new Level("redundant", null), "deafult", new Vector2(600, 250), 0, Vector2.One, 0, 0);
            _Character.Skeleton.Initialize(screen.ScreenManager.GraphicsDevice);
            _Character.AddAnimation();
            _Character.Skeleton.Animations[0].Name = "default pose";
            _Character.Skeleton.AddKeyframe(0, 0);
            _Character.Skeleton.AddKeyframe(0, 3);
            _Character.Skeleton.AddKeyframe(0, 8);
            _Character.Skeleton.AddKeyframe(0, 12);
            _Character.Skeleton.AddKeyframe(0, 15);
            _Character.Skeleton.AddKeyframe(0, 19);

            //Initialize the list of modified bones.
            ResetModifiedBones();

            //Add items to the GUI.
            _InformationList = new List(_GUI, new Vector2(950, 155), 300, 300);
            _AnimationList = new Checkboxlist(_GUI, new Vector2(950, 50), 300, 100);
            _Menu = new Menu(_GUI, new Vector2(0, 0), 500, 30);

            //Save some components closer to home.
            _GUI.AddItem(_InformationList);
            _GUI.AddItem(_AnimationList);
            _GUI.AddItem(_Menu);

            //Create the animation bars and update the animation lists.
            UpdateAnimationLists();
            UpdateInformationList(true);

            //Tinker with the animation.
            _SelectedAnimation.ResetKeyframe(0);

            //Hook up some events.
            _GUI.ItemClicked += OnGUIClicked;
            _InformationList.ItemSelect += OnInformationSelected;
            _AnimationList.ItemSelect += OnAnimationSelected;

            #region Menu
            //Play with the menu.
            _Menu.AddMenuItem();
            _Menu.AddMenuItem();
            _Menu.AddMenuItem();

            _Menu.MenuItems[0].AddListItem();
            _Menu.MenuItems[0].AddListItem();
            _Menu.MenuItems[0].AddListItem();
            _Menu.MenuItems[0].AddListItem();
            _Menu.MenuItems[0].AddListItem();
            _Menu.MenuItems[0].AddListItem();

            _Menu.MenuItems[1].AddListItem();
            _Menu.MenuItems[1].AddListItem();
            _Menu.MenuItems[1].AddListItem();
            _Menu.MenuItems[1].AddListItem();
            _Menu.MenuItems[1].AddListItem();

            _Menu.MenuItems[2].AddListItem();
            _Menu.MenuItems[2].AddListItem();
            _Menu.MenuItems[2].AddListItem();

            _Menu.MenuItems[0].IsScrollable = false;
            _Menu.MenuItems[1].IsScrollable = false;
            _Menu.MenuItems[2].IsScrollable = false;
            _Menu.MenuItems[0].IsFixed = false;
            _Menu.MenuItems[1].IsFixed = false;
            _Menu.MenuItems[2].IsFixed = false;

            _Menu.MenuItems[0].Text = "File";
            _Menu.MenuItems[1].Text = "Edit";
            _Menu.MenuItems[2].Text = "View";

            _Menu.MenuItems[0][0].Label.Text = "New Animation";
            _Menu.MenuItems[0][1].Label.Text = "New Skeleton";
            _Menu.MenuItems[0][2].Label.Text = "Open Animation";
            _Menu.MenuItems[0][3].Label.Text = "Open Skeleton";
            _Menu.MenuItems[0][4].Label.Text = "Save Animation";
            _Menu.MenuItems[0][5].Label.Text = "Save Skeleton";

            _Menu.MenuItems[1][0].Label.Text = "Create Bone";
            _Menu.MenuItems[1][1].Label.Text = "Edit Bone";
            _Menu.MenuItems[1][2].Label.Text = "Create Keyframe";
            _Menu.MenuItems[1][3].Label.Text = "Delete Keyframe";
            _Menu.MenuItems[1][4].Label.Text = "Remove Animation";

            _Menu.MenuItems[2][0].Label.Text = "Zoom";
            _Menu.MenuItems[2][1].Label.Text = "Scroll";
            _Menu.MenuItems[2][2].Label.Text = "Windows";

            _Menu.MenuOptionSelect += OnMenuOptionSelected;
            #endregion
        }
 public AnimatedSprite(Animation animation, Vector2 center)
     : this(animation, center, Anchor.CENTER)
 {
 }
 public AnimatedSprite(Animation animation)
 {
     this.animation = animation;
 }