Ok, I have this ship object which the user controls using the arrow keys.
if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
mAngle -= 0.1f;
else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
mAngle += 0.1f;
if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true)
{
// mSpeed.Y = SHIP_SPEED;
// mDirection.Y = MOVE_UP;
velocity.X = (float)Math.Cos(mAngle) * SHIP_SPEED;
velocity.Y = (float)Math.Sin(mAngle) * SHIP_SPEED;
}
else if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
{
mSpeed.Y = SHIP_SPEED;
mDirection.Y = MOVE_DOWN;
}
The following 2 methods are in another class.
//Update the Sprite and change it's position based on the passed in speed, direction and elapsed time.
public void Update(GameTime theGameTime, Vector2 velocity, float theAngle)
{
Position += velocity * (float)theGameTime.ElapsedGameTime.TotalSeconds;
shipRotation = theAngle;
}
//Draw the sprite to the screen
public void Draw(SpriteBatch theSpriteBatch)
{
Vector2 Origin = new Vector2(mSpriteTexture.Width / 2, mSpriteTexture.Height / 2);
theSpriteBatch.Draw(mSpriteTexture, Position, new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height),
Color.White, shipRotation, Origin, Scale, SpriteEffects.None, 0);
}
The problem is that: the program thinks the front of the ship is one of the side wings, so in a way it's going sideways when I press up. I don't know why this is.
Suggestions?