If you are not familiar with a game engine called Game Maker: Studio, but you want to know how to create a game, especially if it's a platformer. In this tutorial I'll assist how to create one, but I will put links to sources where I find this tutorial which helped me how to create a platformer game back when I was in high school. Also this is a different version of the Game Maker, so if you have a different version like 8.1 or any older versions of this game engine let me know if you want me to cover any these previous versions of Game Maker. For your information I will also include pictures to help out along with their links where I found the images.
First, let's talk about the game engine. Game Maker is a drag and drop engine; therefore, making it a very simple to learn to some people. It was created by the people at yoyogames, so in my opinion if you want to create a video game without worrying if you need the knowledge to program or coding. Of course it has a programming/coding feature(s) in it, but later in the years after it was created and then released there was updated and more advanced versions of it including Game Maker: Studio. Now let's begin the tutorial.
Creating the Sprites: We can't have a game without the sprites. To create your sprite or sprites, you need to click on the icon that looks like Pacman. Then name your sprites "spr_player" and "spr_wall."
Creating the Objects: Now, in order to create the objects for your sprites in Game Maker: Studio you need to click on an orb icon then name both of them "obj_player" and "obj_wall."
NOTE: Make sure to center the origin coordinates of your sprites.
Adding Variables: Now, we have all of the things that we need for the game; however, it is time to create a few variables. We need variables because how the player is going to jump over those platforms and more importantly the movement. Open up "obj_player" and then added in the "create event." In this version of Game Maker, the only action we'll need for this action is the "Execute a piece" action where it could be found in the control tab of actions, under code. Here's what the icon looks like.Inserting The Code:
So now we need know what keys on our keyboard that's being pressed and we can add our variables together to tell us which direction the player is trying to move on this frame. After the first line, the variable "move" contains either a positive one, zero or a negative one. We can now simply multiply this by our original "movespeed" variable which we set up in the create event to give us our intended horizontal speed in this frame. If we're holding left then "key_left" plus "key_right" would equal negative one and then "move" will equal negative one multiplied by four; therefore, giving us a horizontal speed of negative four. We now know how we're going to plan to move horizontally, but we need to work out the same with vertically. We don't want gravity to accelerate infinitely, so we're going to check that our vertical speed on this frame isn't already greater than ten which indicates ten pixels a second downward speed. I four current vertical speed is less than ten, then we can continue to increase it by our grav variable this means we steadily fall faster each frame. If we were currently standing on the ground, then we want the ability to jump, so we will use "if (place_meeting(x,y+1,obj_wall)" to check if there would be a collision with the wall object by exactly one pixel below our player. If there is, then we can allow the player to jump, but all we have to do is multiply "key_jump" (which will be one or zero) by our jumpspeed (negativity because negative vertical speed moves upwards). Then all we need to do is to check whether or not there would be a collision if we were to move horizontally using our "hsp" variable. We do this with the line: "if (place_meeting(x+hsp,y,obj_wall))." This checks, at the coordinates when we would be about to move to (x +hsp, and our current y coordinate) whether or not our sprite would collide with an instance of "obj_wall." If we would, then it carries out the code contained in the curly brackets {}. We will now know there's gonna be a collision, but we want to still move in that direction as much as we can without hitting the wall. We need to stop with a gap between our player and the wall, so to do this we have to use a "while loop" that moves us one pixel at a time towards the collision and then stop just before we would hit it. I should of explain that the sign "sign" function returns one or a negative one depending on whether the variable is given a positive or a negative. Meaning that if we are moving to the right, "sign(hsp)" should equal one and if we're moving left then it should equal a negative one also the exclamation mark in front of the "place_meeting" represents "not." Instead of checking to see if the collision WOULD happen, but we are looking to see if it would NOT happen. This means we can translate the whole "while" line to mean: "While there is NOT a collision, one pixel in our direction of movement with obj_wall." While that condition happens to be true, we'll increase our x coordinate (moving the player object now) by one until we're right next to the wall. At which point the while condition is false and the code will carry on normally. When we're done moving as close as possible to the wall, we can set our horizontal speed to zero as we've moved as much as we can without hitting the wall and we don't want to move any further. Now that we've handled any possible horizontal collisions, we can safely commit to our movement and increase our x coordinate by whatever is left in "hsp." If there was a collision then this will be zero (we already moved as much as possible). If not, it's whatever our inputs said it should be earlier in the code. For the vertical collision, we basically do exactly same thing.
The Player Input: Now, we have all of the variables it's time to add the step event into the "obj_player" and then create an "Execute Code" action. This is where the rest of the code go and will be executed by the player object on every single frame; however, the first thing to do is creating the player's inputs at the start of the frame. If your wondering like "What keys should we pressed or currently being pressed?"
The code above is basically the same thing except "keyboard_check" will return a one or a zero, but it depends on if the key is in the brackets that's being pressed. By the way, you can replace "vk_right" and "vk_left" with the "A" and the "D" keys or whatever letter keys you want to use. This is in the step event because the state of our keys change on every frame, but we need to know at the beginning of every frame what buttons are being pressed, though. The key left is set up to return either negative one or zero instead of a positive one or zero by putting that negative sign in front of the "keyboard_check." This is where we can add "key_right" and "key_left" together and then end up with either positive one for right, negative one for left or zero for neutral keys. That's what we need to do next.
The Collisions: Now, we got the easy stuff out of the way. What people get confuse is the collisions, but in order to do this we need to know how to do it and pixel perfect without using the "solid" function. Make sure your wall objects have "solid" turned off because it will cause problems later on. To detect a collision and then correct the position afterwards, but we're here to detect the collision before it can occur also adjusting our movement accordingly. Remember, at this point we've only been filling variables with numbers, "obj_player" hasn't actually moved anywhere, though. Let's handle the horizontal movement first.
As you can see the code is basically identical, but we just need to replace the "hsp" with "vsp" and make our checks against our y coordinate as opposed to our x coordinate, then once we've dealt with any collisions, move as before. Once you've put all this together your step event.
There you have it, a basic platform engine with pixel perfect collisions in roughly forty lines of Game Maker Language (GML) code while keeping everything full control over every movement the player makes and without using built in variables like solid and gravity.
What did you like and dislike about the game engine? What I like about this game engine is how the interface is still the same one from Game Maker 8.1, but what I don't like about Game Maker: Studio is I feel like you have to know programming and coding in order to create games in this one.
Did you find the game engine easy to use? I find this engine kind of easy because due to my knowledge of using the other Game Maker engine also I'm not a huge fan of the programming feature being used a lot in Studio, though.
What did you like and dislike about the game engine? What I like about this game engine is how the interface is still the same one from Game Maker 8.1, but what I don't like about Game Maker: Studio is I feel like you have to know programming and coding in order to create games in this one.
Did you find the game engine easy to use? I find this engine kind of easy because due to my knowledge of using the other Game Maker engine also I'm not a huge fan of the programming feature being used a lot in Studio, though.
What sorts of improvements would you like to see done to the game engine? What improvements I would like to see done to Game Maker: Studio is when you start it up it doesn't take you straight to where you can create the sprites, objects and et cetera, but instead it just pops up a mini window with the open, new, welcome, import, release notes, demos, tutorials, news, and licenses. That's just me because I'm used to the Game Maker 8.1 or below start ups better.
Would you consider using it for your own game? I wouldn't consider using it for my own game because I really love and feel less anxious when I'm using Game Maker 8.1 or 8.0 due to them having friendly user interfaces and having the drag and drop features in them. Also I cannot understand how to use Game Maker: Studio without using a tutorial.
Source:
Image Sources: