• 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!

SOLVED Creating a group of active enemies that function as one unit

McJazzhands

Member
Heya folks! I'm back with a question relating to Gradius once again. This time around, I'm trying to recreate the bean enemies you see when you start the game, shown below:

beangroup.png

What I'm aiming for is a group of identical enemies (A) that drop a powerup capsule for the player when the whole group is destroyed. If even one of them makes it offscreen (B), the player doesn't get a capsule from that group. How would I go about doing this in GameMaker? Right now I have it tied to a global variable that increments when one of the enemies is destroyed and resets to zero when one of them gets away, but it doesn't work as cleanly as I want it to. Like if one gets offscreen and the player destroys some of the beans behind that one, the relevant variable won't reset to zero and ends up dropping a powerup in the middle of a subsequent group.

Here's what I've got written out thus far:

GML:
global.beancount += 1;
//show_debug_message(global.beancount);

if (global.beancount % 5 = 0)
{
    isRed = true;
}

if (isRed = true)
{
    if (global.capsule_count < 14)
    {
        instance_create_layer(x, y, "Instances", o_powerup);
        global.capsule_count += 1;
        isRed = false;
        global.beancount = 0;
    }
    else
    {
        instance_create_layer(x, y, "Instances", o_crash);
        global.capsule_count = 0;
        isRed = false;
        global.beancount = 0;
    }
}
GML:
    instance_destroy();
    global.beancount = 0;

I'm at a loss for how to get this working like in a manner reminiscent of the source material, truth be told. If it helps, I'm using IDE v2.3.3.574 and Runtime v2.3.3.437.
 
I don’t know if I am misunderstanding this, but In the outside view 0 event, you set global.beaconcount to 0, but in the destroy event, you say global.beaconcount += 1, so even if it is off the screen, when the player shoots it, it will still add one
 

McJazzhands

Member
I don’t know if I am misunderstanding this, but In the outside view 0 event, you set global.beaconcount to 0, but in the destroy event, you say global.beaconcount += 1, so even if it is off the screen, when the player shoots it, it will still add one
Ah, you're right! My bad, I forgot to mention that I have a retreat variable in place to check if any of them are getting away. Here's the full block.

GML:
if (retreat = 2)
{
    instance_destroy();
    global.beancount = 0;
}
else
{

}
 
Have you tried just making these capsules one instance, and just drawing the capsule sprite multiple times? That way if it goes offscreen you don’t need to set that to be true for every capsule
 

woods

Member
maybe have your bean enemies in different labeled groups?
if (all 5 enemies in group A are destroyed) {create your power-up}

it doesnt matter how many beans you kill, so long as you get all of the ones in THIS/THAT group ;o)
 

TheouAegis

Member
I would just set a global variable to how many beans are in a group right when I spawn the first bean. When a bean is destroyed by the player, decrease that variable and check if it is 0.

If you want multiple waves on screen at a time, use a global array instead, have a global variable keep track of where in the array you should set the count, save that value inside each enemy as it is spawned so it knows which part of the array to decrease when dead.
 

McJazzhands

Member
I got it working! Thank you all for your suggestions, it really helped me realize just how many different approaches there are for something like this. In the end, I went with woods' suggestion to set up the enemies in differently labeled groups so now it runs a count and sets them to drop a capsule if the last enemy in the group is destroyed:

GML:
if (instance_number(o_skull_B) == 1)
{
    isRed = true; //drops a capsule when destroyed
}
It was that simple all along. Amazing, isn't it? Seriously though, I can't thank you all enough for helping me think a little differently. I'll keep all of these ideas in mind for the future!
 
Top