Пример #1
0
        public override void Update(GameTime gameTime)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (dodgeTimer > 0f)
            {
                dodgeTimer -= deltaTime;
            }
            if (dodgeCooldownTimer > 0f && !isDodgeRolling)
            {
                dodgeCooldownTimer -= deltaTime;
            }
            if (tauntTimer > 0f)
            {
                tauntTimer -= deltaTime;
            }
            if (dodgeTimer < 0f)
            {
                isDodgeRolling  = false;
                playerAnimation = walkAnimation;
            }


            // this.X += activeGame.currentGamePadState.ThumbSticks.Left.X * playerMoveSpeed * deltaTime;
            // this.Y -= activeGame.currentGamePadState.ThumbSticks.Left.Y * playerMoveSpeed * deltaTime;


            playerAnimation.Position = this.Position;

            bool left = false, right = false;
            bool anyDirection = false;

            if (activeGame.currentKeyboardState.IsKeyDown(Keys.Left) || activeGame.currentGamePadState.DPad.Left == ButtonState.Pressed)
            {
                if (!isDodgeRolling)
                {
                    this.X -= playerMoveSpeed * deltaTime;
                }
                else
                {
                    this.X -= dodgeSpeed * deltaTime;
                }
                Rotation     = (float)Math.PI;
                left         = true;
                anyDirection = true;
            }

            if (activeGame.currentKeyboardState.IsKeyDown(Keys.Right) || activeGame.currentGamePadState.DPad.Right == ButtonState.Pressed)
            {
                if (!isDodgeRolling)
                {
                    this.X += playerMoveSpeed * deltaTime;
                }
                else
                {
                    this.X += dodgeSpeed * deltaTime;
                }
                Rotation     = 0f;
                right        = true;
                anyDirection = true;
            }

            if (activeGame.currentKeyboardState.IsKeyDown(Keys.Up) || activeGame.currentGamePadState.DPad.Up == ButtonState.Pressed)
            {
                if (!isDodgeRolling)
                {
                    this.Y -= playerMoveSpeed * deltaTime;
                }
                else
                {
                    this.Y -= dodgeSpeed * deltaTime;
                }
                Rotation = (float)Math.PI * 3 / 2;
                if (left)
                {
                    Rotation = (float)Math.PI * 5 / 4;
                }
                else if (right)
                {
                    Rotation = (float)Math.PI * 7 / 4;
                }
                anyDirection = true;
            }

            if (activeGame.currentKeyboardState.IsKeyDown(Keys.Down) || activeGame.currentGamePadState.DPad.Down == ButtonState.Pressed)
            {
                if (!isDodgeRolling)
                {
                    this.Y += playerMoveSpeed * deltaTime;
                }
                else
                {
                    this.Y += dodgeSpeed * deltaTime;
                }
                Rotation = (float)Math.PI / 2;
                if (left)
                {
                    Rotation = (float)Math.PI * 3 / 4;
                }
                else if (right)
                {
                    Rotation = (float)Math.PI * 1 / 4;
                }
                anyDirection = true;
            }

            // Dodge Roll
            if (((activeGame.currentKeyboardState.IsKeyDown(Keys.Z) && activeGame.previousKeyboardState.IsKeyUp(Keys.Z)) || (activeGame.currentKeyboardState.IsKeyDown(Keys.Space) && activeGame.previousKeyboardState.IsKeyUp(Keys.Space))) && dodgeCooldownTimer <= 0 && anyDirection)
            {
                dash.Play();
                Debug.WriteLine("Dodge");
                isDodgeRolling     = true;
                dodgeTimer         = dodgeLength;
                dodgeCooldownTimer = dodgeCooldownLength;
                playerAnimation    = dashAnimation;
            }

            // Taunt
            if (((activeGame.currentKeyboardState.IsKeyDown(Keys.X) && activeGame.previousKeyboardState.IsKeyUp(Keys.X)) || (activeGame.currentKeyboardState.IsKeyDown(Keys.LeftShift) && activeGame.previousKeyboardState.IsKeyUp(Keys.LeftShift))) && tauntTimer <= 0)
            {
                tauntfx.Play();
                Shockwave taunt = new Shockwave(this.Position, activeGame);
                activeGame.objectsToAdd.Add(taunt);
                tauntTimer = tauntCooldownLength;
                int points = 100;
                foreach (GameObject go in activeGame.FindGameObjectsByTag("Truck"))
                {
                    Truck truck = go as Truck;
                    if (truck.isDestroyed)
                    {
                        if (Math.Pow(truck.X - this.X, 2) + Math.Pow(truck.Y - this.Y, 2) < Math.Pow(tauntRadius, 2))
                        {
                            // activeGame.objectsToRemove.Add(go);

                            truck.displayingPoints = true;
                            truck.pointValue       = points;
                            if (points < 25600)
                            {
                                points *= 2;
                            }
                            activeGame.timer.points += points;
                            Truck.CrashedTrucks--;
                        }
                    }
                    else
                    {
                        truck.Taunt();
                    }
                }
            }

            this.X = MathHelper.Clamp(this.X, playerAnimation.FrameWidth, activeGame.GraphicsDevice.Viewport.Width);
            this.Y = MathHelper.Clamp(this.Y, playerAnimation.FrameHeight, activeGame.GraphicsDevice.Viewport.Height);

            playerAnimation.Update(gameTime);
        }