In chapter 6 of my C# book we learn how to program an If check for a mouse click.
It says that to do this we need:
1. The player did not press the mouse button during the last Update method;
2. In the current Update method, the player presses the mouse button.
But this says nothing about releasing the mouse button ?? I ran the program and it only takes into account pressing, not releasing...
Whats going on?
protected override void Update(GameTime gameTime)
{
previousMouseState = currentMouseState;
currentMouseState = Mouse.GetState();
if (currentMouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released)
calculateAngle = !calculateAngle;
if (calculateAngle)
{
double opposite = currentMouseState.Y - barrelPosition.Y;
double adjacent = currentMouseState.X - barrelPosition.X;
angle = (float)Math.Atan2(opposite, adjacent);
}
else
angle = 0.0f;
}