Exemple #1
0
        public override void Update()
        {
            //temporaryControls();
            if (GameKeyState.IsKeyPressed(Keys.P)) //test key
            {
                IsMouseLocked = !IsMouseLocked;
            }

            if (IsMouseLocked)
            {
                float mouseDirectionX = GameMouseState.ScreenX - (BananaGame.GameCamera.CameraViewPort.Width / 2);
                float mouseDirectionY = GameMouseState.ScreenY - (BananaGame.GameCamera.CameraViewPort.Height / 2);

                if (mouseDirectionX != 0)
                {
                    BananaGame.GameCamera.LeftRightRotation -= Camera.ROTATION_SPEED * (mouseDirectionX / 50);
                }

                if (mouseDirectionY != 0)
                {
                    float newPosition = BananaGame.GameCamera.UpDownRotation - Camera.ROTATION_SPEED * (mouseDirectionY / 50);
                    if (newPosition < -1.55f)
                    {
                        newPosition = -1.55f;
                    }
                    else if (newPosition > 1.55f)
                    {
                        newPosition = 1.55f;
                    }
                    BananaGame.GameCamera.UpDownRotation = newPosition;
                }

                Mouse.SetPosition(BananaGame.GameCamera.CameraViewPort.Width / 2, BananaGame.GameCamera.CameraViewPort.Height / 2);
            }
        }
        public override void Update()
        {
            Vector2 moveVector = Vector2.Zero;

            if (GameKeyState.IsKeyDown(ForwardKey))
            {
                moveVector += new Vector2(0, 1);
                if (SelectedPlayer.Collection.CurrentAnimationName != "up") //move to player
                {
                    SelectedPlayer.Collection.PlayAnimation("up");
                }
            }
            else if (GameKeyState.IsKeyDown(BackKey))
            {
                moveVector += new Vector2(0, -1);
                if (SelectedPlayer.Collection.CurrentAnimationName != "down")
                {
                    SelectedPlayer.Collection.PlayAnimation("down");
                }
            }
            else if (GameKeyState.IsKeyDown(LeftKey))
            {
                moveVector += new Vector2(-1, 0);
                if (SelectedPlayer.Collection.CurrentAnimationName != "left")
                {
                    SelectedPlayer.Collection.PlayAnimation("left");
                }
            }
            else if (GameKeyState.IsKeyDown(RightKey))
            {
                moveVector += new Vector2(1, 0);
                if (SelectedPlayer.Collection.CurrentAnimationName != "right")
                {
                    SelectedPlayer.Collection.PlayAnimation("right");
                }
            }
            else
            {
                if (SelectedPlayer.Collection.CurrentAnimationName == "up")
                {
                    SelectedPlayer.Collection.PlayAnimation("standUp");
                }
                else if (SelectedPlayer.Collection.CurrentAnimationName == "down")
                {
                    SelectedPlayer.Collection.PlayAnimation("standDown");
                }
                else if (SelectedPlayer.Collection.CurrentAnimationName == "left")
                {
                    SelectedPlayer.Collection.PlayAnimation("standLeft");
                }
                else if (SelectedPlayer.Collection.CurrentAnimationName == "right")
                {
                    SelectedPlayer.Collection.PlayAnimation("standRight");
                }
            }

            /// Test move for movePlayerToHere()
            /// Hold the Z button to test
            if (GameKeyState.IsKeyPressed(Keys.Z))
            {
                movePlayerToHere();
            }

            //if (GameKeyState.IsKeyDown(JumpKey))
            //{
            //    moveVector += Vector3.Up;
            //}

            //if (GameKeyState.IsKeyPressed(Keys.F))
            //{
            //    Diamond dia = new Diamond(SelectedPlayer.Scanner.NearAimPoint);
            //    dia.Direction = FenceGame.GameCamera.LookVector;
            //    dia.Load();
            //    ProjectileManager.Add(dia);
            //}

            //if (GameKeyState.IsKeyPressed(Keys.J))
            //{
            //    SelectedPlayer.PhysicsModel.IsJumping = true;
            //}

            //if (GameKeyState.IsKeyDown(DecendKey))
            //{
            //    moveVector += Vector3.Down;
            //}

            //if (GameKeyState.IsKeyPressed(Keys.Q))
            //{
            //    SelectedPlayer.TestTool.SwitchItems();
            //}

            //if (GameMouseState.IsLeftButtonClicked())
            //{
            //    SelectedPlayer.TestTool.Use();
            //}

            //if (GameMouseState.IsMiddleButtonClicked())
            //{
            //    SelectedPlayer.TestTool.AltUse();
            //}

            //if (GameKeyState.IsKeyPressed(Keys.NumPad9))
            //{
            //    SelectedPlayer.TestTool.BuildTool.RotateRight();
            //}

            if (moveVector != Vector2.Zero)
            {
                //Matrix rotationMatrix = Matrix.CreateRotationY(FenceGame.GameCamera.LeftRightRotation);
                //Vector3 rotatedVector = Vector3.Transform(moveVector, rotationMatrix);
                SelectedPlayer.AddAcceleration(moveVector);
            }
        }