示例#1
0
        public override void Update(GameTime gameTime)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            truckAnimation.Position = this.Position;

            if (displayingPoints)
            {
                pointTimer -= deltaTime;
                if (pointTimer < 0f)
                {
                    activeGame.objectsToRemove.Add(this);
                }

                if (changingToWhite)
                {
                    pointColor = new Color(pointColor.ToVector3().X + 3 * deltaTime, 1f, pointColor.ToVector3().Z + 3 * deltaTime);
                    if (pointColor.ToVector3().X >= 1f)
                    {
                        changingToWhite = false;
                    }
                }
                else
                {
                    pointColor = new Color(pointColor.ToVector3().X - 3 * deltaTime, 1f, pointColor.ToVector3().Z - 3 * deltaTime);
                    if (pointColor.ToVector3().X <= 0f)
                    {
                        changingToWhite = true;
                    }
                }
            }

            if (!isDestroyed)
            {
                if (isTaunted)
                {
                    truckAnimation.color = Color.Red;
                }


                if (!isInvincible)
                {
                    // Ram into the wall here
                    if (this.X /* - truckAnimation.FrameWidth / 2*/ < 0 || this.X > activeGame.GraphicsDevice.Viewport.Width || this.Y /*- truckAnimation.FrameWidth / 2*/ < 0 || this.Y > activeGame.GraphicsDevice.Viewport.Height)
                    {
                        Destroy();
                    }
                }


                Vector2 normalized = Vector2.Normalize(targetPosition - startPosition);
                if (!isTaunted)
                {
                    normalized *= (truckMoveSpeed + Truck.CrashedTrucks * crashedTruckSpeedIncrease);
                    this.X     += normalized.X * deltaTime;
                    this.Y     += normalized.Y * deltaTime;
                }
                else
                {
                    normalized *= (truckTauntedMoveSpeed + Truck.CrashedTrucks * crashedTruckSpeedIncrease);
                    this.X     += normalized.X * deltaTime;
                    this.Y     += normalized.Y * deltaTime;
                }

                if (this.X > 0 + truckAnimation.FrameWidth / 2 && this.X < activeGame.GraphicsDevice.Viewport.Width && this.Y > 0 + truckAnimation.FrameWidth / 2 && this.Y < activeGame.GraphicsDevice.Viewport.Height - 0)
                {
                    // Truck is in bounds
                    isInvincible = false;
                }
            }
            else
            {
                if (truckAnimation == crashAnimation)
                {
                    truckAnimation.color = new Color(truckAnimation.color.ToVector3().X - 0.5f * deltaTime, truckAnimation.color.ToVector3().Y - 0.5f * deltaTime, truckAnimation.color.ToVector3().Z - 0.5f * deltaTime);
                }
            }

            truckAnimation.Update(gameTime);

            // Change the truck animation from the crashing to destroyed
            if (truckAnimation == crashAnimation && !truckAnimation.Active)
            {
                if (!truckAnimation.Active)
                {
                    // Debug.WriteLine("Not active anymore!");
                    deadAnimation.depth    = truckAnimation.depth;
                    deadAnimation.Position = this.Position;
                    deadAnimation.angle    = this.Rotation;
                    deadAnimation.color    = truckAnimation.color;
                    truckAnimation         = deadAnimation;
                    truckAnimation.Update(gameTime);
                }
            }
        }
示例#2
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);
        }