Now that Mega Woman can jump, run, shoot and die, we’ll continue adding to her arsenal of moves by giving her the ability to slide!
Here’s the steps we’ll go through to do that:
- Modify the level to have a low ceiling to slide under
- Create a sprite with a different collision setting to be applied as a mask
- Add controls in the NORMAL state to enter a SLIDE state
- Add the new SLIDE state
Modify the level
Open the room “rm_level_template”. Add some blue wall blocks to create a small gap we want our hero to be able to slide under.
Something like this:

Create the sprite with the low stance collision mask
Here’s one way to do it:
- Right-click on “spritesheet_megawoman” and select “Duplicate” (or select the sprite and press Ctrl+D
- Rename the new sprite to “spr_megawoman_slide“
- Open the new sprite
- Find the sliding frame (frame 7). Delete all other frames.
- Open the Collision Mask section of the sprite and change the Top value to 14
The new sprite should look like that:

Note: You don’t really need the sliding frame. The mask could be an empty 32px by 32px sprite with the Collision Mask value defined above but I find it useful to have the sliding sprite to set up the mask.
Add the controls in the NORMAL state
In Mega Woman’s NORMAL state block, find this code:
// CONTROLS JUMP
if((blocked_down || coyote > 0) && input.A_pressed)
vsp = -jump_spd;
We want our hero to slide when we press the jumping button while holding the down button. To allow for both jumping and sliding, we’ll change the code above to this:
// CONTROLS JUMP / SLIDE
if((blocked_down || coyote > 0) && input.A_pressed)
{
if(input.down)
{
mask_index = spr_megawoman_slide;
set_bounds();
become(STATES.SLIDE);
}
else
{
vsp = -jump_spd;
}
}
The first condition stays the same (the hero has to either be on ground or have remaining coyote time to be able to jump or slide). But then we add a condition to check if the down button is held or not.
If it is held down, we do three things:
- Change the mask_index to our new spr_megawoman_slide sprite
- Call “set_bounds()” (a State object function) to update the bounding box of our hero object (This is important or tile collisions won’t consider the new mask)
- Instantly change the state to STATES.SLIDE
If the down button is NOT held down, the hero jumps normally.
Now all we have to do is build the new SLIDE state.
Creating the SLIDE state
In Mega Woman’s Step event, under the STATES.DIE block we created previously, add this:
case STATES.SLIDE:
if(blocked_left || blocked_right)
become(STATES.NORMAL);
state_play("slide");
state_pause(24);
state_pause_until(!is_under_ceiling());
state_set_mask(spritesheet_megawoman);
state_become(STATES.NORMAL);
if(input.left_pressed) hdir = -1;
if(input.right_pressed) hdir = 1;
hsp = spd * 2 * hdir;
if(!blocked_down)
{
mask_index = spritesheet_megawoman;
set_bounds();
become(STATES.NORMAL);
}
break;
Step by step explanations
Let’s look at this state’s code step by step:
if(blocked_left || blocked_right)
become(STATES.NORMAL);
The part above checks if the hero is blocked on either side (meaning he is touching a wall) in which case he instantly turns back to NORMAL state. This way if the player slides into a wall the slide will quickly be interrupted.
state_play("slide");
state_pause(24);
state_pause_until(!is_under_ceiling());
state_set_mask(sprite_index);
state_become(STATES.NORMAL);
The state functions above start by having Mega Woman play her slide animation. Then it introduces a 24 steps pause (Again, all state_* functions are played in sequence, meaning it finishes dealing with one function before moving to the next one). This defines how long the slide move lasts. Customize this to your liking.
Next we have another pause (state_pause_until()
) that checks for a condition. The condition checked is a handy Super State Function that checks if any solid tile is close above the actor. This part makes sure our hero doesn’t stop her slide until the space above her head is clear, preventing her from standing up and getting stuck inside a wall.
Once the slide is finished and the space above is clear, we set Mega Woman’s mask back to her normal mask and then send her back to her NORMAL state. Note that you don’t have to use “set_bounds()
” when using “state_set_mask()
” as this function takes care of calling “set_bounds()
” itself.
if(input.left_pressed) hdir = -1;
if(input.right_pressed) hdir = 1;
hsp = spd * 2 * hdir;
Above we check if the left
or right buttons
have been pressed and change the horizontal direction (hdir
) accordingly. Then we set the speed to be twice the normal walking speed and multiply it by the direction she’s facing.
This part sets the sliding speed but also allows the player to change direction mid slide. This is not strictly necessary depending on what you want to achieve.
if(!blocked_down)
{
mask_index = spritesheet_megawoman;
set_bounds();
become(STATES.NORMAL);
}
Lastly, this part checks if our hero has a floor under her feet. If at any point she finds herself above empty space she interrupts the slide and revert back to NORMAL state, causing her to fall.
Conclusion
So here’s another classic Mega Man move added to our game! I hope you enjoy this series. Next up we’ll look at how to create our own levels and eventually add a charge shot and other weapons.
Stay tuned!