player.Update(gameTime);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 only has control if he's still alive
if (player.Active == true)
{
// All our stuff
player.Position.X -= 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.
player.Position.Y += playerMoveSpeed;
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:
- 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?
- We'll create this:
if (player.Active == false)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.
{
player.Position.X -= playerMoveSpeed;
player.Position.Y += playerMoveSpeed;
}
No comments:
Post a Comment