GameMaker Studio 2 Tutorial - Character Movement for a Maze Game

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome back for this tutorial we are going to learn how to create a character that moves around in a maze as shown here on this example you see he's he moves around in the maze and what you may not be able to detect here is that he is aligned to a grid so he can only stay on the grid here fine I can turn on a grid here didn't kind of see what I'm talking about here he stays in this grid if you notice his origin which is that green X there this green X is always on one of those red lines whether it's a vertical or horizontal line he is stuck to that grid okay so we're gonna learn to do that so let me close this down real quick and we will get started here so I've already started opening up my game here and I've already got the sprites that I need for this you should already know how to create these left right up and down sprites if you don't there is a video on my page that will demonstrate how to do this so if you have not done this yet please do so if you again if you don't know how go watch the video to show how to do that in addition to those you need a little block sprite just a something square you can get it from the internet anything like that it should be square if it's not it's not it we can we will ultimately make it square so just be aware that so if you have not done that yet please pause the video and go and take care of that get it set up so as we see up here with there again are four directional sprites and a another sprite that we're gonna use for our walls of our room okay alright we're back if again you should have all of these sprites set up and we're going to go ahead and get started and the first thing we're going to do is we've got a we've got to change these sprites here so they can be used in the type of game that we need first of all we've got to take our sprites here for our characters and make them square so there's a couple different ways to do that one of them is by you click over here to edit image and up here you go to image and you go to resize all frames right here click that this little window pops up and what you're going to do in this case we want to resize the canvas we don't want to stretch this guy if we were going to stretch when we would use this when we want we want to resize the canvas so it's Square and the canvas is this rectangular box that our character is sitting in so you want to look at his width and height right here and again click resize canvas here if you haven't already click look at his width and height to find the larger of the two typically it'll be the height and will be larger in these cases but sometimes they're the same sometimes the it's it's a little bit wider than it is tall but whatever whichever one of these two is the largest that's the number you want to use so you want to click the other one change it to 40 oh I'm sorry let me clarify someone make sure this is unchecked make sure maintain aspect ratio is unchecked so change that to 48 so or in my case it's 48 and yours it may be different just depend on the sprite that you use so again both these should be the same once you do that you click apply and you look what has happened here you see now our canvas is a square so you can go ahead and close that sprite and if you look at the little sprite the properties window here you'll see it's 48 and 48 here so we have to repeat this process for all the others now it's a slightly different way we're going to do it this time instead of going to edit image we were just gonna simply press this button right here click that and you see the same window pops up you can do it there too as well so we just resize canvas 48 and forty-eight make sure these are both the same whichever was larger and it should be that was this whatever the first one was these all should be the same thing if you want to click that center button right there just to make sure that it's centered you do that and you see it shrunk down here if you just click this button right here a little large back up so you can see the whole thing just repeat that for the last two I'm gonna do it kind of quickly again if I'm ever going too fast just feel free to pause the video okay and then again I'm Marge that swings it and last one here same thing forty-eight and apply now the other thing you want to do is check on all four of these check to see that the origin is in the top left okay so I'm going to check left yeah top left okay right yep top left up top left and down top left okay now remember this number right here which is either one of these it should be the same in my case it's 48 years maybe different so and then you go to the sprite for the wall that you should have imported already and you're gonna do click the same button here again but this time instead of resizing the canvas we are going to scale the image we're gonna make this image 48 by 48 now if these are the same right now if they're both the same thing right now you can leave this maintain aspect ratio checked if not you can unclick it if you unclick it it it really doesn't matter because you can you do all that means is you just have to change both of you notice when I click it here if I go if I go 57 and then hit enter they both go to 57 or they both change the same amount the same percentage so with it's unchecked all I got to do is just type in the numbers manually like this so these should - these two should be the same so to make that happen and what I would do - before you click apply here is this interpolation here if you wanted to make it look a little nicer click linear here and it will make you a kind of a smoother looking block here I'm gonna be a little it looks just a little bit nicer okay so I'm going to go ahead and close this right now oh yeah I know we're jumping ahead of myself here all right so now what we want to do is we want to create two objects now now you might notice I have an object here this is something that we're gonna use that I'm gonna use later on you're not going to create this object this is just something for me for demonstration so I'm gonna right-click go to object create and I'm gonna create the object for the night so I'm gonna zoom and remember you're naming the rules about naming conventions just be consistent there you go night and then again I'm using that naming convention because it's very similar to the one I use for the sprites and I'm gonna click the down sprite so he's facing me when the game starts okay and then I'm gonna close and I'm gonna go and I'm gonna create another object we're gonna go back to that guy in programming but right now I'm going to create another object here go create and then this one we're gonna call object wall or again you can call it whatever you want and we're gonna set that sprite now what we have to do with this one here is we have to make sure it is solid okay because we don't want our guy walking through it okay go and close this we don't have to we're not gonna do anything else to that wall object yeah yet now the next thing we're going to do is we are going to set up our room we're going to draw our castle or walls in our room here now without changing anything I'm gonna start drawing the wall and you're gonna see a problem right away here and again if your yours ends up the right size you may not have this problem but if you do this is how you solve it you've got I click the object wall here and holding the Alt key down I can now draw my walls here let me undo here because yep okay let me get these back down to the default settings here okay yours probably says 32 by 32 here okay the only reason mine said 48 because I've run through this tutorial once before and that was that's what it was set to all right so let me go back here so if I if the default settings at 32 by 32 then it will cause problems here I'm and excuse me I'm changing something back to the way it was before I started the game here before I went through this tutorial alright so for object wall here a select object wall and I hold the Alt key down and you see when I try and draw them they do not stick together here okay they're they're separated apart from each other that's the reason these are 48 by 48 pixels and our grid is 32 by 32 so the way we fix that is you go up here where we're you guys saw just a second ago you click here and you change your grid size to whatever the size of your sprites were again mine were 48 yours were 50 that's what you would put there were 64 whatever it is that they whatever the is that they are that's the number you want to put that's your magic number for the for the project here so I'm gonna go ahead and erase all these and again too to erase these you hold the shift key down and just click and drag a window around all of them and hit delete so now with that wall selected again now I can go through and I can I'm holding the Alt key down I can draw typically what I'll do is I'll draw a border around this and you'll notice I can't go to the edge over here if I go to the SEM I'm missing I've got a little bit of border over here we're gonna deal with that in a second here now before I so before I go and design the whole room actually I'm gonna do that now I'm going to pause right now and I'm gonna create just draw up a room real quick so I just pause yourself and and just draw the room around if you want to wait for a second you can kind of see what I'm looking at you don't have to make it the same way but just hold on for one second okay okay as you can see I've created the room just a series of walls you don't have to make yours exactly mine at all just get the walls arranged here now if you notice on the edge over here you see I've got some extra space here so I can change the size of my room to get that to be even here so what I do is like I just simply count how many blocks of complete blocks I've got so I got 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 and I know my blocks are 48 pixels wide so if I get my calculator out or 48 I'm sorry so I go 21 times 48 and that gives me 1008 so I know that's how wide I need to make my room so if I go back to my board here and then you see over here on properties over here you can see there's the width if I change that to 1 1003 was that was that my number no 1008 sorry then this will perfectly fit now if you do not see these properties over here click up here at room and find room properties that should open up this window so I'm going to change this to 1008 so now you see that the room fits perfectly now vertically it looks okay but we're just going to double check it mathematically so I'm gonna go 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 and there's again 16 times 48 so I'm gonna look and go 16 times 48 equals 7 68 and if I look at my height yep I'm good 768 happens to fit perfectly so again if you need to change yours do that at this time I'll give you a couple seconds here or if you need to pause the video that would be best okay then I'm gonna stick the guy in the room I'm just gonna stick one copy of him in the room here and I'll quickly play it just to so you can see that he's uh he's just gonna be standing there and it looks like he's dancing here he goes okay so we got it now we got to get him to move alright so first we're going to do is in his create events we're gonna remember when the when the game starts we wanted to not move like that so we need to create a a creative that so go over here double click on object night and again that's our event I'm gonna open this stuff up here so we can I've got a little more room to work with so again when the game starts or when he is first created so you click Add event creates we are going to set his animation speed so he does not cycle through sub images again it's over in the instances section this one here the guy chased after the two triangles that said animation speed we're going to set that to zero okay now we're going to create a couple of variables here that we're gonna use to control how he moves in the game this makes it a little bit easier later on to to do that so we're gonna set variable I'm gonna set three of different ones here so I'm gonna go ahead and quickly drag three a minute here then we'll fill them in here I'll zoom in here so you can kind of see what I'm typing so the first one is going to be SPD again this is we did this in a couple of the variable a couple other tutorials this is just gonna represent the speed we want him to go when he's moving okay it doesn't actually set his speed it just tells you this is the value we want it to be now this you got to do a little more math here that for the speed here the speed in order so in order to keep him so that he can line up the grid your number here has to be a factor of your grid size so your if your grid size like mine is 48 then the factors are basically any number that divides evenly into 48 so 1 2 4 six I believe eight I think 12 24 those numbers so now some of them are obviously way too fast so if we look down to the you want about 4 or 5 ranges that is the number you want so 4 is divisible or 48 is divisible by 4 but it is not divisible by 5 so we are gonna go and stick with we're gonna use 4 here now the next one is going to be for how fast is little legs flop around when he's walking so this is we're gonna we use this same word before and again you can whatever you want to put here is fine both of these are user created variables that that you can make up the name as long as you don't use something that's already being used by game maker you will not have a problem okay so I'm using an e speed a and I SPD if you want to use that so then when we're later on we are working together we can have the same spelling and you know confusion so I'm gonna set this to 0.5 I want his legs to go at half speed is it full speed sometimes he looks like he's flopping around a little bit too much now this last one this is a new one we're going to I'm gonna use I'm gonna call it grid and what this is going to be is the size of our grid and the size of our grid is simply what our whatever our sprites are this wall sprite is 48 by 48 so that's the value I'm going to use so I'm just gonna make that 48 this is gonna be used in some calculations to keep him lined up with the grid okay so okay so we've got that this is our create event against that animation speed to 0 assigned variable SPD to 4 assigned variable any speed Ani SPD to 0.5 and assigned variable grid to 48 or whatever again whatever grid size you have okay now we're going to get him to move we start off with just setting a direction setting a speed changing a sprite and then setting an animation speed so again we want this to happen when the left key is down so we need is key down left and you just if you decide to use a wsd then it for left you would use a key down letters a instead ok so again we're going to set direction which is in the movement and the movement section that guy right there you want to move left we're gonna set his speed which is this guy and we're setting his speed to SPD and again right now for my game at least that value is equal to 4 then we're gonna set his sprite which is up on instance in the instant section here this is a pac-man looking thing we want it to be the left facing sprite which is the first one here and we're gonna set the frame whoo frame is gonna be zero relative and the reason for that is if we if we don't click relative here it's gonna every step that that that left key is held down it's gonna want to go to frame zero and we review this before but I want to go over again frame zero would be this guy right here so if that key is held down it will want to it'll send it to this sub image which will make it look like he's sliding we don't want that so we set it to zero relative what this means this will add zero to whatever the sub image is so if he is on sub image 3 he's on sub image 3 he will stay on sub image 3 because we'll add 0 to that ok so what we do there and then the last thing we want to set his animation speed let me close this set animation speed which is again in the instances section right there the little guy chasing the triangles that down we want as animation speed to be Annie speed and again the we've set that value to be 0.5 so let me zoom in on this so you can kind of double-check your work here Direction fixed left direction then we got speed or set speed to SPD set sprite to the left sprite and frame is zero relative said animation speed - Annie speed okay now we're gonna simply duplicate this for the other four directions so we could start testing our game here so duplicate event again to duplicate you just click on the one you want to duplicate and get in this case we wanted to get the left key and you right click and you go duplicate event and then you pick key down right again if you're using the letters a WASD then you would go key down letters D in this case duplicate it again for up and down which would be W and s if you're going to use the keys duplicate event key down up and okay to get one more time key down down okay so then we got to go through and just double check our we got to change what we need to change here so up obviously the directions going to change it up and our sprite is going to change to up and again that's the only two thing we really need to changing all of them so for the right change it to right change this guy to the right facing sprite four down and click down change this now again you can slide this slider here so you can see these a little bit better here's our down key down guy so click that so now if we play our game you will see that the guy will now move the knight will now move left right up and down but he's gonna go through walls that's because we have not told him not to okay so we'll do that so exit out of this and again if I'm going too fast please just pause and until you get caught up and then and then continue alright so again we want him to stop when he hits a wall okay so we're gonna do that we're gonna click add event and we're gonna go collision with the wall so when he collides with the wall we are gonna want him to stop basically so all we're gonna do is set his speed is zero and go down a movement here just so you remember where they are movement set speed to zero we're gonna set his animation speed which is in the instances section here there we go say the animation speed we're gonna set it to zero so he'll stop walking as walking and then since we don't know which direction we're heading when we hit the block we're in we can't use this we can't use the set sprite and set this to zero because we don't know which one of these we want we only the only thing we want to do is hit the is set the frame we can't do it here so don't use that when you're going to use this set instance variable drag that into place the variable we are changing that controls the frame that the character is on is called image index so this should say image index and it should say zero relative so now if we play the game whenever he hits a wall he will stop and go to the first sub image so that these legs are together so you see he walks in there and there we go okay all right now one other thing that you will have to do now again I've already run this so run through this tutorial so some of the changes I made I have to unmake here so you're going to show you what you need to do now what ends up happening here is see he gets stuck here and he can't go through hallways unless he is perfectly lined up so that's we got to do a few things to make it so that he can get through these hallways here so one thing we need to do is we got to make a little adjustment to his sprites so I'm gonna go ahead and open his sprites here and you're gonna open up collision masks right here on the left side here now yours is probably set to automatic like this mine mine was again set to the setting we need because I was a had run through this tutorial already once before so you see this is what the computer sees we we need to get him so that he stays lined up with the grid and this is one of the methods we do here instead of making the computer just see this we're gonna make it so the computer sees this entire block as this character so if you go over here to mode right here you click the little side thing here and go full image and see the whole thing turns gray down now the computer will see that now be careful not to click down over here while you're doing while you're working on this because you'll end up undoing the origin see if I click over here then my origin gets mixed up so before you exit make sure this says top left again okay so you're gonna repeat that process for all the other ones so if you click on preview mask on all these again you just go to collision mask and you set it to full image all of them should say full image okay go quickly through and just make sure that they're all that way in collision masks full image last one collision masks full image okay all right so now this still this does not completely solve our problem we need to get him so that he he will stay lined up with the grid if I play right now and I'm gonna show you this other object I made here what it what its purpose is is to show you the grid on the screen so you see he walks around and but if I turn the grid on hold on for one second please all right now I've got a set here all right I've got an error here let me fix this real quick no I got my problem fixed as you see when he walks around here even with that done here he'll still get stuck and the reason being is again you'll see he doesn't stay stuck to that grid so the next step will get him to stay aligned to that grid so that his origin will always be on one of those red lines okay all right now to do that we are going to make some conditions for him to move in order for him to move we had he has to be aligned to the grid so that's our next step here so I'm gonna go to the key down left I'm gonna zoom out a little bit here so you can see a little bit better what we're doing here this time we're going to use if an expression equals something and we're going to do is going to drag this guy or right above here and then we're going to take all of these that are in this line right here we're going to move them to the side over here so these will only run if whatever expression we put here is true okay so the expression that we're gonna put here let me open this up a little bit and zoom in here and make this a little bit wider here so you can see the whole thing the expression we're going to use this is part of game maker programming language is we're gonna test to see if we are aligned to a particular grid so the expression is place snapped oops snapped and then in parentheses you put basically gonna put the size of your grid now when we're moving left and right we don't really care where he is on the x-axis we only what we're gonna what we want to do is we only want to be able to move left and right if he's on one of the vertical axis if he's on one of the if he is touching one of the bases if he's touching one of the horizontal lines if I play the game this is my back I can't run it right now their game in error so we don't care where it is along the x-axis we just care about where it is on the up and down axis on the y axis so for the x value here we're going to put 0 and then comma and then we're gonna put the word grid and the reason we're using word grid is because that's is in our create event what we set has our grid value our grid is 48 by 48 so that's what we're going to use so what this means if this guy if he is basically anywhere on the on the x axis but he is aligned with the grid he is in some multiple of 48 so 0 48 96 so on and so on this means he's aligned to the vertical grid so if he is aligned to the vertical grid then he can change direction and he can we can set his feed change his sprite and change his animation speed okay so what we have to do now is we have to copy this then we can't just copy this because it'll it'll copy all of this other program we don't want this whole thing we just want this code right here so I'm gonna highlight this and go ctrl C and that's gonna copy it and you know it doesn't let you right-click like some programs do so I'm gonna highlight this I'm the control C again and then I'm going to go to right I'm gonna do right first because it's it's almost exact same program and I'm gonna drag the same thing in if expression drag that in and I've got to just like be just like B on the other one I've got to drag all of these so that they're in line on the left side here okay and then I'm gonna go in zoom in here and I'm gonna change this variable to what I've got in the clipboard I'm gonna paste it so control V V is in victor and it's the same code place snap to 0 0 comma grid it doesn't matter it doesn't if we're going left to right it doesn't matter where we are on the ax we still want to go right what matters is are we at the right vertical position and it'll only work if he's in the right vertical position so let's go to up and do the same thing here let me zoom out add a if expression take it to the top again drag all these to the side and on this case we still have it in the we still have it in the clipboard here so I'm gonna paste this again control V but this time I since I'm going up and down I do care where I am on the x-axis I don't care where I am on the y-axis I don't care where I am vertically I care where I am horizontally because I want to be aligned up with my grid if I want to be able to move up or down so I'm gonna switch these instead of 0 comma grid it's now going to be grid comma 0 like that and I'm going to recopy this because I'm gonna use the same one for down so copy go to down again same thing drag if expression and start putting these all 100 other and we're gonna paste the same thing that was in up is gonna go and down place snapped place snapped and then in parentheses these are regular parentheses not the square ones grid comma zero okay now when we play the game now we play the game you see he if I want to move to the left or right he will only move once I'm aligned to the grid now I'm gonna turn on the grid so you can kind of see it a little bit better see now he sticks on the grid so if I go down this area here it moves very easy through here because he always is lined up with the grid okay alright and now the next thing you might notice is you notice he does not stop in hallways so you might want to get him so that he will stop in a hallway and if you make a game like pac-man if you make some kind of copy of pac-man pac-man if you remember or if you've ever played it he can't stop in a hallway too in order to keep from going too far the player has to you know hit the left and right arrow keys to keep him still so with the next bit of code we're gonna put in is to get it so that he can stop in the middle of the hallway and he'll stop a line to a grid okay so we're we're going to do that is in the it's going to be in a vent called step begin step so at the beginning of every step it's gonna check for your player's position and if nothing else is happening it will stop him so again we're gonna check for an expression here and we're gonna use the same one we used before but this time we do care about its x position and y position because we want this to work either on either way so instead of going 0 grid or grid 0 it's gonna be grid grid here place snapped open parentheses grade grid now it's going to check that it's aligned in both directions okay if that is true then what we want to happen is we want him to stop and we want his animation speed to stop so I'm going to do that I'm going to add that right here movement down here set speed I'm gonna put set speed right here we want to set his speed to zero and we want to set his animation speed to zero as well okay you set that to zero too so now when he will stop in the middle of the grid and evil's his animation will stop as well so you'll see so as he's moving he'll continue to move until he's lined up with a grid and then he'll stop okay so if we hit turn the grid on here see it's a little bit hard to tell when okay so if I go over like right here see he stops in the grid he always stops now we do have an issue with his little legs are spread apart sometimes and not they're not lined up like they should be again most people when they stop walking don't stop with their legs apart like that so we are going to get it we're gonna do another little extra thing here that to make it so that his legs stay come together when he stomps so in this same area here and we have to put it in kind of a weird place because you see here we get him to stop when if we put what I'm gonna put here after this then he will his his legs will skip to the to the first sub image every time he hits a grid line and so we don't want that to happen we want we only wanted to happen we only want his legs to stop moving if his speed is zero so you see his speed is zero turns to zero here so this happens every time but if you're heavy if you're holding down another key we ill his speed will he will have a speed so we want to before we turn the speed off we want to check to see if his speed is already zero if the speed is already zero we're gonna make it we're gonna set his image index to that so this is gonna take a little bit of shuffling around so we're going to go over here to if variable right here we're gonna drag this to the side here and you see that kind of throws everything out of order so we're gonna we gotta drag these below this one so and again at the bottom of it not not at the top of it or not to the side of it I mean so if his speed if if his grid is stopped or if he's if he's lined up with the grid and his speed here this is now we're gonna actually use the word speed because we're checking his actual speed if his speed is equal to zero so if he is stopped then we want to set his image index which is this guy right here said instance variable drag that to the side right there and you see shoots off to the side there and we're gonna the what we want to check is image index that's his sub image is frame and we want that to be zero so now the way you read this and this happens after a couple passes so if you let go of a key let me let me spread this out a little bit so we can get the most real estate out of here we can see and we'll go through this all right all right so what happens is every step it checks to say okay if if you're not pressing any other keys and this say this character is moving to the left then what will happen is every step it'll check okay is that person snap to a grid is he lined up with the grid if he is then it's going to check if it's to zero now when he first gets there his speed will not be zero because he's moving so that it ignores this part and goes down here and then now this is what stops him he will stop his direction will be is his speed will be zero and his animation speed would be zero then the next step around provided nobody's pressed an arrow key or anything it runs through the skin so he is if he is still locked on the place which he will be because he was stopped in the previous step then his speed is now zero so if his speed is zero then it changes his image index to the first friend so now when we play it you'll see he's whenever he stops his legs are always together and you'll see sometimes it even skips a little bit so it gets over there all right now the last bit I want to do here is to make like in a pacman game if you ever played pac-man you know that there's holes in the side here that if he goes out of one side he comes around to the other side so we're gonna that's the next thing we're gonna do to add to this so first thing I wanna do is let's open up that room again and I'm gonna simply just click on a 1 square on each side here so I'm gonna take one out here so again you just click on it hit the Delete key up at the top hit delete down to the bottom now you want to make sure these are lined up so that one needs to be lined up there that one needs to be lined up there if you don't do this then he gets he hits a wall on the outside of the room and you don't ever see him again okay alright so we've done that and then we're gonna go back to the night object and then we're going to now program this so that if he goes off the screen one side he will come back the other side now what we've done this before we've used the outside room event and use the wrap screen but it's in this version of game maker that setup doesn't work as well as it should have as consistently as it should so we're going to use a slightly more complex program that will work all the time so I'm gonna add an event and we're gonna check basically we're going to do is we're going to check our our characters position every step of the game so I go at event step step shrink this down a little bit so I can see more all right so all right so what we're gonna do in this step event we are gonna check our x position or horizontal position where we are left to right so we're gonna use this guy if a variable dragged that in the variable we were checking is our x value and we're gonna see if he is less if his if his x values than zero - grid and the reason I'm doing that is because his origin is on the left side of his body and zero is on the left side of the screen so if his origin hit zero you can still see his body completely in the room so we have to wait till his body is completely 32 and 32 or whatever the grid sizes I think 48 for my game whatever the grid size is we gotta wait till he's that far out of the room before he will we want him to jump to the other side so that's what grid means in this case that's 4 that the equals 48 in my in my game in your game it may be different so if his if his X variable is less than 0 - grid which means he is completely off the screen then we want him to jump to the other side of the screen but all we really want to do is we want to add the room width to his to his position so I'm gonna click here we're in a set variable here and the position we want him to be the what we're changing again if his X is less than the the the he's off the left side of the screen then we want to move his X to the other side of the screen so again the variable we're changing is X and the new value we're going to set here is room width okay room width is just a variable that could that tells you how wide your room is so in our case I think my room is 1008 pixels wide so room width equals 1008 now since again since his origin is on the left side of his body if we moved that origin all the way to the right side of the screen again I'm kind of using this to represent the room if if his exposition is all the way in the right side of screen his body will be off the screen over here somewhere so now I'll demonstrate that again when you get to it so now we've got this one set up so now I'm going to do the opposite basically I'm going to take this and again if I select this one right here and go ctrl C that copies it and then click down below here and go control V again as in Victor then we can you'll see it just duplicates it now this time we're going to give the opposite we're gonna check to see if X is greater than now this time we're just going to reverse these two instead of we're gonna put room with here and 0 minus grid here so I'm gonna go if my value is room is greater than room width then make my x value 0 minus grid okay and that's gonna that's going to create that's gonna make it to work in the other direction so I'm going to paste it one more time here I'm going to I'm going to copy this one again go to the bottom paste it and you'll see now this time we're going to deal with Y and it's going to be this basically the same thing we're gonna check our Y variable okay and we're gonna see if it's less than 0 minus grid since the origin is above him if if his origin is right at the top of the screen he is still completely visible so we want to go 0 minus grid that puts him 1 1 grid spaced out of the room and if he is that then we want to change his Y to room height now in the past people have had problems spelling height hei ght so make sure you spell that right and make sure it's an underscore it's got to be spelled exactly this way okay okay so now again just like we did with X how we did going off the left side then the right side we're gonna do the same thing here we've gone off the way this is dealing with the top then we're going to copy this just copy and then paste down here and we're going to do the bet we're gonna reverse it again we're going to go greater than room height and then if it is greater than room height we're going to change the Y value to 0 minus grid okay now once we've done this now we should be able to test this and see it works my cursor out of the way and you see we get them to the top of the room and there appears at the bottom now let me turn on the grid so you can kind of see what was talking about with the origins see that green across is his orange and so if he's right if his origin is at zero he is still completely visible in the room you can see I'm right there okay so that's why we have to move and we have to wait until he's completely out of the room which is one more cred grid space across and then that makes him jump too you see right there see is at room height right there you can see it's sticking through a little bit there so if we back up if he gets more than that then he jumps to the other side same with the top his origins up at the top and he moves so he's still completing the room when his origins at 0 for y and then so we just bring it up here and you see it you'll see it pop up there okay all right so that is it for this tutorial thank you for your patience I know there's a long one put thank you for sticking with it if you can if you have any problems there's anything you ever I don't understand in any of these videos please let me know in class so that I can help you out okay
Info
Channel: Eric Gallery
Views: 9,836
Rating: undefined out of 5
Keywords: GameMaker, Studio 2, Maze, Pac-Man, Tutorial
Id: eQWArQ0Wo8o
Channel Id: undefined
Length: 48min 11sec (2891 seconds)
Published: Wed Sep 06 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.