How to make player movement for a platformer in Gamemaker Studio

GameMaker-Studio-Logo

(The following method is borrowed from Animator XP’s “Game Maker Studio Tutorial: Arcade Platformer Part 1 (Movement)”

1.Create a sprite, name it spr_player

Capture

2.Open up the sprite and select “Modify Mask”

Capture1

3.In Bounding Box, set it to “Full image”

Capture2

This allows the player object to have the best collision possible with platforms.

4.Create an object, name it obj_player

Capture3

5.Open up the new object and select “Add Event” in the events tab

Capture4

6.Select “Create”

Capture5

7.In the “Actions” tab, select “Control” and in “Code” drag the document icon into “Actions”

Capture6

Capture7

8.In the code window, type in the following:

room_speed = 60 // sets the game’s frame rate. (FPS) 60 is the ideal FPS for games.

jumped = false //the player is unable to jump until an actions changes it to true.

9.Then in obj_player, select “Add Event” in the events tab

10.Open up the “Alarm 0” event

Capture8

Repeat step 7

11. Type in the following:

jumped = false // this determines if the player is able to jump or stay on the ground.

This is changed in the “Step” code. The create event makes this variable and the alarm triggers when a player input changes it to false.

Repeat step 9

12. Open up the “Step” event

Capture9

Repeat step 7

13. Type in the following:

if(keyboard_check(vk_left)) //when the left key is pressed
{
if(place_free(x-5,y))//this checks if 5 pixels to the left are open space
{
x-=5//speed of movement.
}
}

if(keyboard_check(vk_right)) //when the left key is pressed
{
if(place_free(x+5,y))//this checks if 5 pixels to the left are open space
{
x+=5//speed of movement.
}
}

if(keyboard_check_pressed(vk_up))//when the up key is pressed
{
if(!place_free(x,y+5))//this checks if 5 pixels up and down are open space.
{
jumped = true//the alarm changes to true.
alarm[0] = 15// jump into the air. Affects how high the player jumps.
}
}

if(jumped == false)//when the alarm’s false, trigger the falling code.
{
//Fall code:
if(place_free(x,y+8))
{
y+=8//affects how fast the player falls.
}
else
{
if(place_free(x,y+2))
{
y+=2
}
}
}

else
{
//Jump code:
if(place_free(x,y-alarm[0]))
{
y-=alarm[0]//the alarm changes to false.
}
else
{
alarm[0] = 1
{
y-=0
}
}
}

14.Repeat step 1 and 4, name it spr_wall and obj_wall

15. Open up obj_wall and tick “Solid”

Capture10

16. Make a room

Capture11

17. Make a basic level and place obj_player in it.

Capture12

Capture13

The player should stand on the ground, fall when jumping and not pass through walls.

This method is good for platform controls that feel fluid and responsive on a basic level, but it has flaws. “Place_free” checks if a set number of pixels are open space, meaning this method is not ideal if your level design consists of pixel perfect platforms. Animation with player movement is also limited because “Keyboard_check” responds to the specific input.

Say you pressed left and the jump button together. Players will see the left key animation and not the jump key animation unless it’s the only button pressed.

E.g

if (jumped == true) //checks if jump is true

{

sprite_index = spr_playerjump //jump animation displays on screen

}

if (jumped == false) //checks if jump is false

{

sprite_index = spr_player // idle animation displays on screen

}

if(keyboard_check(vk_left)) //checks if the left key is pressed

{

sprite_index = spr_playerleft // left movement animation displays on screen

if(place_free(x-5,y))

{

x-=5

}

}

if(keyboard_check(vk_right)) //checks if the right key is pressed

{

sprite_index = spr_playerright // right movement animation displays on screen

if(place_free(x+5,y))

{

x+=5

}

}

If you require a method with complete and fully robust customization, use the method on GameMaker Tutorials.com

I hope this method has helped you with your title in progress. Do not hesitate to point out faults with this tutorial and take care.

References:

Gamemaker Tutorials.com “Platformer Basics [Article]” May 4, 2014 viewed on 22nd May 2016 http://gamemakertutorials.com/?p=383

AnimatorXP (May 8th 2016)”Game Maker Studio Tutorial: Arcade Platformer Part 1 (Movement)” retrieved from https://www.youtube.com/watch?v=sx50CKhfT88

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s