2
\$\begingroup\$

I'm working on a boss fight for a 2D platformer/shooter game in the vein of the Megaman franchise. I expect part of the fight to include this boss causing large boulders to fall from certain points on the ceiling to possibly crush the player, which serve both as an attempt to harm the player and a possible means by which the player may harm the boss. I am having some difficulty, however, with conceptualizing how to tie these randomly-falling rocks to an action on the boss's part. I can make spawner objects to drop the boulders when prompted, my issue mainly lies in how to give the boss object the ability to trigger this action, especially given there will be several such spawners in the level, which may be selected at random.

Are there any functions or techniques that may be useful in allowing a single "boss" object to trigger one or more of a set of other "spawner" objects as a part of an action the "boss" takes, rather than simply automating the spawners to work on their own timing?

\$\endgroup\$
1
  • \$\begingroup\$ This sounds like you should make the spawn method public on your spawner. Then when the boss does something where you want him to spawn rocks, you iterate over your spawners and call the spawn method. \$\endgroup\$
    – Stephan
    Commented Dec 11, 2017 at 20:13

1 Answer 1

1
\$\begingroup\$

For ways to let him trigger actions on his own, try using gamestates.

Game states is an form of using enums that describes different kinds of movement or actions. by using a switch statement to seperate the gamestates and a timer to change the gamestates, you can give your boss patterns on his own.

To give an example of a timer-based gamestate:

In the Create Method:

int timer = 0; 
public enum GameState 
{ 
     MOVE,  
     THROWROCKS 
     STANDSTILL, 
};
GameState gameState = GameState.MOVE;

And in the Step method:

public void Update 
{    
    timer -= 1;
    switch (gameState) 
    { 
        case MOVE: 
        { 
            //moves 
            if (timer <= 0)
            { 
                timer = 10;
                gameState = GameState.THROWROCKS;
            }
            break; 
        } 
        case THROWROCKS: 
        { 
            //do another action 
            if (timer <= 0)
            { 
                timer = 10;
                gameState = GameState.THROWROCKS;
            }
            break; 
        } 
    } 
}

This is just a raw example to explain properly what I mean, try playing around and see if this can fit you.

(I remember this better from XNA experience than Gamemaker, but they almost work the same way, so be aware that a few parts might work differently in GML, it's mostly to show an example)

\$\endgroup\$
5
  • \$\begingroup\$ When were enum’s added? They don’t exist in my version? \$\endgroup\$
    – user64742
    Commented Dec 26, 2018 at 0:43
  • \$\begingroup\$ If you're using Game Maker Studio 2, then it should be: docs.yoyogames.com/source/dadiospice/002_reference/… But keep in mind that mine example was a raw sketch of XNA code. defining variables in GMS2 is slightly different. \$\endgroup\$
    – Steven
    Commented Jan 2, 2019 at 8:06
  • \$\begingroup\$ Still on Game Maker 8.0. I knew some changes occurred to the language but I wasn't aware they had progressed that far in new additions. That's quite interesting. \$\endgroup\$
    – user64742
    Commented Jan 4, 2019 at 1:15
  • 1
    \$\begingroup\$ Alternatively, gamestates can also work just as well by using an integer (int) instead. enums are technically just integers that allows easier readability. \$\endgroup\$
    – Steven
    Commented Jan 4, 2019 at 13:41
  • \$\begingroup\$ Yes, I'm aware of this. I just didn't realize the formal enum declaration had been added. It's been a while since such additions made it to the language.You don't want to see how many named global constants I have for that..... \$\endgroup\$
    – user64742
    Commented Jan 5, 2019 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .