I'm just prototyping a simple project. I'm moving a sprite on screen using the Xbox gamepad:
public override void Update(GameTime gameTime)
{
gamePad = GamePad.GetState(PlayerIndex.One);
GetPlayerRotation();
base.Velocity = new Vector2(vSpeed.X * gamePad.ThumbSticks.Left.X, -vSpeed.Y * gamePad.ThumbSticks.Left.Y);
base.Update(gameTime);
}
private void GetPlayerRotation()
{
leftThumb = gamePad.ThumbSticks.Left;
base.Rotation = -(float)Math.Atan2(leftThumb.Y, leftThumb.X);
}
This works fine to move the sprite in the correct direction (Dependent on the angle of the joystick).
However, the problem is, when I try to do a collision with a simple test object that is just a sprite, with a rectangle:
public virtual bool Collision(Entity entity1, Entity entity2)
{
if (entity1.Rectangle.Intersects(entity2.Rectangle))
{
Debug.WriteLine("Collision");
return true;
}
else
return false;
}
foreach (TestBlock block in blockList)
{
block.Update(gameTime);
if(player.Collision(player, block))
{
player.vSpeed = -player.vSpeed;
}
}
Whilst this does work, and the speed is inverted, when the bool returns to false after the collision, the control scheme becomes inverted (I.e, pressing the thumbstick up moves the sprite down).
I was trying to achieve a simple bounce effect off the block.