Beispiel #1
0
        public static void InitAnimations()
        {
            Texture2D nessTexture = WorldEditor.Instance.Content.Load<Texture2D>("commando");

            Animation walkAnimation = new Animation();
            walkAnimation.Name = "walk";
            walkAnimation.Texture = nessTexture;
            for (int index = 0; index < 4; index++)
            {
                walkAnimation.ChangeFrameMotionDelta(index, 0, new Vector2(0, 30.0f));
                walkAnimation.SetFrameDuration(index, 5);
            }
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 64, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 128, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 64, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 0, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 64, 64, 64), 3);

            Animation attackAnimation = new Animation();
            attackAnimation.Name = "attack";
            attackAnimation.Texture = nessTexture;
            for (int index = 0; index < 2; index++)
            {
                attackAnimation.ChangeFrameMotionDelta(index, 0, new Vector2(0, 10.0f));
                attackAnimation.SetFrameDuration(index, 4);
            }

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 256, 64, 64), 1);

            int idleX = 0;
            Rectangle[] idleFrames = new Rectangle[8];
            for (int index = 0; index < 8; index++)
            {
                idleFrames[index] = new Rectangle(idleX, 0, 64, 64);
                idleX += 64;
            }

            Animation idleAnimation = new Animation();
            idleAnimation.Name = "idle";
            idleAnimation.SetFrameDuration(0, 1);
            idleAnimation.Texture = nessTexture;

            idleAnimation.AddFrame(RotationComponent.CardinalDirections.N, idleFrames[0], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.NE, idleFrames[1], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.E, idleFrames[2], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.SE, idleFrames[3], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.S, idleFrames[4], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.SW, idleFrames[5], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.W, idleFrames[6], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.NW, idleFrames[7], 0);

            AnimatedManager.Instance.AddAnimation("idle", idleAnimation);
            AnimatedManager.Instance.AddAnimation("walk", walkAnimation);
            AnimatedManager.Instance.AddAnimation("attack", attackAnimation);
            InputScriptNode isLeftStickActiveNode = new InputScriptNode();
            isLeftStickActiveNode.ScriptType = InputScriptNode.InputScriptType.TYPE_LEFT_STICK_ACTIVE;

            PlayAnimationScriptNode playWalkAnimScriptNode = new PlayAnimationScriptNode();
            playWalkAnimScriptNode.AnimationToQueue = "walk";
            playWalkAnimScriptNode.FrameToQueue = 0;
            playWalkAnimScriptNode.PlayIfTrue = true;

            PlayAnimationScriptNode playIdleAnimScriptNode = new PlayAnimationScriptNode();
            playIdleAnimScriptNode.AnimationToQueue = "idle";
            playIdleAnimScriptNode.FrameToQueue = 0;
            playIdleAnimScriptNode.PlayIfTrue = false;

            ToggleMotionDeltaScriptNode toggleMotionDeltaNode = new ToggleMotionDeltaScriptNode();

            InputScriptNode attackButtonNode = new InputScriptNode();
            attackButtonNode.ScriptType = InputScriptNode.InputScriptType.TYPE_BUTTON_DOWN;
            object attackString = "attack";
            attackButtonNode.SetInputValue(attackString);

            PlayAnimationScriptNode playAttackScriptNode = new PlayAnimationScriptNode();
            playAttackScriptNode.PlayIfTrue = true;
            playAttackScriptNode.AnimationToQueue = "attack";

            PlayAnimationScriptNode backToIdleNode = new PlayAnimationScriptNode();
            backToIdleNode.AnimationToQueue = "idle";
            backToIdleNode.PlayIfTrue = false;

            isLeftStickActiveNode.Name = "Is left stick active";
            playWalkAnimScriptNode.Name = "Play walk animation";
            playIdleAnimScriptNode.Name = "Play idle animation";
            toggleMotionDeltaNode.Name = "Toggle motion delta";
            playAttackScriptNode.Name = "Play attack animation";
            attackButtonNode.Name = "If attack button hit";
            ScriptNodeManager.Instance.RegisterNode(isLeftStickActiveNode);
            ScriptNodeManager.Instance.RegisterNode(playWalkAnimScriptNode);
            ScriptNodeManager.Instance.RegisterNode(playIdleAnimScriptNode);
            ScriptNodeManager.Instance.RegisterNode(playAttackScriptNode);
            ScriptNodeManager.Instance.RegisterNode(toggleMotionDeltaNode);
            ScriptNodeManager.Instance.RegisterNode(attackButtonNode);

            //ScriptNodeManager.Instance.SerializeNodes("ness.nodes");

            ScriptRoutine inputToWalkScript = new ScriptRoutine();
            inputToWalkScript.Add("Is left stick active");
            inputToWalkScript.Add("Play walk animation");
            idleAnimation.AddScriptRoutine(inputToWalkScript);

            ScriptRoutine noInputToIdleScript = new ScriptRoutine();
            noInputToIdleScript.Add("Is left stick active");
            noInputToIdleScript.Add("Play idle animation");
            walkAnimation.AddScriptRoutine(noInputToIdleScript);

            ScriptRoutine toggleMotionDeltaScript = new ScriptRoutine();
            toggleMotionDeltaScript.Add("Is left stick active");
            toggleMotionDeltaScript.Add("Toggle motion delta");
            walkAnimation.AddScriptRoutine(toggleMotionDeltaScript);
            attackAnimation.AddScriptRoutine(toggleMotionDeltaScript);

            ScriptRoutine playAttackScript = new ScriptRoutine();
            playAttackScript.Add("If attack button hit");
            playAttackScript.Add("Play attack animation");
            walkAnimation.AddScriptRoutine(playAttackScript);
            idleAnimation.AddScriptRoutine(playAttackScript);

            ScriptRoutine keepAttackingScript = new ScriptRoutine();
            keepAttackingScript.Add("If attack button hit");
            keepAttackingScript.Add("Play attack animation");
            attackAnimation.AddFrameRoutine(1, keepAttackingScript);

            ScriptRoutine backToIdleScript = new ScriptRoutine();
            backToIdleScript.Add("If attack button hit");
            backToIdleScript.Add("Play idle animation");
            attackAnimation.AddFrameRoutine(1, backToIdleScript);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="animation"></param>
 public static void AddAnimation(string name, Animation animation)
 {
     if (sAnimations.ContainsKey(name) == false)
     {
         sAnimations.Add(name, animation);
     }
 }
