示例#1
0
文件: Bot.cs 项目: kallotec/Bonsai
        public void Update(GameTime time)
        {
            var kbState = Keyboard.GetState();

            // move to point
            var isAtPoint = Math.Abs(GameMathHelper.CalculateDistanceBetween(Props.Position, movingTo)) < 2f;

            if (!isAtPoint)
            {
                // look at point
                Props.Rotation = GameMathHelper.GetDirectionInRadians(Props.Position, movingTo);

                var force = GameMathHelper.UpdateVelocity(
                    Props.Rotation,
                    5f);

                Props.AddForce(force);
            }
            else
            {
                if (waypointsQueue.Count == 0)
                {
                    allWaypoints.Reverse();
                    waypointsQueue = new Queue <Vector2>(allWaypoints);
                }

                movingTo = waypointsQueue.Dequeue();
            }
        }
示例#2
0
        public void Update(GameTime time)
        {
            var kbState = Keyboard.GetState();

            var isRunning = kbState.IsKeyDown(Keys.LeftShift);

            // Movement
            if (kbState.IsKeyDown(Keys.A))
            {
                var leftAngle = Props.Rotation + MathHelper.ToRadians(-90);
                var force     = Bonsai.Framework.Maths.GameMathHelper.UpdateVelocity(
                    leftAngle,
                    5f);

                Props.AddForce(force);
            }
            else if (kbState.IsKeyDown(Keys.D))
            {
                var rightAngle = Props.Rotation + MathHelper.ToRadians(90);
                var force      = Bonsai.Framework.Maths.GameMathHelper.UpdateVelocity(
                    rightAngle,
                    5f);

                Props.AddForce(force);
            }

            if (kbState.IsKeyDown(Keys.W))
            {
                var force = Bonsai.Framework.Maths.GameMathHelper.UpdateVelocity(
                    Props.Rotation,
                    10f * (isRunning ? 1.5f : 1f));

                Props.AddForce(force);
            }
            else if (kbState.IsKeyDown(Keys.S))
            {
                var force = Bonsai.Framework.Maths.GameMathHelper.UpdateVelocity(
                    Props.Rotation,
                    -5f);

                Props.AddForce(force);
            }

            // projectiles
            fireListener.Update(time);

            var mouseState = Mouse.GetState();
            var mousePos   = mouseState.Position;

            if (lastMouseX == null)
            {
                lastMouseX = mousePos.X;
            }

            var mouseHorizontalMovement = mousePos.X - lastMouseX.Value;

            lastMouseX = mousePos.X;

            // aim

            /*base.Props.DirectionAim = Bonsai.Framework.Maths.MathHelper
             *  .GetDirectionInRadians(this.Position, (camera.CurrentFocus - BonsaiGame.Current.ScreenCenter) + new Vector2(mousePos.X, mousePos.Y));
             */

            var minRadians = 0f;
            var maxRadians = MathHelper.ToRadians(360);

            var dir = base.Props.Rotation;

            dir = dir + (mouseHorizontalMovement * 0.01f);

            if (dir < minRadians)
            {
                dir = maxRadians;
            }
            else if (dir > maxRadians)
            {
                dir = minRadians;
            }

            base.Props.Rotation = dir;

            // show tip
            canOpenBox.Value = Props.OverlappingObjects.OfType <LootBox>().Any();
        }