Example #1
0
        private void SwitchMovement(bool isCrouching, bool isRunning)
        {
            AnimationController contr = Owner.GetComponent <AnimationController>();
            string mov1 = (this.isCrouching ? "crouch" : (this.isRunning ? "run" : "walk"));

            this.isCrouching = isCrouching; this.isRunning = isRunning;
            string mov2 = (isCrouching ? "crouch" : (isRunning ? "run" : "walk"));

            if (contr.StopAnimation(mov1 + "Forward", 0.2f))
            {
                contr.PlayAnimation(mov2 + "Forward", 1, 0.2f);
            }
            if (contr.StopAnimation(mov1 + "Backward", 0.2f))
            {
                contr.PlayAnimation(mov2 + "Backward", 1, 0.2f);
            }
            if (contr.StopAnimation(mov1 + "Left", 0.2f))
            {
                contr.PlayAnimation(mov2 + "Left", 1, 0.2f);
            }
            if (contr.StopAnimation(mov1 + "Right", 0.2f))
            {
                contr.PlayAnimation(mov2 + "Right", 1, 0.2f);
            }
            if (isCrouching)
            {
                contr.SetBindPose("crouchForward", 0.2f);
            }
            else
            {
                contr.SetBindPose("death", 0.2f);
            }
        }
Example #2
0
        protected override void HandleDeath()
        {
            decisionTree.InterruptCurrentDecision();
            StopMoving(null);
            Minimap.Enemies.Remove(Owner);
            if (weapon != null)
            {
                weapon.Destroy();
            }
            AnimationController contr = Owner.GetComponent <AnimationController>();

            if (contr != null)
            {
                contr.StopAllAnimations(0.2f);
                contr.PlayAnimation("death", 100, 0f);
                contr.SetBindPose("death", 0.2f, 1);
            }
            List <Component> comps = Owner.GetComponents <Component>();

            foreach (Component comp in comps)
            {
                if (!(comp is AnimationController) && !(comp is MeshInstance))
                {
                    comp.Enabled = false;
                }
            }
        }
Example #3
0
        public override void DealDamage(float amount, Weapon causer)
        {
            base.DealDamage(amount, causer);

            if (amount > 0)
            {
                AnimationController contr = Owner.GetComponent <AnimationController>();
                if (contr != null)
                {
                    contr.PlayAnimation("hit", 5, 0.2f);
                }
            }

            if (causer.Owner.Parent.Parent.Name == "Player" && attributes[1] != causer.Owner.Parent.Parent)
            {
                attributes[1] = causer.Owner.Parent.Parent;
                state         = EnemyState.Combat;
                decisionTree.InterruptCurrentDecision();
            }
        }
Example #4
0
        private void RecordingButton(PressedActionArgs args)
        {
            Rigidbody rig = Owner.GetComponent <Rigidbody>();

            if (!hologramRecording && !hologramPlaying && (rig == null || rig.IsGrounded || !rig.GravityEnabled))
            {
                GameObject hologramRecording = new GameObject("HologramRecorder", Owner.LocalPosition,
                                                              Owner.LocalQuaternionRotation, Owner.LocalScale, Owner.Scene, Owner.Parent);
                hologramRecording.AddComponent(new HologramRecorder(5.0f, 100, StopRecording));
                hologramRecording.AddComponent(new Rigidbody(Owner.GetComponent <Rigidbody>()));
                Collider holCol = hologramRecording.AddNewComponent <Collider>();
                Bounding_Volumes.BoundingBox bound = (Owner.GetComponent <Collider>().bound as Bounding_Volumes.BoundingBox);
                holCol.bound = new Bounding_Volumes.BoundingBox(holCol, bound.Center, new Vector3(bound.HalfLength, bound.HalfHeight, bound.HalfWidth));
                MeshInstance mesh = Owner.GetComponent <MeshInstance>();
                if (mesh != null)
                {
                    hologramRecording.AddComponent(new MeshInstance(mesh));
                }
                if (PlayerMesh != null)
                {
                    Owner.AddComponent(PlayerMesh);
                    AnimationController contr = Owner.AddNewComponent <AnimationController>();
                    contr.BindAnimation("idle", isCrouching ? 7 : 6, true);
                    contr.PlayAnimation("idle");
                }
                Stay(null);
                if (getWeapon() != null)
                {
                    getWeapon().Owner.IsVisible = false;
                }
                player         = Owner;
                playerRotation = Owner.LocalQuaternionRotation;
                Vector3 rotation = Owner.LocalEulerRotation;
                Owner.RemoveComponent(this);
                hologramRecording.AddComponent(this);
                Owner.Scene.Camera.Parent = hologramRecording;
                rotation.Y = 0; rotation.Z = 0;
                player.LocalEulerRotation = rotation;
                this.hologramRecording    = true;
            }
        }
