So in my game, the player controls a square around the screen, and if you collide with other moving squares you die. The feature I am currently working on is collectibles (which are circles randomly placed around the screen). A certain number of them are drawn to the screen and then they disappear if you collide with them. However, what I am struggling with is how to make it so, say they are 5 collectibles, you collect 3 and then die. In this scenario I want the amount of collectibles to be reset to 5 and amount collected to 0. At the moment if you collect some and die, when you respawn the ones you have collected stay collected, what logic is need to fix this so if you collect some, die and then respawn the ones you collected before your death reappear.
Crossbones+ - Reputation: 5638
Posted 13 January 2013 - 08:20 AM
What you could do is keep a list of all collectibles that have ever spawned, and mark them either collected by the player or not. Add to the end of the list whenever a new collectible spawns. Then, when the player dies, assume he has N collectibles collected, go to the end of the list, and walk backwards through the list, marking the last N "collected by player" collectibles as "not collected" (ignore those which were not collected by the player). This will have the literal effect of reversing the player's collection of his past N collectibles, putting them back on the map as if they had never been collected. Make sure your game keeps reading the list to know which collectibles to draw or not. This also allows you to check previously collected collectibles for collision to prevent spawning new collectibles on top of collectibles collected by the player which might respawn if the player dies (o.O)
There are more sophisticated methods but this should do fine for a start, and the logic is easy to understand.
Edited by Bacterius, 13 January 2013 - 08:23 AM.
"The best comment is a deleted comment."