GameMaker Studio 2: Complete Platformer Tutorial (Part 1: Basics)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'm starting something everyone is due for quite a while I'm going to run a series on building a complete platform game what is completely well it means we're going from nothing at all for some lovely Squires moving around and eventually to something that looks like this front end to the back ended a functioning menu screen shake flourishes and everything you need to build your own high quality action platformer a lot of this is content I've made before reworked for game mix studio 2 and brought together into one complete learning package for a beginner developer so let's get started so humble beginnings you've got a blank project in gaming studio - what do we do now well in order to actually get to our basic platforming game from nothing at all we need to follow a few neat steps first thing we need to do is create what's called sprites for our player and all ok there's the two game objects we're going to be working on in this part so go ahead and right click in sprites and hit create I'm going to call it s underscore player as the sprite player for player I'm going to edit the image you'll notice by default my sprites when I make a new sprite are 32 by 32 you can see wet and paint over here your default when you first start in game make it might be 64 by 64 that's fine you can work with that as well but if you want to change it on you can go to file preferences and in there you'll find a thing to change your default sprite size I'm going to go with 32 by 32 you can also resize it if you want if you want to fold exactly what I'm doing but that's the size I'm going to use so now I've made this front I'm going to go into edit image I'm not going to spend long actually making an image I'm literally just going to grab a nice green color and just fill the box are just going to have a fill a green rectangle and that's going to be our sprite if I click this equals button here you can see the exact size of the sprite and that's really all I need make sure your origin as well by default minor is also set to middle Center yours might be set to top left by default make sure you select this little drop-down box here and just like the middle center or you can type 16 by 16 into here it's just important to have this little crosshair here that represents the origin or center of your sprite so make sure that is in the middle of your sprite okay Alton I'm gonna do the exact same thing again in fact I'm going to right-click s player I'm going to hit duplicate so we've got a second copy of this place right now and making sure I'm editing the second one rename it to a skin door and this is going to represent our war now quickly edit this to be just kind of a gray color or something for our wall objects that we're going to collide with again make sure that origin just lined up nicely in the middle there so those are just a couple of images okay they don't do anything by themselves I mean we could have put anything in there as well we could have added animation and so on welcome to that stuff layer those are just images they don't do anything in our game so in order to actually do stuff and have game logic we need objects okay and they kind of represent the logical blueprints they carry all with the game logic for our game so we're going to make a couple of objects one for the player and one for the walls for right-clicking objects now and hit create you'll see if your workspace pans down here give you a new object editor I'm gonna call a player okay Oh meaning object player being player that's going to be our player object in here it says no sprite you want to assign this to your player sprite gauge to clip that select your player spray okay in is Benson here is where we're going to put all the game logic of the game but before we actually do any of that on first of all just going to create another object for our wall in the Cold War set the sprite to be s wall okay sighs our wall sprite so now we have a couple of objects now before we actually set up any real game logic or anything like that and dive into the the nitty-gritty of developing a game let's just go to our room okay so in rooms you'll notice you already have a room 0 that's been added by default every game make a game needs at least one room in order to run at all in the first place so it gives you one by default we just double click that it'll open up room editor so you'll see you just have this big sort of blank rectangle at the moment with kind of a grid and in fact if you were to run the game right now this is all you would see you would just see a game window with a big black rectangle and it would be nothing and it you win seats grid either that's just a that's just to help you please stuff in the remittitur you just see this blank rectangle so we need to actually put stuff into our room or into the game world if you will so you can see we have kind of a couple of layers on the right here we have Bank ground down instances make sure you've got the instances layer selected then just click on the resource tree on your player and if you hold the Alt key you'll see him appear under the cursor again as we just holding the Alt key you can also just drag which I might just from the left like that and place the player into the game mode or as I said now I'm going to select wall to start placing the walls around if you hold alt and see okay little cursor you can then just click and drag to add multiple of an object into the game world some people who are maybe maybe a bit more familiar with some of my older videos might be wondering why we're not doing a tile collision system or we can use an object collision system but we will come to tiles and maybe a later part we're going to keep this real simple now just the beginners okay so which is some walls there just to kind of curve out a rough shape of a kind of a level for us to jump about in and that's really all we need I'll just order the week these ones up the edge here just select and then and pressing delete on the keyboard just kind of clean it up a little bit get rid of some ones we don't really need there we go just nice sort of smooth layout there so we have we have a room we have a game object and we have our walls about to run the game now though we've not really given this game any instructions to work with other than what should appear in the game room so this is our game so far it's just a little green square and gray rectangles everywhere so what we actually need to do to get you know a video game out of this we'll get something playable or interactive is actually give the game instructions we've not given it any instructions we've just other than you should place these objects around here in this room okay that's all we've told it so in order to get more instructions and now we're going to edit these game objects o player and we're not really going to overall much overall is just there to be a wall but we're going to do a lot of editing to O player okay so double click on a player just to bring you back to the workspace now and I'm going to press X 12 just a sort of you know myzel workspace and give us some space to work with we've got this window called events now what's an event um well the waking maker works if every object is based on events and actions an event is when a certain thing in the game happens so the user pressed a button or a frame passed or the objects got made or destroyed or the room start or the game ended or something like that those are what's called events okay and then they trigger certain actions to go off which will appear over here so I'm going to click Add it then I'm going to add the create event okay so the create event is triggered it'll be triggered right at the start of the game when when this object gets made in the roof the very first time by our game okay so what we're saying is when this object is created do whatever code we write into this box okay now we're going to get start with some very very very basic code okay I'm going to declare a couple of variables okay so I'm just going to write a few things and I'm going to explain what they mean afterwards like HSB equals zero with a semicolon on the end there as well PS T equals zero gr v equals naught point naught 5 I can make that null point one and walk SP equals four okay those are for variable so you see they turn blue the words on the left side of our equal sign and the numbers on the right have turned red okay give me kind of works out like why it is you're typing when you're writing code and it marks certain elements appropriate colors so what what am I doing here maybe I've just lost all your just written some nonsense what does any of this mean well a variable is just a word any word we can make up I can type in any number characters like that this is or whatever equals and then say 50 basically all I'm saying is that this word from now on whenever I'm type it in the code means this number okay that's literally all a variable is okay saying a word to equal something else usually a number the things but most of the time I can be another variable so now I've got HS P equals zero so every time I type HS p I'm basically telling the game zero okay what I can do later is say like HS p equals PSP for example and and set one variable to equal whatever the result of another one is and then basically if how the bulk of programming works is we're just comparing and changing what numbers are in these different variables in order to affect stuff in the game okay that's how we create game logic we just compare and change numbers around until we get what we want okay so I'm just going to make this a bit bigger now just so you can definitely always see whenever I'm typing on the screen here so changes people's 0 so we wanted all these words mean these are all shorthand things like what only leaves mean HSP I'm using a shorthand for horizontal speed okay H for a horizontal SP for speed you might get PSP vertical speed okay gr V is going to be gravity and walk SD is walk speed so that's the speed we actually want to move when we when we move left and right we're going to set our horizontal speed to be this number in whichever direction okay so the reason HSP and VSP are currently 0 is because we don't actually want to be moving at the star the game we want to set yourself to move based on whether you're pressing left and right or whether gravity is applying speaking of gravity that's what grv meanest geography stands for gravity and I'm saying that tune or point one meaning we're going to move downwards like no point one pixels a frame every single frame while we're in the air okay until we touch the floor so just copy those down if you're following along don't worry too much of over I've already kind of lost you diving this code it'll all start to become clear as you do more of it the more of this you write the more you practice the more to all start to slowly make sense okay feel free to go back and re-watch if you don't understand any of the explanations I just made the only other thing I'm clarify is that the semicolons on the end here that just tells game maker when a line of code has the next Oh cakes you can technically do fear funny things where you carry on one line of code onto multiple lines as weird as that sounds but for now all you need to remember is at the end of almost every line of code you want to write a semicolon just a special detail GameMaker where that line of code ends ok make is actually very forgiving place you get away with actually not putting this most of time like that will still work but it's good practice just to make sure you have those on the end every line ok so now we've done that now we've established a few of these variables what I'm going to do is add another event I'm going to add what's called the step isn't come down here pass creates the fourth one down step and you've got three different kinds that begins step and end step don't worry about those last two just select step ok step event is a special event that happens every single frame of your game so if you play games and you know about frame rates and things or even if you don't games tend to run at either 30 or 60 frames per second okay that means like you're being basically every game is just showing you a sequence of still images certain speeding is shown and fast enough to you that everything looks like it's moving right each one of those images is called a frame so at 60 frames a second are step event is going to be logic that happens every single one of those so 60 times every second and this is where we put the majority of our players game logic okay so every single frame we check to see whether or not the user is pressing left or right or pressing jump and then react accordingly and do other stuff okay so that's the very first thing we're going to do is we're going to check to see if the player is pressing left right or spacebar while I left forward jump okay so how do we do any of that well I'm going to do the same thing I did in the create event by establishing some variables but I'm going to do it a little bit differently and I write some stuff and again I'll explain what it all means afterwards so I'm there right key left equals keyboard check Open bracket EK left okay so what Warner does any of that mean we because as you can see I've got this blue line a text again here but this time we've got a yellow word on the right-hand side okay and this is what's called a function or a command okay what that is is basically a special line of code that does a certain thing in your game or checks a certain thing and in this case keyboard check what it does is it checks to see whether or not we're pressing whatever key we specify in this pair of brackets okay so especially IBK elect which think sounds a virtual keyboard left okay so that will tell us whether or not we're pressing the left arrow key and whether if we are then boy basically what this whole line will mean is one okay the number one and if we're not pressing it it'll be the number zero okay so just like binary 0 for false 1 for true and that number is then going to get placed into key left so then we can leave a check while in key left to know whether or not we're pressing the left arrow key I'm going to do the same thing for some other keys I'm going to write course keyboard check Open bracket BK's right close bracket semicolon then a key shrimp lastly keyboard check and this time underscore Pro cracks DK space so now why have I run underscore pressed here well that's going to basically we don't want to check every single frame whether or not we're holding jump we want to check to see whether or not we pressed it on this frame okay so whether these just return 1 or 0 based on whether or not the key is held or not this returns 1 or 0 depending on whether or not the key was pressed on that frame so the very frame that you actually pressed it for the first time after that it'll just return 0 until you let go with the bone and press it again okay so now we know whether or not we're pressing left right you'll jump right so now we need to actually react accordingly so I'm going to make another variable this time using the group of our function ok you can see that turns yellow as well because it's doing something special and GameMaker one vial does is it lets you establish one of these variables on these blue words but establish isn't as kind of a yellowy tenth word and what it means when you establish using var is that that variable is temporary okay so it only lasts for one frame so one loop of this step event that's as long as it lasts for so the barge we called mu and now when we set this to equal is key right - key - left now think about what I just told you about these variables okay so key right is going to be 1 or 0 then or not we press the right arrow key and key left is going to be 1 or 0 depending what whether or not we press the left arrow key so if I subtract a key left from key right imagine you're pressing a right but not left so you'd get 1 minus 0 giving move 1 now imagine you're pressing key left but not key right you'd get 0 minus 1 minus 1 okay so you get 1 if you're moving right minus 1 if you're moving left the reason I'm doing it this way it might seem a bit like anti intuitive but the reason I'm doing it like this so that if you're pressing both Keys you get 1 minus 1 0 so that you don't want to move at all when you're pressing both arrow keys or when you're pressing neither 0 minus 0 is 0 k it just handles every every possible outcome very very elegantly okay it's a very smooth way of dealing with whether an or you're pressing left and right and whether or not you should move in that direction so now what I'm going to do is I'm going to set our horizontal speed so remember the variable that we wrote HSP we set it as 0 and I'll create event in here he just B equals zero are what we're going to do now is set that to equal movie so whatever that happens to be on this frame it might be 0 1 or minus 1 multiplied five walks but okay so work SP which is four that's our current walk speed or however fast we want to move let go right so we're going to get either one zero or minus one so if we are holding the right arrow key we'll get 1 times 4 so we'll get 4 meaning we want to move 4 pixels to the right or if we're holding the left we'll get minus 1 times 4 minus 4 we want to move 4 pixels to the left or it will be 0 times 4 if we're pressing both or neither meaning we don't want to move at all okay and HSP is going to get that final result so it'll be 0 minus 4 or 4 and then all I'm going to do in order to so we can actually see some of this are working now because we've done a lot of playing around with numbers and variables and that really seemed any fun game stuff so when you set X you see X turns green because that's a built-in property of our object as a few of those okay the things like sprite index and all sorts of different properties and things you can actually physically change about the object X represents its x-coordinate in the room ok so that's a horizontal corner in the game room Y represents all vertical coolness of change we change either of these to be something else the object will physically move in our game world and it's an X to equal itself so whatever our x-coordinate currently is is going to equal itself again which obviously wouldn't change it but we're going to add KSP ok so we're going to add either 4 or minus 4 to our current x-coordinate and to move the movies around so we'll either move 4 pixels to the right or 4 pixels to the left and now before I run the game I'm going to quickly go into game options okay and just at the top here and main options general I'm going to set game frames per second to 60 just so we get a nice smooth 60 FPS game you can we better 30 if you prefer then I prefer a game to run another smooth 60 I'm going to hit play now or you can also press f5 you see we've got game again just our green objects and white squares now but if I press the left and right arrow keys now you see our green square actually starts to move around okay so there's some obvious problems here we've not quite got a platform yeah okay we can move left and right but we can move through walls that's no good and we don't fall and we can't jump yes because there's no gravity and that's because there's also no collisions setup with any walls okay so that's what we're going to look to do next okay so back in our player object we now need to check to see if we're colliding so how do we work out if is a collision between the player and the wall and then how do we react accordingly right um what we're going to do we're not actually going to check to see if we like a currently colliding with the wall we're going to predict it okay so here we've worked out with HSB where we're going to move we're going to end up moving at X plus h SP so what we're going to do before we commit to making this movement just in the middle here we're going to check to see if there is a collision and if there is we're going to reduce our speed and stop that problem before it actually happens before I do that I'm going to add in a couple of quick comments in here just so we can see what each section does so by typing two forward slashes and where you can see the text turns green and that means I can just write whatever I want and it won't get a computers code I'm just useful for writing notes and reminders so this section here is a get-well important I suppose on this section here would be calculate movement we're going to do horizontal collision here okay just useful see if you can sort of tell what's going on in fact we're running our spaces so I'm going to do is I'm going to press after well just close this maximize this just so we've got as much space as possible here to work on our code okay because this is basically all we need to work in now until the end of this particular part for horizontal collision I'm going to type it place meeting okay open bracket X plus h SP comma Y comma o wall close bracket close bracket again underneath open up squiggly bracket close the square bracket now that was a lot of stuff so what is any alampi now if you can see it's a special thing quite like var what is does is it asks game maker a question okay that question is what we put in this pair of brackets and it says if the thing that in the brackets is true do whatever we put in these squiggly brackets if this is not true skip it and just go to whatever comes after it okay so if and in place meeting what place meeting does is check to see whether or not there is a collusion between this object and the object that you give it here in the brackets at this position okay so if if my player happened to be in this spot would there be a collision between my player and a wall and if there is it returns 1 if there isn't it returns 0 it returns 1 we do this stuff if it isn't we skip straight to movement so is there a collision between myself and the wall and if there is what do we do about it so if there is a collision first thing I wanna do is set HSB 2 equals 0 right we don't want to move anymore now that we know that is going to be a collision if we were to actually move where the player was telling us to okay but that's not all we want to do because if you think about it if you were say 3 pixels away from the wall and you wanted to move 4 pixels towards the wall now problem there is that you can set your speed to 0 but then you would still be three pixels away from the wall so what you actually want to do is say Oh speak 0 but then move as close as you can so how do we work that out well organize what's called a Y or statement while now while for the most part works exactly the same as a gift okay we're going to ask a maker a question in these brackets if that question returns true we're going to do whatever we put in these squiggly brackets okay so what's the question we're going to ask to see if we're not if there's not a collision one pixel in the direction we're moving okay so you can do see how we did if place meeting up here that's to say if there is a collision we want to see if there's not a collision and you can do that you can change anything to a not instead of an is just by putting an exclamation mark in front of it so by typing exclamation mark place of meeting we're going to check to see if there's not a collision okay it flips the result you get so if I get a one it reaches zero if we get a zero treat it is a one okay just a quick way of doing that so we can check if our X school in that but not plus our for horizontal sleep of sine HS key and then comma or Y corner and I'll get working for is a war again okay so if there's not a collision at X plus sign Hegarty what sign do though that's another function what I've auditors do assign returns either 1 or minus 1 depending whether or not the variable we get is positive or negative okay so because HSB like if we were moving for the right edge of D will be 4 so a sign HSB would be 1 4 meaning left it be minus 4 so sign HSP would be minus 1 okay so if that happens to be true then we do whatever is in these brackets now the difference being a while statement and an if statement so while stem will continue to do these things over and over and over and over and over again it will just loop on the spot over and over until this condition is no longer true okay so as long as there's not a collision one pixel in the direction of movement we continue doing what's in here over and over and over we don't even finish a new frame until it's done they have to be very careful otherwise you can cause freezers and infinite loops if you get stuck in a while statement so you're going to be careful how you use them and make sure the condition eventually returns false so what do we want to do while there's no collision one pixel to the side of us well we want to increase our x-coordinate by 1 in that direction so I'm going to say X equals n plus sign plus P so we're going to increase X by 1 in either either to the right if it's plus 1 or to the left of its negative 1 okay that there should really be enough if I press f5 now and run the game I should see if I move to the left I can't go through the wall anymore I collide flush against the wall nice and cleanly if I move all the way to the right again flush against that wall perfect pixel collision okay so now there's obviously a problem again we don't have any gravity still we still can't jump or anything like that so let's fix that okay let's move these things close together because this is a horizontal section okay let's create a collision section for vertical movement okay I'm just going to copy and paste that whole section because what we're going to do is completely the same thing okay so I'm going to change this to avoid football and now we just need to move these Plus HSPs to the y coordinate and change them from HSV to vsp for vertical speed right and then we want to change these X's to YS so make sure you do all of those steps okay if you're falling on make sure you copy this down as well I'll just do it person and you can make sure you've got it exactly right okay so I'm going to cut just with control X this section front of X here paste in front of Y instead and do the same here this plus sign HSB cut that paste it in front of Roy instead okay just those two sections I'm going to rename HSD to the SP instead okay then I'm also going to change this one the VSD this one 3 SP and oops and this one the VSP okay so you should have no HSPs left in this section nation or every single these blue things should read VSP okay make sure and I change these x coordinates here to wise look okay so those should be wise we want to leave these X's in but change all the rest of those those other four are just these four too wise okay then that should be really that should be it okay that's everything we need to actually change there that's the local collision we go which is complicated that change some variables around exactly the same thing just in the other direction with the other coordinate we won't know is it yaks we don't actually have any vertical movement so that sticks of that we want to move by our gravity okay so I say VSP equals d SP plus TR v remember that's the gravity variable we set up in the career then it's no problem let's change it nor point three make it a little bit quicker okay once you do Matt come back to you the step event so that should be enough to actually make us move by gravity so if I run the game now just press that five that or compile a little bomb and then you can see right start there just fell down and I can demonstrate against by walking off this ledge just watch very carefully I thought okay and I learn flush against the surface as you can see are still colliding perfectly so we're almost there now we always have what some recognizable as a platform and right so they close that the last thing we need to do is make it so you can actually jump so jump in how on earth do we do that right so what we first need to do is check if we're on the floor okay um we obviously don't want to be able to jump over in the air or maybe we do in which case ignore this next line of code which is going to be if please neatly again just another collision check X our current x coordinate y plus 1 so one pixel the lowers remember vertical movement is positive if we're moving down or it's negative if we're moving up and all wall or the wall object closed both pairs of brackets open squiggly bracket and closes it again so if we're on the floor okay so if we're on the floor we also then want to check to see if the jump key is being pressed now I could type if we jump here and open another if statement but we don't need to do that what we can do is combine our current listing with another one so if I type to ampersand symbols here or I just write the word and I'm going to use the ampersand symbol look at the same thing that means we're going to check two conditions so we're going to check to see if this is true and whatever we put here is true okay and we'll only do what's in the squiggly brackets at bed both true okay so and II jump okay open another one there we go so we've got two conditions that if we're on the floor and we just press jump so what do we want to happen well we want to change our vertical speed so it take VSP equals negative set okay I'm just going to save because we're going to move upwards we want to move upwards by quite a lot so I'm just going to use big negative number negative seven so allow us to jump and now if I press f5 you can see we're on the floor there and we fall to the floor and if I press space we actually jump in and gravity brings us back down so they have that's the basics that's setting up a very simple platformer game that's a lot of if you're very new to programming that's quite a lot to get your head around for this so if you didn't understand any of this code at all first of all I'd recommend just you know typing it all in exactly as you've seen here exactly as I described it and then what you can actually do is you can middle click on any of these functions and they'll actually take you to the manual ok the manual open at the page for that function it will tell you what it does okay I hope you enjoyed that and I'll catch you guys next time thanks for watching a huge shout out to my patreon sports without whom none of these videos could realistically happen a big big shout out in particular to Dan Angel Rodriguez Harold Guidry and Jason McMillon thank you guys ever so much and thank you for watching this video if you enjoyed this video or found it useful maybe you subscribe or maybe pledge a dollar to them month on patreon up to you don't you like um but I would totally appreciate it thank you very much for watching I'll catch you guys next time see you guys
Info
Channel: Shaun Spalding
Views: 1,428,056
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Tutorial, GameMaker Tutorial, GameMaker, Game Development, Indie Games, Tutorial Series, Game Maker Studio, Making Games, How to make games, GMS2, GameMaker Studio 2
Id: izNXbMdu348
Channel Id: undefined
Length: 32min 50sec (1970 seconds)
Published: Fri Jun 23 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.