Beispiel #1
0
        public override void Update()
        {
            var distanceFromTarget = (Position - curTargetPoint).Length();

            if (distanceFromTarget <= 0.01)
            {
                nextState();
            }

            float dt = (float)Context.GameTime.ElapsedGameTime.TotalSeconds;

            if (nextStopTime < 0.1 * activityTime * (walking ? 1 : 0.1))
            {
                walking      = !walking;
                nextStopTime = (float)Utils.Random.NextDouble();
                activityTime = 0;
            }

            if (!walking)
            {
                var direction = curTargetPoint - Position;
                direction.Normalize();
                var delta = direction * walkSpeed * dt;
                Position += delta;
                orientationManager.UpdateOrientation(delta);
            }
            else
            {
                orientationManager.UpdateOrientation(Vector3.Zero);
            }

            activityTime += dt;
        }
Beispiel #2
0
        private void HandleWalking()
        {
            KeyboardManager kb        = Context.Keyboard;
            Vector3         changeDir = Vector3.Zero;

            if (Context.World.TimeToLive <= 0)
            {
                orientationManager.Dead();
                return;
            }

            if (kb.IsKeyDown(Keys.Right))
            {
                changeDir += new Vector3(1, 0, 0);
            }

            if (kb.IsKeyDown(Keys.Left))
            {
                changeDir += new Vector3(-1, 0, 0);
            }

            if (kb.IsKeyDown(Keys.Up))
            {
                changeDir += new Vector3(0, -1, 0);
            }

            if (kb.IsKeyDown(Keys.Down))
            {
                changeDir += new Vector3(0, 1, 0);
            }

            if (changeDir != Vector3.Zero)
            {
                changeDir.Normalize();
            }

            Vector3 posChange = changeDir * WalkSpeed * (float)Context.GameTime.ElapsedGameTime.TotalSeconds;

            Position += posChange;
            orientationManager.UpdateOrientation(posChange);
        }