O'Reilly logo

XNA 4.0 Game Development by Example Beginner's Guide by Kurt Jaegers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - updating and drawing the player's ship

  1. Add the imposeMovementLimits() helper method to the PlayerManager class:
    private void imposeMovementLimits()
    {
    Vector2 location = playerSprite.Location;
    if (location.X < playerAreaLimit.X)
    location.X = playerAreaLimit.X;
    if (location.X >
    (playerAreaLimit.Right - playerSprite.Source.Width))
    location.X =
    (playerAreaLimit.Right - playerSprite.Source.Width);
    if (location.Y < playerAreaLimit.Y)
    location.Y = playerAreaLimit.Y;
    if (location.Y >
    (playerAreaLimit.Bottom - playerSprite.Source.Height))
    location.Y =
    (playerAreaLimit.Bottom - playerSprite.Source.Height);
    playerSprite.Location = location;
    }
    
  2. Add the Update() method to the PlayerManager class:
    public void Update(GameTime gameTime) { PlayerShotManager.Update(gameTime); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required