Example #5
0
        public override void Update(GameTime gameTime)
        {
            overallTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (overallTime < path.Duration)
            {
                List <Pair <Pair <float, float?>, Pair <GameAction, bool> > > currentActions = path.Actions.FindAll(x => (x.First.First <overallTime && x.First.Second> overallTime));
                foreach (Pair <Pair <float, float?>, Pair <GameAction, bool> > action in path.Actions)
                {
                    if (action.First.First < overallTime && action.First.Second > overallTime && !action.Second.Second)
                    {
                        action.Second.Second = true;
                        AnimationController contr = Owner.GetComponent <AnimationController>();
                        if (contr != null)
                        {
                            string mov = (isCrouching ? "crouch" : (isRunning ? "run" : "walk"));
                            switch (action.Second.First)
                            {
                            case GameAction.CROUCH: SwitchMovement(true, isRunning); break;

                            case GameAction.JUMP: if (!isCrouching)
                                {
                                    contr.PlayAnimation("jump", 100, 0.2f);
                                }
                                break;

                            case GameAction.RUN: SwitchMovement(isCrouching, true); break;

                            case GameAction.MOVE_FORWARD: contr.PlayAnimation(mov + "Forward", 1, 0.2f); break;

                            case GameAction.MOVE_BACKWARD: contr.PlayAnimation(mov + "Backward", 1, 0.2f); break;

                            case GameAction.STRAFE_LEFT: contr.PlayAnimation(mov + "Left", 1, 0.2f); break;

                            case GameAction.STRAFE_RIGHT: contr.PlayAnimation(mov + "Right", 1, 0.2f); break;
                            }
                        }
                    }

                    if (action.First.Second < overallTime && action.Second.Second)
                    {
                        action.Second.Second = false;
                        AnimationController contr = Owner.GetComponent <AnimationController>();
                        if (contr != null)
                        {
                            string mov = (isCrouching ? "crouch" : (isRunning ? "run" : "walk"));
                            switch (action.Second.First)
                            {
                            case GameAction.CROUCH: SwitchMovement(false, isRunning); break;

                            case GameAction.JUMP: break;

                            case GameAction.RUN: SwitchMovement(isCrouching, false); break;

                            case GameAction.MOVE_FORWARD: contr.StopAnimation(mov + "Forward", 0.2f); break;

                            case GameAction.MOVE_BACKWARD: contr.StopAnimation(mov + "Backward", 0.2f); break;

                            case GameAction.STRAFE_LEFT: contr.StopAnimation(mov + "Left", 0.2f); break;

                            case GameAction.STRAFE_RIGHT: contr.StopAnimation(mov + "Right", 0.2f); break;
                            }
                        }
                    }
                }

                if (index < path.LocalPositions.Count - 1)
                {
                    time += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    Owner.LocalPosition = Vector3.LerpPrecise(path.LocalPositions[index], path.LocalPositions[index + 1], time / durationOfStep);
                    float rot1 = path.LocalRotations[index];
                    float rot2 = path.LocalRotations[index + 1];
                    if (Math.Abs(rot1 - rot2) > 180)
                    {
                        if (rot2 < 180)
                        {
                            rot2 += 360;
                        }
                        else
                        {
                            rot2 -= 360;
                        }
                    }
                    float newRot = MathHelper.Lerp(rot1, rot2, time / durationOfStep);
                    if (newRot > 360)
                    {
                        newRot -= 360;
                    }
                    if (newRot < 0)
                    {
                        newRot += 360;
                    }
                    Owner.LocalEulerRotation = Vector3.UnitX * newRot;
                    if (time > durationOfStep)
                    {
                        time = 0.0f;
                        index++;
                    }
                }
            }
            else
            {
                StopPlayback(null);
            }
        }