Beispiel #3
0
        public static void SerializeAnimations()
        {
            Texture2D nessTexture = WorldEditor.Instance.Content.Load<Texture2D>("ness");

            Animation walkAnimation = new Animation();
            walkAnimation.Name = "walk";
            walkAnimation.Texture = nessTexture;
            walkAnimation.TextureName = "ness";
            for (int index = 0; index < 4; index++)
            {
                walkAnimation.ChangeFrameMotionDelta(index, 0, new Vector2(0, 30.0f));
                walkAnimation.SetFrameDuration(index, 5);
            }
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 64, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 128, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 64, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 0, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 64, 64, 64), 3);

            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 0, 64, 64), 0);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 64, 64, 64), 1);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 128, 64, 64), 2);
            walkAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 64, 64, 64), 3);

            Animation attackAnimation = new Animation();
            attackAnimation.Name = "attack";
            attackAnimation.Texture = nessTexture;
            attackAnimation.TextureName = "ness";
            for (int index = 0; index < 2; index++)
            {
                attackAnimation.ChangeFrameMotionDelta(index, 0, new Vector2(0, 10.0f));
                attackAnimation.SetFrameDuration(index, 4);
            }

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(0, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(64, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(128, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(192, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(256, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.SW, new Rectangle(320, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.W, new Rectangle(384, 256, 64, 64), 1);

            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 192, 64, 64), 0);
            attackAnimation.AddFrame(RotationComponent.CardinalDirections.NW, new Rectangle(448, 256, 64, 64), 1);

            int idleX = 0;
            Rectangle[] idleFrames = new Rectangle[8];
            for (int index = 0; index < 8; index++)
            {
                idleFrames[index] = new Rectangle(idleX, 0, 64, 64);
                idleX += 64;
            }

            Animation idleAnimation = new Animation();
            idleAnimation.Name = "idle";
            idleAnimation.SetFrameDuration(0, 1);
            idleAnimation.Texture = nessTexture;
            idleAnimation.TextureName = "ness";

            idleAnimation.AddFrame(RotationComponent.CardinalDirections.N, idleFrames[0], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.NE, idleFrames[1], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.E, idleFrames[2], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.SE, idleFrames[3], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.S, idleFrames[4], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.SW, idleFrames[5], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.W, idleFrames[6], 0);
            idleAnimation.AddFrame(RotationComponent.CardinalDirections.NW, idleFrames[7], 0);

            InputScriptNode isLeftStickActiveNode = new InputScriptNode();
            isLeftStickActiveNode.ScriptType = InputScriptNode.InputScriptType.TYPE_LEFT_STICK_ACTIVE;

            PlayAnimationScriptNode playWalkAnimScriptNode = new PlayAnimationScriptNode();
            playWalkAnimScriptNode.AnimationToQueue = "walk";
            playWalkAnimScriptNode.FrameToQueue = 0;
            playWalkAnimScriptNode.PlayIfTrue = true;

            PlayAnimationScriptNode playIdleAnimScriptNode = new PlayAnimationScriptNode();
            playIdleAnimScriptNode.AnimationToQueue = "idle";
            playIdleAnimScriptNode.FrameToQueue = 0;
            playIdleAnimScriptNode.PlayIfTrue = false;

            ToggleMotionDeltaScriptNode toggleMotionDeltaNode = new ToggleMotionDeltaScriptNode();

            InputScriptNode attackButtonNode = new InputScriptNode();
            attackButtonNode.ScriptType = InputScriptNode.InputScriptType.TYPE_BUTTON_DOWN;
            object attackString = "attack";
            attackButtonNode.SetInputValue(attackString);

            PlayAnimationScriptNode playAttackScriptNode = new PlayAnimationScriptNode();
            playAttackScriptNode.PlayIfTrue = true;
            playAttackScriptNode.AnimationToQueue = "attack";

            PlayAnimationScriptNode backToIdleNode = new PlayAnimationScriptNode();
            backToIdleNode.AnimationToQueue = "idle";
            backToIdleNode.PlayIfTrue = false;

            isLeftStickActiveNode.Name = "Is left stick active";
            playWalkAnimScriptNode.Name = "Play walk animation";
            playIdleAnimScriptNode.Name = "Play idle animation";
            toggleMotionDeltaNode.Name = "Toggle motion delta";
            playAttackScriptNode.Name = "Play attack animation";
            attackButtonNode.Name = "If attack button hit";
            ScriptNodeManager.Instance.RegisterNode(isLeftStickActiveNode);
            ScriptNodeManager.Instance.RegisterNode(playWalkAnimScriptNode);
            ScriptNodeManager.Instance.RegisterNode(playIdleAnimScriptNode);
            ScriptNodeManager.Instance.RegisterNode(playAttackScriptNode);
            ScriptNodeManager.Instance.RegisterNode(toggleMotionDeltaNode);
            ScriptNodeManager.Instance.RegisterNode(attackButtonNode);

            ScriptRoutine inputToWalkScript = new ScriptRoutine();
            inputToWalkScript.Name = "Input to walk";
            inputToWalkScript.Add("Is left stick active");
            inputToWalkScript.Add("Play walk animation");
            idleAnimation.AddScriptRoutine(inputToWalkScript);

            ScriptRoutine noInputToIdleScript = new ScriptRoutine();
            noInputToIdleScript.Name = "No input to idle";
            noInputToIdleScript.Add("Is left stick active");
            noInputToIdleScript.Add("Play idle animation");
            walkAnimation.AddScriptRoutine(noInputToIdleScript);

            ScriptRoutine toggleMotionDeltaScript = new ScriptRoutine();
            toggleMotionDeltaScript.Name = "Toggle motion delta";
            toggleMotionDeltaScript.Add("Is left stick active");
            toggleMotionDeltaScript.Add("Toggle motion delta");
            walkAnimation.AddScriptRoutine(toggleMotionDeltaScript);
            attackAnimation.AddScriptRoutine(toggleMotionDeltaScript);

            ScriptRoutine playAttackScript = new ScriptRoutine();
            playAttackScript.Name = "Play attack";
            playAttackScript.Add("If attack button hit");
            playAttackScript.Add("Play attack animation");
            walkAnimation.AddScriptRoutine(playAttackScript);
            idleAnimation.AddScriptRoutine(playAttackScript);

            ScriptRoutine keepAttackingScript = new ScriptRoutine();
            keepAttackingScript.Name = "Keep attacking";
            keepAttackingScript.Add("If attack button hit");
            keepAttackingScript.Add("Play attack animation");
            attackAnimation.AddFrameRoutine(1, keepAttackingScript);

            ScriptRoutine backToIdleScript = new ScriptRoutine();
            backToIdleScript.Name = "Back to idle";
            backToIdleScript.Add("If attack button hit");
            backToIdleScript.Add("Play idle animation");
            attackAnimation.AddFrameRoutine(1, backToIdleScript);

            //crispy
            //List<string> attackTrigger = new List<string>();
            //TriggerNode newTrig = new TriggerNode(TrigType.HITBOX, new Object[] { new Rectangle(-20, -20, 20, 20), Vector2.Zero, 0f, AffectFlags.ALL});
            //newTrig.Name = "Hitbox";
            //ScriptNodeManager.Instance.RegisterNode((INode)attackTrigger);
            //attackTrigger.Add(newTrig.Name);
            //attackAnimation.AddFrameScript(1, attackTrigger);
            //crispy

            ScriptNodeManager.Instance.SerializeNodes("ness.nodes");

            string filePath = Application.StartupPath;
            filePath += "\\Content\\" + "ness" + ".fap";

            Stream stream = File.Create(filePath);
            BinaryFormatter formatter = new BinaryFormatter();
            BinaryWriter writer = new BinaryWriter(stream);

            int numAnimations = 3;
            writer.Write(numAnimations);
            formatter.Serialize(stream, idleAnimation);
            formatter.Serialize(stream, walkAnimation);
            formatter.Serialize(stream, attackAnimation);

            stream.Close();
        }
Beispiel #4
0
        public static void InitAnimations()
        {
            Texture2D oldManTexture = WorldEditor.Instance.Content.Load<Texture2D>("oldManSheet");

            Animation walkAnimation = new Animation();
            walkAnimation.Name = "oldManWalk";
            walkAnimation.Texture = oldManTexture;
            walkAnimation.TextureName = "oldManSheet";

            Animation attackAnimation = new Animation();
            attackAnimation.Name = "oldManAttack";
            attackAnimation.Texture = oldManTexture;
            attackAnimation.TextureName = "oldManSheet";

            Animation idleAnimation = new Animation();
            idleAnimation.Name = "oldManIdle";
            idleAnimation.Texture = oldManTexture;
            idleAnimation.TextureName = "oldManSheet";

            Animation takeCoverAnimation = new Animation();
            takeCoverAnimation.Name = "oldManTakeCover";
            takeCoverAnimation.Texture = oldManTexture;
            takeCoverAnimation.TextureName = "oldManSheet";

            int frameOffset = 0;
            for (int index = 0; index < 6; index++)
            {
                takeCoverAnimation.SetFrameDuration(index, 2);
                takeCoverAnimation.AddFrame(RotationComponent.CardinalDirections.NONE, new Rectangle(frameOffset, 640, 128, 128), index);

                walkAnimation.SetFrameDuration(index, 3);
                walkAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(frameOffset, 0, 128, 128), index);
                walkAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(frameOffset, 128, 128, 128), index);
                walkAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(frameOffset, 256, 128, 128), index);
                walkAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(frameOffset, 384, 128, 128), index);
                walkAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(frameOffset, 512, 128, 128), index);

                if (index < 2)
                {
                    attackAnimation.SetFrameDuration(index, 2);
                    attackAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(frameOffset, 768, 128, 128), index);
                    attackAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(frameOffset + 384, 768, 128, 128), index);
                    attackAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(frameOffset, 896, 128, 128), index);
                    attackAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(frameOffset + 384, 896, 128, 128), index);
                    attackAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(768, frameOffset, 128, 128), index);
                }

                if (index == 0)
                {
                    idleAnimation.SetFrameDuration(index, 10);
                    idleAnimation.AddFrame(RotationComponent.CardinalDirections.E, new Rectangle(frameOffset, 0, 128, 128), index);
                    idleAnimation.AddFrame(RotationComponent.CardinalDirections.S, new Rectangle(frameOffset, 128, 128, 128), index);
                    idleAnimation.AddFrame(RotationComponent.CardinalDirections.N, new Rectangle(frameOffset, 256, 128, 128), index);
                    idleAnimation.AddFrame(RotationComponent.CardinalDirections.NE, new Rectangle(frameOffset, 384, 128, 128), index);
                    idleAnimation.AddFrame(RotationComponent.CardinalDirections.SE, new Rectangle(frameOffset, 512, 128, 128), index);
                }

                frameOffset += 128;
            }

            walkAnimation.DirectionMap[RotationComponent.CardinalDirections.SW] = RotationComponent.CardinalDirections.SE;
            walkAnimation.DirectionMap[RotationComponent.CardinalDirections.W] = RotationComponent.CardinalDirections.E;
            walkAnimation.DirectionMap[RotationComponent.CardinalDirections.NW] = RotationComponent.CardinalDirections.NE;

            idleAnimation.DirectionMap[RotationComponent.CardinalDirections.SW] = RotationComponent.CardinalDirections.SE;
            idleAnimation.DirectionMap[RotationComponent.CardinalDirections.W] = RotationComponent.CardinalDirections.E;
            idleAnimation.DirectionMap[RotationComponent.CardinalDirections.NW] = RotationComponent.CardinalDirections.NE;

            attackAnimation.DirectionMap[RotationComponent.CardinalDirections.SW] = RotationComponent.CardinalDirections.SE;
            attackAnimation.DirectionMap[RotationComponent.CardinalDirections.W] = RotationComponent.CardinalDirections.E;
            attackAnimation.DirectionMap[RotationComponent.CardinalDirections.NW] = RotationComponent.CardinalDirections.NE;

            takeCoverAnimation.DirectionMap[RotationComponent.CardinalDirections.SW] = RotationComponent.CardinalDirections.SE;
            takeCoverAnimation.DirectionMap[RotationComponent.CardinalDirections.W] = RotationComponent.CardinalDirections.E;
            takeCoverAnimation.DirectionMap[RotationComponent.CardinalDirections.NW] = RotationComponent.CardinalDirections.NE;

            walkAnimation.ChangeFrameMotionDelta(0, 0, new Vector2(0, 0.0f));
            walkAnimation.ChangeFrameMotionDelta(1, 0, new Vector2(0, 0.0f));
            walkAnimation.ChangeFrameMotionDelta(2, 0, new Vector2(0, 0.0f));
            walkAnimation.ChangeFrameMotionDelta(3, 0, new Vector2(0, 5.5f));
            walkAnimation.ChangeFrameMotionDelta(4, 0, new Vector2(0, 10.5f));
            walkAnimation.ChangeFrameMotionDelta(5, 0, new Vector2(0, 8.0f));

            attackAnimation.ChangeFrameMotionDelta(0, 10, new Vector2(0, -50f));
            attackAnimation.ChangeFrameMotionDelta(1, 10, new Vector2(0, -50f));

            AnimatedManager.Instance.AddAnimation("oldManIdle", idleAnimation);
            AnimatedManager.Instance.AddAnimation("oldManWalk", walkAnimation);
            AnimatedManager.Instance.AddAnimation("oldManAttack", attackAnimation);
            AnimatedManager.Instance.AddAnimation("oldManTakeCover", takeCoverAnimation);

            InputScriptNode isLeftStickActiveNode = new InputScriptNode();
            isLeftStickActiveNode.ScriptType = InputScriptNode.InputScriptType.TYPE_LEFT_STICK_ACTIVE;

            PlayAnimationScriptNode playWalkAnimScriptNode = new PlayAnimationScriptNode();
            playWalkAnimScriptNode.AnimationToQueue = "oldManWalk";
            playWalkAnimScriptNode.FrameToQueue = 0;
            playWalkAnimScriptNode.PlayIfTrue = true;

            PlayAnimationScriptNode playIdleAnimScriptNode = new PlayAnimationScriptNode();
            playIdleAnimScriptNode.AnimationToQueue = "oldManIdle";
            playIdleAnimScriptNode.FrameToQueue = 0;
            playIdleAnimScriptNode.PlayIfTrue = false;

            PlayAnimationScriptNode playTakeCoverAnimScriptNode = new PlayAnimationScriptNode();
            playTakeCoverAnimScriptNode.AnimationToQueue = "oldManTakeCover";
            playTakeCoverAnimScriptNode.FrameToQueue = 1;
            playTakeCoverAnimScriptNode.PlayIfTrue = true;

            ToggleMotionDeltaScriptNode toggleMotionDeltaNode = new ToggleMotionDeltaScriptNode();

            InputScriptNode attackButtonNode = new InputScriptNode();
            attackButtonNode.ScriptType = InputScriptNode.InputScriptType.TYPE_BUTTON_DOWN;
            attackButtonNode.SetInputValue("attack");

            InputScriptNode secondaryButtonNode = new InputScriptNode();
            secondaryButtonNode.ScriptType = InputScriptNode.InputScriptType.TYPE_BUTTON_DOWN;
            secondaryButtonNode.SetInputValue("secondary");

            PlayAnimationScriptNode playAttackScriptNode = new PlayAnimationScriptNode();
            playAttackScriptNode.PlayIfTrue = true;
            playAttackScriptNode.AnimationToQueue = "oldManAttack";

            PlayAnimationScriptNode backToIdleNode = new PlayAnimationScriptNode();
            backToIdleNode.AnimationToQueue = "oldManIdle";
            backToIdleNode.PlayIfTrue = false;

            PlayAnimationScriptNode stopUnderCoverNode = new PlayAnimationScriptNode();
            stopUnderCoverNode.AnimationToQueue = "oldManTakeCover";
            stopUnderCoverNode.FrameToQueue = 5;
            stopUnderCoverNode.PlayIfTrue = true;

            PlayAnimationScriptNode getOutOfCoverNode = new PlayAnimationScriptNode();
            getOutOfCoverNode.AnimationToQueue = "oldManTakeCover";
            getOutOfCoverNode.FrameToQueue = 4;
            getOutOfCoverNode.SpeedToQueue = -1.0f;
            getOutOfCoverNode.PlayIfTrue = false;

            isLeftStickActiveNode.Name = "Is left stick active";
            playWalkAnimScriptNode.Name = "Play walk animation";
            playIdleAnimScriptNode.Name = "Play idle animation";
            playTakeCoverAnimScriptNode.Name = "Play take cover animation";
            toggleMotionDeltaNode.Name = "Toggle motion delta";
            playAttackScriptNode.Name = "Play attack animation";
            attackButtonNode.Name = "If attack button hit";
            secondaryButtonNode.Name = "If secondary button hit";
            stopUnderCoverNode.Name = "Stop under cover";
            getOutOfCoverNode.Name = "Get out of cover";

            ScriptNodeManager.Instance.RegisterNode(isLeftStickActiveNode);
            ScriptNodeManager.Instance.RegisterNode(playWalkAnimScriptNode);
            ScriptNodeManager.Instance.RegisterNode(playIdleAnimScriptNode);
            ScriptNodeManager.Instance.RegisterNode(playTakeCoverAnimScriptNode);
            ScriptNodeManager.Instance.RegisterNode(playAttackScriptNode);
            ScriptNodeManager.Instance.RegisterNode(toggleMotionDeltaNode);
            ScriptNodeManager.Instance.RegisterNode(attackButtonNode);
            ScriptNodeManager.Instance.RegisterNode(secondaryButtonNode);
            ScriptNodeManager.Instance.RegisterNode(stopUnderCoverNode);
            ScriptNodeManager.Instance.RegisterNode(getOutOfCoverNode);

            ScriptNodeManager.Instance.SerializeNodes("oldMan.nodes");

            ScriptRoutine inputToWalkScript = new ScriptRoutine();
            inputToWalkScript.Name = "Input to walk";
            inputToWalkScript.Add("Is left stick active");
            inputToWalkScript.Add("Play walk animation");
            idleAnimation.AddScriptRoutine(inputToWalkScript);

            ScriptRoutine noInputToIdleScript = new ScriptRoutine();
            noInputToIdleScript.Name = "No input to idle";
            noInputToIdleScript.Add("Is left stick active");
            noInputToIdleScript.Add("Play idle animation");
            walkAnimation.AddScriptRoutine(noInputToIdleScript);

            ScriptRoutine toggleMotionDeltaScript = new ScriptRoutine();
            toggleMotionDeltaScript.Name = "Toggle motion delta";
            toggleMotionDeltaScript.Add("Is left stick active");
            toggleMotionDeltaScript.Add("Toggle motion delta");
            walkAnimation.AddScriptRoutine(toggleMotionDeltaScript);
            attackAnimation.AddScriptRoutine(toggleMotionDeltaScript);

            ScriptRoutine playAttackScript = new ScriptRoutine();
            playAttackScript.Name = "Play attack";
            playAttackScript.Add("If attack button hit");
            playAttackScript.Add("Play attack animation");
            walkAnimation.AddScriptRoutine(playAttackScript);
            idleAnimation.AddScriptRoutine(playAttackScript);

            ScriptRoutine playSecondaryScript = new ScriptRoutine();
            playSecondaryScript.Name = "Play take cover";
            playSecondaryScript.Add("If secondary button hit");
            playSecondaryScript.Add("Play take cover animation");
            walkAnimation.AddScriptRoutine(playSecondaryScript);
            idleAnimation.AddScriptRoutine(playSecondaryScript);

            ScriptRoutine stopUnderCoverScript = new ScriptRoutine();
            stopUnderCoverScript.Name = "Stop while in cover";
            stopUnderCoverScript.Add("If secondary button hit");
            stopUnderCoverScript.Add("Stop under cover");
            takeCoverAnimation.AddFrameRoutine(5, stopUnderCoverScript);

            ScriptRoutine keepAttackingScript = new ScriptRoutine();
            keepAttackingScript.Name = "Keep attacking";
            keepAttackingScript.Add("If attack button hit");
            keepAttackingScript.Add("Play attack animation");
            attackAnimation.AddFrameRoutine(1, keepAttackingScript);

            ScriptRoutine backToIdleScript = new ScriptRoutine();
            backToIdleScript.Name = "Back to idle";
            backToIdleScript.Add("If attack button hit");
            backToIdleScript.Add("Play idle animation");
            attackAnimation.AddFrameRoutine(1, backToIdleScript);

            ScriptRoutine stopTakingCoverScript = new ScriptRoutine();
            stopTakingCoverScript.Name = "Get out of cover";
            stopTakingCoverScript.Add("If secondary button hit");
            stopTakingCoverScript.Add("Get out of cover");
            takeCoverAnimation.AddFrameRoutine(5, stopTakingCoverScript);

            ScriptRoutine getOutOfCoverScript = new ScriptRoutine();
            getOutOfCoverScript.Name = "Idle after cover";
            getOutOfCoverScript.Add("Play idle animation");
            takeCoverAnimation.AddFrameRoutine(0, getOutOfCoverScript);

            ScriptNodeManager.Instance.SerializeNodes("nodes.MILF");

            string filePath = Application.StartupPath;
            filePath += "\\Content\\" + "oldMan" + ".fap";

            Stream stream = File.Create(filePath);
            BinaryFormatter formatter = new BinaryFormatter();
            BinaryWriter writer = new BinaryWriter(stream);

            int numAnimations = 4;
            writer.Write(numAnimations);
            formatter.Serialize(stream, idleAnimation);
            formatter.Serialize(stream, walkAnimation);
            formatter.Serialize(stream, attackAnimation);
            formatter.Serialize(stream, takeCoverAnimation);

            stream.Close();
        }
        private void mAnimationNameComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            StopAnimation();

            mCurrentAnimation = mAnimations[mAnimationNameComboBox.Text];

            if (mCurrentAnimation.TextureName != null)
            {
                string filename = mContentDirectory + "\\Content\\" + mCurrentAnimation.TextureName;
                mSpriteSheetImage = Image.FromFile(filename);
                mSpriteSheetWidth = mSpriteSheetImage.Width;
                mSpriteSheetHeight = mSpriteSheetImage.Height;
                mPictureBox.Picture = filename;
            }
            else if (mOpenImageFilename != "")
            {
                //MessageBox.Show("Sprite sheet filename is NULL for animation: " + mCurrentAnimation.Name);
                SetTextureName(mOpenImageFilename);
            }
            else
            {
                loadSpriteSheetToolStripMenuItem_Click(null, null);
            }

            if (mCurrentAnimation.Frames.ContainsKey(RotationComponent.CardinalDirections.N))
            {
                // Check if flipping is enabled
                if (mCurrentAnimation.DirectionMap[RotationComponent.CardinalDirections.SW] == RotationComponent.CardinalDirections.SW)
                {
                    if (mMultidirCheckBox.Checked == false) mSuppressChange = true;
                    mMultidirCheckBox.Checked = true;
                    if (mFlippingCheckBox.Checked) mSuppressChange = true;
                    mFlippingCheckBox.Checked = false;
                }
                else
                {
                    // Selected Animation is multi-directional, without flipping
                    if (mMultidirCheckBox.Checked == false) mSuppressChange = true;
                    mMultidirCheckBox.Checked = true;
                    if (mFlippingCheckBox.Checked == false) mSuppressChange = true;
                    mFlippingCheckBox.Checked = true;
                }
                mMultidirCheckBox.Enabled = true;
                mFlippingCheckBox.Enabled = true;
                SetDirections();
            }
            else if (mCurrentAnimation.Frames.ContainsKey(RotationComponent.CardinalDirections.NONE))
            {
                // Selected Animation is one-directional
                if (mFlippingCheckBox.Checked) mSuppressChange = true;
                mFlippingCheckBox.Checked = false;
                mFlippingCheckBox.Enabled = false;
                if (mMultidirCheckBox.Checked) mSuppressChange = true;
                mMultidirCheckBox.Checked = false;
                mMultidirCheckBox.Enabled = true;
                SetDirections();
            }
            else // Selected animation is new/undefined
            {
                if (mFlippingCheckBox.Checked) mSuppressChange = true;
                mFlippingCheckBox.Checked = false;
                mFlippingCheckBox.Enabled = false;
                if (mMultidirCheckBox.Checked) mSuppressChange = true;
                mMultidirCheckBox.Checked = false;
                mMultidirCheckBox.Enabled = true;

                SetDirections();
            }

            if (mDirectionComboBox.SelectedIndex == 0)
            {
                // This is taken care of when the direction is changed (x->0)
                mKeyframeImageList.Clear();
                Bitmap imageToCopy = new Bitmap(mSpriteSheetImage);
                KeyFrameDictionary kfd = mCurrentAnimation.Frames[mCurrentDirection];
                for (int i = 0; i < kfd.Values.Count; i++)
                {
                    System.Drawing.Rectangle frameRect = new System.Drawing.Rectangle();
                    frameRect.X = (int)(kfd[i].U * mSpriteSheetWidth);
                    frameRect.Y = (int)(kfd[i].V * mSpriteSheetHeight);
                    frameRect.Width = (int)(kfd[i].Width * mSpriteSheetWidth);
                    frameRect.Height = (int)(kfd[i].Height * mSpriteSheetHeight);
                    Bitmap croppedImage = imageToCopy.Clone(frameRect, imageToCopy.PixelFormat);
                    mKeyframeImageList.Add(croppedImage);
                }

                mImageView.Clear();
                for (int ii = 0; ii < mKeyframeImageList.Count; ii++)
                {
                    mImageView.AddImage(mKeyframeImageList[ii]);
                    mImageView.PictureBoxes[mImageView.PictureBoxes.Count - 1].MouseClick += new System.Windows.Forms.MouseEventHandler(imageViewKeyframe_Click);
                }
                SetTotalFrameCount();
            }
            else
            {
                mDirectionComboBox.SelectedIndex = 0;
            }

            mAddKeyframeButton.Enabled = true;

            mScriptEditorSuite.SetActiveScript(mCurrentAnimation.AnimationScripts, mCurrentAnimation.Name);
            mScriptEditorSuite.Enabled = true;
        }
        private void mAddAnimationButton_Click(object sender, EventArgs e)
        {
            mTextEntryDialog.ShowDialog();

            if ((mTextEntryDialog.DialogResult == DialogResult.OK) && (mTextEntryDialog.Message != string.Empty))
            {
                if (mAnimations.ContainsKey(mTextEntryDialog.Message))
                {
                    MessageBox.Show("Animation '" + mTextEntryDialog.Message + "' already exists.");
                }
                else
                {
                    mCurrentAnimation = new Animation();
                    mCurrentAnimation.Name = mTextEntryDialog.Message;
                    mAnimations.Add(mTextEntryDialog.Message, mCurrentAnimation);

                    if (mFlippingCheckBox.Checked) mSuppressChange = true;
                    mFlippingCheckBox.Checked = false;
                    mFlippingCheckBox.Enabled = false;
                    if (mMultidirCheckBox.Checked) mSuppressChange = true;
                    mMultidirCheckBox.Checked = false;
                    mMultidirCheckBox.Enabled = true;
                    SetDirections();

                    mAnimationNameComboBox.Items.Add(mTextEntryDialog.Message);
                    mAnimationNameComboBox.SelectedIndex = mAnimationNameComboBox.Items.Count-1;
                }

                mTextEntryDialog.Message = string.Empty;
            }
        }
        private void newProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog fDialog = new SaveFileDialog();
            fDialog.Title = "Create FNA Animation Project";
            fDialog.Filter = ".fnAnim Files|*.fnAnim";
            if (fDialog.ShowDialog() == DialogResult.OK)
            {
                mAnimationProjectFilename = fDialog.FileName.ToString();
                if (mAnimationProjectFilename != string.Empty)
                {
                    if (System.IO.File.Exists(mAnimationProjectFilename) == false)
                    {
                        System.IO.File.Create(mAnimationProjectFilename);
                    }

                    mCurrentAnimation = null;
                    mAnimations = new Dictionary<string, Animation>();
                    mTabControl.Enabled = true;
                    mKeyframePanel.Enabled = true;

                    mContentDirectory = mAnimationProjectFilename;
                    mContentDirectory = mContentDirectory.Remove(mContentDirectory.IndexOf("\\Content\\"));

                    mAnimationNameComboBox.Items.Clear();

                    for (int ii = 0; ii < mKeyframeImageList.Count; ii++)
                    {
                        mImageView.PictureBoxes[mImageView.PictureBoxes.Count - 1].MouseClick -= new System.Windows.Forms.MouseEventHandler(imageViewKeyframe_Click);
                    }
                    mKeyframeImageList.Clear();
                    mImageView.Clear();
                }
            }
        }
        private void mRemoveAnimationButton_Click(object sender, EventArgs e)
        {
            StopAnimation();

            string name = mAnimationNameComboBox.Text;
            mAnimationNameComboBox.Items.Remove(name);
            mAnimationNameComboBox.SelectedItem = null;

            mCurrentAnimation = null;
            mAnimations.Remove(name);

            for (int ii = 0; ii < mKeyframeImageList.Count; ii++)
            {
                mImageView.PictureBoxes[mImageView.PictureBoxes.Count - 1].MouseClick -= new System.Windows.Forms.MouseEventHandler(imageViewKeyframe_Click);
            }
            mKeyframeImageList.Clear();
            mImageView.Clear();

            mDirectionComboBox.Items.Clear();
            mDirectionComboBox.Enabled = false;
            mMultidirCheckBox.Enabled = false;
            mFlippingCheckBox.Enabled = false;
            mMultiSelectLabel.Visible = false;
            mScriptEditorSuite.ClearActiveScript();
            mScriptEditorSuite.Enabled = false;
        }