Ammo

Ammo

Ammo is kept track of using a variable. First, you need to create a variable for the ammo. You should probably do this in the Create event of the object that has the ammo by giving the ammo variable a value equal to what you want the starting ammo to be. For example, if you wanted the player to start with 50 ammo :

ammo = 50;

Before Shooting

Before shooting, make sure to check that the player has ammo to shoot by checking that the ammo variable is not :

if ( ammo > 0 )
{
    //then player can shoot
}

Subtracting Ammo

When the player shoots, you can subtract 1 from the ammo variable to reflect the spent shot :

ammo -= 1;

Be sure to check that the player

Refilling / Picking up More Ammo

When the player gets more ammo, either by refilling his ammo at the end of a level or by picking up an icon that gives him more ammo instantly, you can add to the player's ammo by simply adding to the ammo variable. For example, if the player gains 5 more shells :

ammo += 5;