Google+

Monday, October 10, 2011

Let's Make A Game Episode 23: Falling Away

So here's what we've decided to do. First, we're going to take control of the player away after they've died. That's easy enough to do:

player.Update(gameTime);

// Player only has control if he's still alive

if (player.Active == true)
{
// All our stuff
Next, though, is the tricky section. What happens to a ship if it gets hit in mid-air? It slows down and falls to the ground, correct? Ergo, we should decelerate the ship and drop it by lowering its X and Y values like so:
player.Position.X -= playerMoveSpeed;
player.Position.Y += playerMoveSpeed;
It's not working quite right, though.  I've placed it a place that doesn't checked often, the UpdateCollision area. It actually only updates this once, which means that after the ship gets hit, it twitches on in that direction instead of continually falling.

It's better to put this in the UpdatePlayer area, where this will run along with the rest of the loop. We'll do two things in this area:
  1. We'll only have MathHelper.Clamp run when the player is active, first of all. Otherwise, it looks silly to have the ship hit the bottom of the viewable area and then stop moving, right?
  2. We'll create this:
    if (player.Active == false)
            {
                player.Position.X -= playerMoveSpeed;
                player.Position.Y += playerMoveSpeed;
            }
So now we're actually making the ship fall off the screen when it blows up. We still have to work out some kind of counter to start the game over, though, or else the ship will continually falling in perpetuity.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.