GMS 2 Segmented enemy

1up Indie

Member
GM Version: GMS2
Target Platform: All

Summary:
This video tutorial shows you how to make 2 types of segmented enemy in gamemaker studio 2.
What are these types? Well, they are like those iconic enemies that you see in a good old mario game. One where the segments are flying after each other and one where the segments are "on rails".

The idea is that it is only one simple object "cloning" itself. No real magic here.


Tutorial bombhead snake thing:

Create:
Code:
tail_parts = 4;
follow = false;
takeThis_Id = id;
followThisOne = id;



// create follwing ball
checkOnce = false;
Step:
Code:
// head ->
if (follow == false) {
x = lerp(x, mouse_x, 0.02);
y = lerp(y, mouse_y, 0.02);

}


//
if (follow == true) {
x = lerp(x, followThisOne.x, 001);
y = lerp(y, followThisOne.y, 0.1);
}


// flip image
if (x > xprevious) {   image_xscale = -1;  }
if (x < xprevious) {   image_xscale =  1;  }



if (tail_parts > 0 and checkOnce == false) { tail_parts -= 1; checkOnce = true;
 
if (tail_parts == 0) {
 
    with instance_create_layer(x,y, "Instances", obj_BossSnake) {
    tail_parts = other.tail_parts;
    follow = true;
    followThisOne = other.takeThis_Id;
    sprite_index = spr_Boss_End;

}} else
 
 
with instance_create_layer(x,y, "Instances", obj_BossSnake) {
    tail_parts = other.tail_parts;
    follow = true;
    followThisOne = other.takeThis_Id;
    sprite_index = spr_Boss_Part;
}


}


Tutorial cactus dude:

Create:
Code:
tail_parts = 4;
follow = false;
takeThis_Id = id;
followThisOne = id;



// create follwing ball
checkOnce = false;



// ease move
start = -1.5;
dest =   1.5;
duration = 120;
time = 0;

move = 0;  // ease function -1.5 to 1.5


// wiggle movement
start_X = x;
realmovement = 0;

startEasing = false;


// delay for each following part
startChecking = false;
alarm[0] = 30;  // delay to check

Step:
Code:
// head ->

// Ease function
if (startEasing == true) {
    if ( time < duration) {
 
    move = ease_in_and_out(time, start, dest - start, duration);
 
    time++;
    }
else {
 
    var tempStart = start;
    start = dest;
    dest = tempStart;
    time = 0;    }}
 
 
 


if (follow == false) {
x = start_X + move + realmovement;

// actual movement
realmovement += 0.05;    }


if (follow == true ) {
x = followThisOne.x + move;
}


// flip image
if (x > xprevious) {   image_xscale = -1;  }
if (x < xprevious) {   image_xscale =  1;  }





if (tail_parts > 0 and checkOnce == false and startChecking == true) {
 
    tail_parts -= 1;  checkOnce = true;
 
    with instance_create_layer(start_X, y + 14, "Instances", obj_BossCactus) {
    tail_parts = other.tail_parts;
    follow = true;
    followThisOne = other.takeThis_Id;
    sprite_index = spr_Cactus_Body;
                                                                            }
}

Alarm[1]:
Code:
/// @description start checking
startChecking = true;

startEasing = true;
 
Last edited by a moderator:
look nice the 2 tutorials . I have some suggestions :
--> add indentation in blocks that have folow true/false .
--> add script ease_in_and_out() code .
--> expand the code of Black Snake, in the case that you don't want have empty bettween his pieces or just set a "max distance" with the part that is following.
 

1up Indie

Member
Hello, this is only an "basics" tutorial to show you how i setup. So I have bad news and good news.

The bad news first: It is a standalone tutorial and ends here, I have no intention to further the scope.
The half good news: I am in the process of making for my patreons a complex segmented enemy boss type that consists of many diffrent parts (blinking weakpoints, fires a rocket, laserbeam, spinning spikeball, charge attack, ... ) that amounts to a whopping total of 18 unique parts to mix and match. So if you are further interested in that stuff head over to my patreon. https://www.patreon.com/1upindie
 
Top