[Gamemaker Studio 2] Turned Based RPG Tutorial Part 1: Movement & Collisions

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this is sniper ninja and welcome to my turn based RPG tutorial in game maker studio 2 you can also use game makers studio 1 for this tutorial this will be a little bit more on the intermediate side but make sure you know just a tiny bit about game maker studio and GML anyway let's begin by making a new project select GML and we will name this project RPG video now the next thing I'm going to do I'm just going to drag this over here I like it better there and now go to game options and set your games frames per second to 60 this will make our game look a lot smoother now it's time to get started I'm going to create a new sprite and name it SPR layer mask edit the image go to image resize all frames we're going to set this to 12 by 12 what I like to do is make a white box now a black box with a white outline now we're going to create another sprite svr wall edit the image set the size to 16 by 16 and for this we will just use a simple black box alright we are done here now we will create a new object and we will name this obj wall set the sprite to SV our wall and now we will create a second object this will be obj player not only do we want to set the sprite to SB our player mask but we also want to set the mask to SBR player that way when we import our eight directional sprites in the next episode it will have the same collision mask and we'll get stuck anywhere so we will begin our code by creating a create event what I like to do in game maker studio is that in app desk so that way you have a initialize right for it that way you have the description over there if you're using game maker studio one you don't need to add app desk you just need with three outlines anyway let's initialize our variables speed equals four HC d equals zero g speed equals zero length equals zero there equals zero and we'll set our state to state next thing we will do is create a step event at desk every step get input you may notice that input does nothing at the moment but we're going to fix that soon step equals negative Y script executes State now what we're going to do now is create a new script called get input what this will do is it will well give us the input get input now what we will do is that we will make it so you can use either the WASD keys or the arrow keys at the same time you can use either he'd like our key you do this by using max keyboard check PK right I'm going to enlarge this window keyboard check board be zero so this will make us either check for VK right which is the right arrow or D now what we're going to do is that we're going to copy paste this and then we will make this L key we will change VK right to VK left and it will change D to a now copy paste both of these and with this we are going to create down key and up key as you can probably guess VK down VK up s W all right x-axis equals RT minus LT they say what this will do is that a it will check if we're doing if we're checking our key it will return 1 if we're checking LTL return 1 but when you subtract the two if you're pressing both then it will then have a zero so that way you don't move y-axis equals down e minus up key all right now we will add an e gamepad input if gamepad is connected 0 our key basically what we're going to do here is that we're actually going to check for for either the right stick the left stick or the d-pad game check correct right okay gamepad button check 0gp add our left key equals GP pad l EP pad the DB pad up now we're going to be using the max with the with the x-axis again x-axis equal to max gamepad axis value 0 GP axis left horizontal so until our ki KI zero and we are going to do the same with the y-axis hang on I added an extra an extra thing now you're going to look for the two vertical axes and the down key and the up key all right we are finally done with our get input script now we will create mood States Ronia a dot desk there so we will begin this script by getting our direction Direction equals point Direction 0 0 x axis and y axis point direction is a function that's actually very useful since it since basically what's going to do is it's going to take it's going to take zero and whichever direction the accesses are in so that way you'll return a direction that our player will move in now what we need to do is get the link if x axis equals zero and y axis equals zero then length equals zero else length equals speed now we're going to do is get the speed variables I on i spelt length wrong H speed equals length sir X blanks here length sir is a function that takes that takes your length I takes your speed and your direction to create basically a vector band more simple terms terms of speed in like which our direction the direction is V speed equals basically the same thing except this time I'm going to do length stir why now for our collisions we are going to use the while loop method if place meeting X + H speed by Bowie J wall while place meeting X plus sign in case if you do not know sign is basically takes a number and it just multiplies it to one or it turns it to one depending on whichever integer it's in Y for each AWOL X plus equals sign each speed H speed equals zero X plus equals H speed all right once we're done with that we're going to do the same thing but with vertical collisions copy paste this here now it's important that you check your code after this because because it's very easy to mess this up and get very messy collisions but always if you're if you're having a problem that you can't seem to fix just ask me in the comments I'll be my best all right so I'm in a mistake here what you need to do is I need to do Wow not place meaning that was a mistake I made whoops all right so this is my visual representation of the while loop collisions so you can hopefully understand this better first on frame 0 and position 0 we are moving towards a wall object that will stop us at a speed of 5 so in the next frame frame 1 we have done that I moved to position 5 on frame 1 once again on frame to move forward another 5 to expose to position 10 and on the same with frame 3 frame 4 is when things get more complex because when we are closer to the wall than 5 pixels you may have noticed that our speed is now 0 and the while loop has begun that is because if you are closer than your speed away from the wall then your speed is now 0 now if we begin the while loop inside the while loop if we are not in one pixel away from the wall we will loop and do it again notice how we are moving towards the world pixel by pixel but our frame isn't changing that is because in a loop our frame doesn't advance until the loop has finished in this case we can move one pixel towards the wall now once we touch the wall the while loop has finished so the frame advances one thing that might actually be worth noting here is that the player object isn't actually colliding with the wall object it's simply one pixel away from it and the while loop doesn't allow to get any closer all right we are now done with our code now we are going to rename our room to RM graph Karen if you're using game maker studio one don't name this RM grasp parent because parents aren't testing in studio one room parents at least alright now what we're going to do is we are going to set the room size to 320 by 240 we make this a little larger but there's one actually yeah I'm going to do that I'll hang on sorry this is taking a while just like my layout we're going now 320 by 240 is way too small so we're going to create a viewport basically in case you don't know what a viewport is it's not basically where we are creating a view in our room which is this white box right here and like if you have like a larger room like it will like follow the player as we can define right here set the vertical bore to 160 by 120 and now basically what we're going to do is that we're going to make this bigger by setting the viewport to 640 by 480 now we're going to place the player actually before we place the player in here one thing I forgot to do is Center the sprite now go to background we're going to like set this to a lush green color seventy and seventy all right this is a pretty good looking grass color now we're going to do I'm going to make this a little bit easier to see click this one is oom right in we are going to drag the player in here into the middle and now one cool thing you can do a studio to a sock you hold down the Alt key you cannot you can place walls or any object that's selected here we're just going to make some random wall objects here to test for science all right now we can run our game all right now when you run your game you'll see you now have a fully work game character with collisions if you notice that your character is moving to class make sure you change your speed back to 1 thank you very much for watching this tutorial if you enjoyed this tutorial please like subscribe and check out my other social media in the next part we will be adding 8 directional sprites to our turn-based RPG see you next time bye
Info
Channel: Aidan
Views: 189,854
Rating: undefined out of 5
Keywords: Games, RPG, Tutorial
Id: evkFHHNp0-Q
Channel Id: undefined
Length: 18min 52sec (1132 seconds)
Published: Wed Jun 28 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.