Player Ammo in the Platform Games tvOS and iOS Starter Kit
In the image above notice there are 4 ammo drops, two named Player1Ammo and two named Player2Ammo. The properties for these are set on a per-level basis with identical named dictionaries: Player1Ammo and Player2Ammo. See the image below for reference.
- AwardsHowMuch – a number value for how much ammo the player will get when they collide with the ammo.
- SpawnsHowOften – a number value for how often the ammo will respawn.
- SpawnsAtRandomTime – a YES or NO value for whether or not the ammo randomly respawn within the time frame specified above. So for example, if SpawnsHowOften is 30, then at most, the random time would be is 30 seconds.
- MinimumTimeBetweenSpawns – If you randomly spawn ammo, you can set the minimum time between respawns. So if the random time generated is lower than this value, this value is used instead.
- AwardsToBothPlayers – a YES or NO value setting whether or not the ammo can be awarded to both players. If set to NO, then obviously Player1Ammo can only be picked up by Player1 and vice versa.
- OnlyAllowOneAtATime – a YES or NO value setting whether more than one Player1Ammo or Player2Ammo can exist at a time. Notice in the example image above, the scene has 4 ammo drops, but in the property list OnlyAllowOneAtATime is set to YES on both of them. So at most the scene would only ever drop one set of ammo for each player. Which ammo is dropped next (after one is collected) is determined by the time settings specified. So whichever ammo’s “clock” comes first, is the one to drop.
- SoundAmmoCollect – the sound to play when ammo is collected. This should be the full file name including extension, for example collect.caf or collect.mp3. This value is optional, and can harmlessly be left blank.
- SoundAmmoDrop – the sound to play when ammo is dropped. This should be the full file name including extension, for example collect.caf or collect.mp3. This value is optional, and can harmlessly be left blank.
Note: If you do not want to set these properties on every level (or exclude them and use default values), you can easily set your own defaults in the Ammo class. Find the Ammo.swift file, and edit any of the properties below…