예제 #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            currentTime += gameTime.ElapsedGameTime.Milliseconds;

            crrKS = Keyboard.GetState();

            if (preKS.IsKeyUp(Keys.S) && preKS.IsKeyUp(Keys.A) && preKS.IsKeyUp(Keys.D) && preKS.IsKeyUp(Keys.W))//Down , Left , Right , Up
            {
                pers.Direction     = Direction.Stop;
                pers.PersDirection = PersDirection.Standart;
            }

            //стоит сделать так , чтобы перс мог ходить по диагонали //правил код CreaHaGame                    \/
            if (Keyboard.GetState().IsKeyDown(Keys.A) && Keyboard.GetState().IsKeyDown(Keys.W))//left && Up
            {
                //code...
                pers.Direction     = Direction.LeftUp;
                pers.PersDirection = PersDirection.Run;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) && Keyboard.GetState().IsKeyDown(Keys.D))//Up && right
            {
                //code...
                pers.Direction     = Direction.UpRight;
                pers.PersDirection = PersDirection.Run;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.D) && Keyboard.GetState().IsKeyDown(Keys.S))//right && down
            {
                //code...
                pers.Direction     = Direction.RightDown;
                pers.PersDirection = PersDirection.Run;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.S) && Keyboard.GetState().IsKeyDown(Keys.A))//down && left
            {
                //code...
                pers.Direction     = Direction.DownLeft;
                pers.PersDirection = PersDirection.Run;
            }

            //поменял местами с верхней проеркой
            //лол , только так работает , если только проверять букву А , то if перехватывает всегда и по деагонали не идет перс
            if (Keyboard.GetState().IsKeyDown(Keys.A) && !(Keyboard.GetState().IsKeyDown(Keys.W)) && !(Keyboard.GetState().IsKeyDown(Keys.S)))
            {
                pers.Direction     = Direction.Left;
                pers.PersDirection = PersDirection.Run;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.D) && !(Keyboard.GetState().IsKeyDown(Keys.S)) && !(Keyboard.GetState().IsKeyDown(Keys.W)))
            {
                pers.Direction     = Direction.Right;
                pers.PersDirection = PersDirection.Run;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) && !(Keyboard.GetState().IsKeyDown(Keys.A)) && !(Keyboard.GetState().IsKeyDown(Keys.D)))
            {
                pers.Direction     = Direction.Up;
                pers.PersDirection = PersDirection.Run;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.S) && !(Keyboard.GetState().IsKeyDown(Keys.A)) && !(Keyboard.GetState().IsKeyDown(Keys.D)))
            {
                pers.Direction     = Direction.Down;
                pers.PersDirection = PersDirection.Run;
            }//правил код CreaHaGame --- --- --- --- --- --- ---     /\       ======         ======        /\

            if (currentTime > period)
            {
                currentTime -= period;
                pers.Animation(3, 1, 1);
            }

            pers.Move(3);

            preKS = crrKS;
            base.Update(gameTime);
        }
예제 #2
0
        protected override void Update(GameTime gameTime)
        {
            try
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    Exit();
                }

                currentTime += gameTime.ElapsedGameTime.Milliseconds;

                crrKS = Keyboard.GetState();
                MouseState CurrentMouse = Mouse.GetState();//отслеживаем мышь (мышке картинку сделать бы)



                //управление движением персонажа
                if (preKS.IsKeyUp(Keys.S) && preKS.IsKeyUp(Keys.A) && preKS.IsKeyUp(Keys.D) && preKS.IsKeyUp(Keys.W))//Down , Left , Right , Up
                {
                    pers.Direction     = States.Stop;
                    pers.PersDirection = PersDirection.Standart;
                }

                if (crrKS.IsKeyDown(Keys.A) && crrKS.IsKeyDown(Keys.W))//left && Up
                {
                    pers.Direction     = States.LeftUp;
                    pers.PersDirection = PersDirection.Run;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.W) && Keyboard.GetState().IsKeyDown(Keys.D))//Up && right
                {
                    pers.Direction     = States.UpRight;
                    pers.PersDirection = PersDirection.Run;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.D) && Keyboard.GetState().IsKeyDown(Keys.S))//right && down
                {
                    pers.Direction     = States.RightDown;
                    pers.PersDirection = PersDirection.Run;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.S) && Keyboard.GetState().IsKeyDown(Keys.A))//down && left
                {
                    pers.Direction     = States.DownLeft;
                    pers.PersDirection = PersDirection.Run;
                }


                if (Keyboard.GetState().IsKeyDown(Keys.A) && !(Keyboard.GetState().IsKeyDown(Keys.W)) && !(Keyboard.GetState().IsKeyDown(Keys.S)))
                {
                    pers.Direction     = States.Left;
                    pers.PersDirection = PersDirection.Run;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.D) && !(Keyboard.GetState().IsKeyDown(Keys.S)) && !(Keyboard.GetState().IsKeyDown(Keys.W)))
                {
                    pers.Direction     = States.Right;
                    pers.PersDirection = PersDirection.Run;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.W) && !(Keyboard.GetState().IsKeyDown(Keys.A)) && !(Keyboard.GetState().IsKeyDown(Keys.D)))
                {
                    pers.Direction     = States.Up;
                    pers.PersDirection = PersDirection.Run;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.S) && !(Keyboard.GetState().IsKeyDown(Keys.A)) && !(Keyboard.GetState().IsKeyDown(Keys.D)))
                {
                    pers.Direction     = States.Down;
                    pers.PersDirection = PersDirection.Run;
                }


                //Анимация персонажа
                if (currentTime > period - 100)
                {
                    currentTime -= period - 100;
                    pers.Animation(9, 1, 1);
                }

                //Скорость передвижения персонажа
                pers.Move(3, CurrentMouse);

                if (Keyboard.GetState().IsKeyDown(Keys.F11))//Тех.Клавиша для фпс
                {
                    indicator1 = !indicator1;
                }

                base.Update(gameTime);
            }
            catch (Exception msg)
            {
                Log.Write(msg);                      //Запись в лог
                Console.WriteLine(msg.ToString());   //Вывод в консоль
                //throw;
            }
        }