Example #1
0
 public void Update(GameTime time)
 {
     //update key listeners
     if (IsValueAttached)
     {
         keyListener_Left.Update(time);
         keyListener_Right.Update(time);
     }
     else
     {
         keyListener_Enter.Update(time);
     }
 }
Example #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();
        }
Example #3
0
        public void Update(GameTime time)
        {
            var kbState = Keyboard.GetState();

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

            // Movement
            if (kbState.IsKeyDown(Keys.A))
            {
                Props.AddForceX(-acceleration * (isRunning ? runModifier : 1));
            }
            else if (kbState.IsKeyDown(Keys.D))
            {
                Props.AddForceX(acceleration * (isRunning ? runModifier : 1));
            }

            if (kbState.IsKeyDown(Keys.W))
            {
                Props.AddForceY(-acceleration * (isRunning ? runModifier : 1));
            }
            else if (kbState.IsKeyDown(Keys.S))
            {
                Props.AddForceY(acceleration * (isRunning ? runModifier : 1));
            }

            // Anims
            animCurrent.Update(time.ElapsedGameTime.Milliseconds);

            // Ensure correct anim is being used
            if (IsJetPacking)
            {
                if (animCurrent.Name != animJetting.Name)
                {
                    animCurrent = animJetting;
                }
            }
            else if (Props.IsGrounded)
            {
                if (Props.Velocity.X != 0 && animCurrent.Name != animWalking.Name)
                {
                    animCurrent = animWalking;
                }
                else if (Props.Velocity.X == 0 && animCurrent.Name != animStanding.Name)
                {
                    animCurrent = animStanding;
                }
            }
            else
            {
                if (animCurrent.Name != animStanding.Name)
                {
                    animCurrent = animStanding;
                }
            }

            /*
             * // Jump action
             * var canJump = (Props.IsGrounded && Props.Velocity.Y == 0);
             *
             * if (kbState.IsKeyDown(Keys.Space) && canJump)
             * {
             *  Props.AddForceY(-jumpPower, overrideTopSpeed: true);
             *
             *  // raise event
             *  eventBus.QueueNotification(Events.PlayerJumped);
             * }
             *
             * // Jetpack
             * if (kbState.IsKeyDown(Keys.W))
             * {
             *  IsJetPacking = true;
             *  Props.AddForceY(-jetPower, overrideTopSpeed: true);
             * }
             * else
             * {
             *  IsJetPacking = false;
             * }
             */

            // projectiles
            fireListener.Update(time);

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

            // aim
            base.Props.Rotation = Bonsai.Framework.Maths.GameMathHelper
                                  .GetDirectionInRadians(this.Position, (camera.CurrentFocus - BonsaiGame.Current.ScreenCenter) + new Vector2(mousePos.X, mousePos.Y));
        }