I seem to be having this problem a lot, I'm still learning XNA / C# and well, trying to make a classic paddle and ball game. The problem I run into (and after debugging have no answer) is that everytime I run my game and press either of the movement keys, the Paddle won't move. Debugging shows that it never gets to the movement part, but I can't understand why not?
Here's my code:
// This is the If statement for checking Left movement.
if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A))
{
if (!CheckCollision(walls[0]))
{
Location.X -= Velocity;
}
}
//This is the CheckCollision(Wall wall) boolean
public bool CheckCollision(Wall wall)
{
if (this.BoundingBox.Intersects(wall.BoundingBox))
{
return true;
}
return false;
}
As far as I can tell there should be absolutely no problem with this, I initialize the bounding box in the constructor whenever a new instance of Walls and Paddle is created.
this.BoundingBox = new Rectangle(0, 0, Sprite.Width, Sprite.Height);
Any idea as to why this isn't working?
I have previously succeeded with using the whole Location.X < Wall.Location.X + Wall.Texture.Width code... But to me that seems like too much coding if a simple boolean check could be done.