示例#1
0
        private void UpdatePlayer(Player player, GameTime gameTime)
        {
            player.Update(gameTime);

            // Use the Keyboard / Dpad
            if (currentKeyboardState.IsKeyDown(Keys.Left))
            {
                player.Position.X -= playerMoveSpeed;
                player.PlayerAnimation.Active = true;
            }
            else if (currentKeyboardState.IsKeyDown(Keys.Right))
            {
                player.Position.X += playerMoveSpeed;
                player.PlayerAnimation.Active = true;
            }
            else
                player.PlayerAnimation.Active = false;

            if (currentKeyboardState.IsKeyDown(Keys.Up))
            {
                player.CannonAngle += 0.01f;

                //if (player.CannonAngle > MathHelper.ToRadians(359))
                //{
                //    player.CannonAngle = MathHelper.ToRadians(359);
                //}

            }
            else if (currentKeyboardState.IsKeyDown(Keys.Down))
            {
                player.CannonAngle -= 0.01f;

                //if (player.CannonAngle < MathHelper.ToRadians(270))
                //{
                //    player.CannonAngle = MathHelper.ToRadians(270);
                //}

            }

            if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                // Fire only every interval we set as the fireTime
                if (gameTime.TotalGameTime - previousFireTime > fireTime)
                {
                    // Reset our current time
                    previousFireTime = gameTime.TotalGameTime;

                    // Add the projectile, but add it to the front and center of the player
                    //AddProjectile(player.Position +player.CannonTip);
                    AddProjectile( player.CannonTip);
                }
            }

            // Make sure that the player does not go out of bounds
            player.Position.X = MathHelper.Clamp(player.Position.X, 0, ScreenWidth - player.Width);
            //player.Position.Y = MathHelper.Clamp(player.Position.Y, 0, ScreenHeight - player.Height);

            player.CannonAngle = MathHelper.Clamp(player.CannonAngle, MathHelper.ToRadians(270), MathHelper.ToRadians(359));
        }
示例#2
0
        private void UpdatePlayer(Player player, GameTime gameTime)
        {
            if (player == player1)
            {

                player.Update(gameTime);

                // Use the Keyboard / Dpad
                if (currentKeyboardState.IsKeyDown(Keys.Left) || (GamePad1.ThumbSticks.Left.X < 0))
                {
                    player.Position.X -= playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Right) || (GamePad1.ThumbSticks.Left.X > 0))
                {
                    player.Position.X += playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else
                    player.PlayerAnimation.Active = false;

                if (currentKeyboardState.IsKeyDown(Keys.Up) || (GamePad1.ThumbSticks.Right.Y > 0))
                {
                    player.CannonAngle += 0.01f;

                }
                else if (currentKeyboardState.IsKeyDown(Keys.Down) || (GamePad1.ThumbSticks.Right.Y < 0))
                {
                    player.CannonAngle -= 0.01f;
                }

                if (currentKeyboardState.IsKeyDown(Keys.Space) || (GamePad1.Triggers.Right > 0))
                {
                    // Fire only every interval we set as the fireTime
                    if (gameTime.TotalGameTime - previousFireTime > fireTime)
                    {
                        // Reset our current time
                        previousFireTime = gameTime.TotalGameTime;

                        // Add the projectile, but add it to the front and center of the player
                        //AddProjectile(player.Position +player.CannonTip);
                        AddProjectile(player.CannonTip, player.CannonAngle, player);
                    }
                }

                // Make sure that the player does not go out of bounds
                player.Position.X = MathHelper.Clamp(player.Position.X, wallPosition.X + (wall.Width / 2), ScreenWidth - player.Width);

                player.CannonAngle = MathHelper.Clamp(player.CannonAngle, MathHelper.ToRadians(270), MathHelper.ToRadians(359));
            }

            else
            {
                player.Update(gameTime);

                // Use the Keyboard / Dpad
                // Use the Keyboard / Dpad
                if (currentKeyboardState.IsKeyDown(Keys.A) || (GamePad2.ThumbSticks.Left.X < 0))
                {
                    player.Position.X -= playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else if (currentKeyboardState.IsKeyDown(Keys.D) || (GamePad2.ThumbSticks.Left.X > 0))
                {
                    player.Position.X += playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else
                    player.PlayerAnimation.Active = false;

                if (currentKeyboardState.IsKeyDown(Keys.W) || (GamePad2.ThumbSticks.Right.Y < 0))
                {
                    player.CannonAngle += 0.01f;

                }
                else if (currentKeyboardState.IsKeyDown(Keys.S) || (GamePad2.ThumbSticks.Right.Y > 0))
                {
                    player.CannonAngle -= 0.01f;
                }

                if (currentKeyboardState.IsKeyDown(Keys.Q) || (GamePad2.Triggers.Right > 0))
                {
                    // Fire only every interval we set as the fireTime
                    if (gameTime.TotalGameTime - previousFireTime2 > fireTime2)
                    {
                        // Reset our current time
                        previousFireTime2 = gameTime.TotalGameTime;

                        // Add the projectile, but add it to the front and center of the player
                        //AddProjectile(player.Position +player.CannonTip);
                        AddProjectile(player.CannonTip, player.CannonAngle, player);
                    }
                }

                // Make sure that the player does not go out of bounds
                player.Position.X = MathHelper.Clamp(player.Position.X, 0, wallPosition.X + (wall.Width / 2) - player.Width);
                player.CannonAngle = MathHelper.Clamp(player.CannonAngle, MathHelper.ToRadians(0), MathHelper.ToRadians(90));
            }
        }