I am using the functions Health and FireBullet to shoot and kill enemies in the game.
By defining properties for enemy health being damaged, enemies get killed etc.
How would you approach the effect that the player gets a “Mass Kill” message, so when killing lets say 10 enemies in a time frame of 3 seconds, this message appears.
I was thinking of continuously storing the total amount of killed enemies in a variable, and then start checking with a timer, but maybe you guys know the most efficient way to achieve this.
Thanks in advance
There is an example showing you that kind of effect.
That’s for the Mass Kill message. To get if Player has killed the Enemy or not, do something like this:
If Enemy is killed Then
Change the Scene Variable DeadEnemyCount + 1
If time elapsed in Lol timer is greater than 3 seconds
In child event
Variable DeadEnemyCount < 10 Then
Change the Scene Variable DeadEnemyCount = 0
In another child event
Variable DeadEnemyCount >= 10 Then
Display Flying Mass Kill sprite
I’d look at using an array. Store the time (rounded to seconds) as the value. The times will be stored in order, because they get pushed onto the array, and so you’ll have a chronological list of kills.
Remove all those elements that have a value (effectively a timestamp) older than 3 seconds (value < time now - 3). The array child count will tell you how many enemies you’ve knocked off in the last 3 seconds.
And it’s a rolling 3 seconds, so it’s never ending
This looks very interesting, as I am not such an expert with arrays, is there any chance you could get me in the right direction by writing down the conditions and associated actions? Would be a great help.
Also thanks for your reply as well, Mixen
I have played a bit with arrays but couldn’t get it working 100%. Its a bit too complex for me for now.
So the solution with repeating timers is what’s currently working fine.
But that’s more coding and work. And it’s not what you’re after.
Here’s how you would implement the array version:
Makkelijk, niet moeilijk
Thanks man, yesterday I figured out something similar as what you wrote here (although I used the Array tools extension) but for some reason it doesnt work properly. Also, trying with your code the MassKill shows only the first time when killing enemies.
There must be something that I did wrong somewhere… but with the below code the same goal is achieved, so I’m fine with it.
Nevertheless, wel tof dat je even geholpen hebt…
I’d say you will have erred somewhere, because it works fine when I run it. Remember the order of the repeat condition is important.
That’s 3 kills within 1/2 a second? But good if it suits your needs. It’ll also give GDevelopers another option if they want to implement something similar.