• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker how to count shots or enemy destruction[solved]

D

diester

Guest
Hello, I'm looking for a tutorial that would allow to count the number of enemy detruis to fill a gauge.
this gauge would allow me to activate a new function once full (like having the possibility to have a special shot or activate a shield)
I try to coded from the tutorial healtbar (since I have not found any tutorial on this way to do).

but I can not do anything. who can help me or give me the link of a tutorial please thank you
 

CloseRange

Member
create an obj_enemy_counter
Code:
/// create event
enemy_needed = 10; // how many enemys need to be killed
killed = 0; // how many have been killed (leave at 0 here)
width = 200; // width of the bar to draw
height = 16; // height of the bar to draw
dp = 0;// delta percent : will be 1 when all you have enough kills
Code:
/// draw event
dp = (killed / enemy_needed);
var dw = dp * width; // the width of the bar to draw
var dh= height;
// draw a rectangle
draw_set_color(c_black);
draw_rectangle(x, y, x+width; y+height);
// draw main bar
draw_set_color(c_red); // color of bar
draw_rectangle(x, y, x+dx, y+dy);
now when you kill an enemy
Code:
/// enemy is ready to die
obj_enemy_counter.killed++;
and when you need to see if you have enough kills
Code:
if(obj_enemy_counter.dp == 1) {
     obj_enemy_counter.killd = 0; // make sure to reset it to show it was consumed
     // .... do your special attack ......
}
 
D

diester

Guest
so simple while I go around in circles for days ...... thank you very much I will test this, it shows me that I still have much to learn
 
D

diester

Guest
I just have a little problem if I kill more enemy than the number defined
Code:
enemy_needed = 20; // how many enemys need to be killed
it does not work anymore. How can you make sure that once the set number has been reached, the bar will remain locked until the special shot is used?
 
Last edited by a moderator:

CloseRange

Member
at the top of the draw event for obj_enemy_counter write:
Code:
killed = clamp(killed, 0, enemy_needed):
clamp makes it so the value cant go below 0 and cant go above the max
 
D

diester

Guest
thank you very much it works perfectly you manage. thanks thanks thanks ;)
 
Top