/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; // The game pauses either if the user presses the pause button, or if // they unplug the active gamepad. This requires us to keep track of // whether a gamepad was ever plugged in, because we don't want to pause // on PC if they are playing with a keyboard and have no gamepad at all! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { if (input.IsTankFire(ControllingPlayer)) { if (isPlayer1Turn) { double missileAngle = ((player1.shotAngle /** (Math.PI / 180)*/)); Console.WriteLine("The missile angle is: "+missileAngle); Projectile missile; if (missileAngle < 0) { missile = new Projectile(ScreenManager.Game, new Vector2(player1.cannonLocation.X - (float)(Math.Cos(missileAngle) * player1.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player1.cannonTexture.Height) + player1.cannonLocation.Y - player1.texture.Height), new Vector2(-player1.force, player1.force)); } else { missile = new Projectile(ScreenManager.Game, new Vector2(player1.cannonLocation.X + (float)(Math.Cos(missileAngle) * player1.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player1.cannonTexture.Height) + player1.cannonLocation.Y - player1.texture.Height), new Vector2(player1.force, player1.force)); } player1.fireMissile(missile); ScreenManager.Game.Components.Add(missile); } else { double missileAngle = ((player2.shotAngle /** (Math.PI / 180)*/)); Console.WriteLine("The missile angle is: " + missileAngle); Projectile missile; if (missileAngle < 0) { missile = new Projectile(ScreenManager.Game, new Vector2(player2.cannonLocation.X - (float)(Math.Cos(missileAngle) * player2.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player2.cannonTexture.Height) + player2.cannonLocation.Y - player2.texture.Height), new Vector2(player2.force, player2.force)); } else { missile = new Projectile(ScreenManager.Game, new Vector2(player2.cannonLocation.X + (float)(Math.Cos(missileAngle) * player2.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player2.cannonTexture.Height) + player2.cannonLocation.Y - player2.texture.Height), new Vector2(-player2.force, player2.force)); } player2.fireMissile(missile); ScreenManager.Game.Components.Add(missile); } } if (input.IsTankMovingLeft(ControllingPlayer)) { if (isPlayer1Turn) { player1.moveTank("Left"); } else { player2.moveTank("Left"); } } if (input.IsTankMovingRight(ControllingPlayer)) { if (isPlayer1Turn) { player1.moveTank("Right"); } else { player2.moveTank("Right"); } } if (input.IsAimUp(ControllingPlayer)) { if (isPlayer1Turn) { player1.changeAim("Up"); } else { player2.changeAim("Up"); } } if (input.IsAimDown(ControllingPlayer)) { if (isPlayer1Turn) { player1.changeAim("Down"); } else { player2.changeAim("Down"); } } if (input.IsAimChanged(ControllingPlayer) != -1) { if (isPlayer1Turn) { player1.shotAngle = input.IsAimChanged(ControllingPlayer); } else { player2.shotAngle = input.IsAimChanged(ControllingPlayer); } } } }
public void fireMissile(Projectile newMissile) { if (tankState != TankState.Idle || tankState != TankState.Firing) { //You fired a projectile missile = newMissile; tankState = TankState.Firing; } }