I’m working on a game with a mechanic similar to Plants vs Zombies. Imagine a tower defense type game with enemies advancing on defenses in columns. The problem I’m trying to solve is how to work with enemies damaging defenses.
When an enemy comes into contact with a defense I want the enemy to start applying damage to that defense. It’s possible for more than one enemy in the same column to begin damaging the same defense.
At this point I have things set up where I can apply some damage every frame. What I’d rather do is apply damage at a timed interval. Seems that I need a timer. Here are the problems I see.
- Adding a timer means that the timer needs to be removed when defense is destroyed or when the enemy that created the timer is destroyed.
- If two enemies are attacking the same defense they will both have created timers. If the enemy is destroyed by applying damage from one of these timers, then the others need to be removed.
Besides timers I keep thinking that some sort of event listener might work as a solution