welcome back to a new game maker Studio 2 tutorial and in this one we will be creating this snake game that you are seeing with your eyes we can collect apples we can move around like a snake in a retro way like we all love it huh and we can go like teleporting things you know oh boy and let me tell you let's first like this video And subscribe before I throw this pig away through my window I'm giving him the last chance now so be quick I said quick good now that we're done with that intro Let me just tell you real quick again what we will be doing in this tutorial so we got this beautiful snake moving around and we can move with it as well in a retro Nokia game play way you know and um we can go like teleporting from the right wall to the left wall and I will show you everything you have to know to create this in the fastest way possible so stick around would you good now that we have the intro out of the way we're going to start a new project by doing it in the best way possible and you can do that by pressing over here on new new blank and name the project as you want I'm going to name it B sound like3 and choose the folder where you want to save it and then press on let's go congratulations you have made it to the workspace now that you're in a workspace just go to your room one and create the width to be dividable by 32 so let's say like 672 as you can see and the height has to be dividable as well by 32 with no rest good and then just create two Sprites uh for the snake head and one for the body it has to be 32 for the height and 32 for the width the this buddy here the snake head has to be middle Center over here and for that spr body it doesn't matter what it is good and then go to your room one and just drag your snake in and you're going to have to hold uh C all while you're moving him so you can put him straight into this one square doesn't matter which one but just inside of one of those squares good then just save and then check if everything works but pressing run if everything is working we can start with the coding that's the fun part oh yeah actually no boss we before we start with the cating we have to create another Sprite in another object so let's go to spr uh CR Sprite and go to spr spr Apple and then we just do 16 by 16 here you just put 16 apply and then you draw beautiful apple and make sure it hits every corner at least you know looks good looks better and over here just do middle Center that's it assign that to the obj apple and go to ad event create and this is my create event I will just tell you real quick simple what it does it just searches in the room where it should spawn between 32x and um room height room width minus uh 32 and the YX is the same thing pretty much and yeah that's it good and then you go to destroy when it gets destroyed by our snake and I will show you that c is beh that will happen we'll just put that inside of here and that's it boom done good pretty much does only that uh after it gets destroyed it's searches as well again uh we're spawned the science x and y axis and then we just do instance instance create layer so we just create another object of itself obj Apple inside of that layer instances good let's go to our room one and put your Apple inside of there and check if it works press R button oh we didn't do that oh let's do that real quick good r obj snake go to ad event go to uh key press there we go letters and then R for restart and then gamecore restart two brackets and boom semicolon save blate pretty much when we press the R button we just restart the game so we always can see how it looks like good great that works perfectly fine and then go to room one make sure as I said inside of those brackets Apple doesn't matter good good and then we go to obj snake and now we just do the create event for uh obj snake and a step event and that's it pretty much almost there is one more thing we have to do collisions obj apple and then we do inside of here something as well it's very important too let's go first of all to create event for the snake good let me just pick out my coat real quick I know I'm not going to cut this video you're going to watch full whole thing you're going to have fun with me good paste that inside of here this is not important this is only for music you can can do that and just uh create go over here create and uh choose sound and then you will be able to go over here and press over this to choose your file or your M3 whatever and uh just go to your snake again and type inside of here the name of the sound so in my case sound one will work we're going to delete that and just do here two slashes there we go so we create a common so now we just over here have the move speed so pretty much this is 60 60 time 0.2 and you get something right I I don't want to do that the math now and pretty much this the lower the uh the the number here uh the faster our body will move because the move timer gets uh decreased every time when it hit zero our player mooves so you know the closer to zero the better the faster good and the direction of the start will be up straight up du tuity good and the points of the start will obviously be zero and the start body part three you know every single block we got I said three number one is overhead I think I'm not so sure but we will see okay guys now calm down calm down I said good and it's set of your body part we just declare this list uh we just say obj head is zero inside of this list that it pretty much this runs every time until star body part isn't reached so until I isn't three it's one because zero is our head and we don't need to start from zero but from one good this pretty much just uh creates another body um in delay instances obj body as you can see but we're going to do another oh we we forgot to create the object obj buddy maybe somebody already did that congrats little buddy obj body great and go to obj body and just assign a Sprite great you don't have to pull this ins out of here we don't want that go back to room one uh go to back to our obj snake and great now it should work perfectly fine just still doesn't really know uh what obj head is because we don't have obj head we are have obj snake we can call it but obj snake head so you understand a little bit better and name now this snake head great and we're going to copy that and okay no we don't need it that's fine good and obj body great let's save that and now we still do not use those two things but we're going to do that in the step event we're going to have the movement over there good save again great now what we have to do is we have to go step event and do this code no no I'm not going to cut going stay right here here my pig is going to entertain you say something you little prick I said say something okay sorry great good now I already found the code while my pig entang you I hope so right guys good and we're just going to copy paste that and put it right in just like that boom it's a bit cold it's a big code you know it took a little bit time until I didn't copy everything okay pretty much the move timer gets less and less less and this is pretty much the easiest movement you have ever seen we just say um when we press W our image angle will not look will not be if and if it's not uh 180° so what we mean with 180° if it is not looking downwards okay so uh pretty much this is zero if it was um flipped so 90 and then 180 okay so if we're looking down we don't want to go with the snake while we're looking going down immediately up cuz the game it's not like that and it won't really work you will die immediately immediately okay good let's go back to our snake head and so pretty much this is the movement okay and this is just uh a string we say Direction equals uh up okay and if Direction equals up you can say UPS doesn't matter we just say it's up so if the if move timer is zero so if it hits zero finally uh this move timer we got over here it's calculated with our move speed times room speed uh it does the movement once you know every time it gets zero because we at the end just give the move timer to be the same thing as it was at them start good and now what we have to do is we go over here and de clear our position from our B from our snake head we have to do that because the movement won't really work without that so what will happen if we start now will it crash let's see oh this doesn't look good but let me show you why as well but at the end good now that we have that we just have to go over here where is that now um good move timer great so if move timer is zero we say that I'm behind I'm tell you you should go there where I was so I'm pretty much decreasing you once and you autoally brother for some reason as well and you good the next part we have to do is we have to declare this um variable to be our X and our y so we save the position so we know later on uh to save the last position from our head so we can give the position to our uh body parts so pretty much uh every time it hits zero yeah it uh moves once everything uh not everything my head and this is pretty much pretty much the other part so this is all the time good yeah and uh there's not much to go then one more thing to fix as we saw it uh when we start with the game we have this going on we don't want that but at least uh yeah we the apple is not even getting destroyed so pretty much there is one more thing we have to do actually two things buddy how many times did I call you already buddy not even my buddy maybe you are let's see going to do a middle Center okay middle Center save and boom there we go now it's working perfectly fine I hope I didn't say some ass crap at the start like um it doesn't matter but it matters it has to be in the middle good now we can still eat uh the Apple but um you know it's very easy you have to do one little thing and I'm going show you in a bit good so there is one more thing we have actually to do and there that is go to obj uh snake head and um just pretty much at event and go to Collision object obj apple and put this inide up here pretty much we say when we collide with the obj Apple we destroy it with utter you have to see utter because if you don't see utter it will just destroy the obj snake head and Points Plus equal one and we just uh say where each should spawn and that's it let's go good now let's go to eat an apple and we see it decreases one more we get one more body part and what happens if we hit ourself nothing we still have to declare that we still do not have the teleportation now we got the movement good now for the uh death event we just have to go over here here collision with our obj body and we just say instance destroy and boom that's it now we just have to do four teleporters so let's do a real quick sprad okay spr teleporter boom edit image given color as you wish it doesn't matter and then we just go through rooms room one and create a new object real quick obj teleporter Boom Room one and then we just drag the teleporter in oh first of all we got to give them the Sprite now we can do drag the teleporter in let's drag it like that yeah it's fine it's fine good now this is the left teleporter so we got to rename that teleporter left good now let's just duplicate that by pressing C your L uh with D boom boom boom it's just rename that [Music] F2 I'm good now we just have to say when we collide with the right wall we spawn somewhere around over here overhead like like we said uh plus 32 pixels so this is about this and because we have everybody centered this will be perfectly fine good now we go to obj Snakehead and we say collision with the teleporter down so we just have to go over here and do ad event Collision object and then choose each one I'm going to do this real quick again and you just watch good so just pretty much um do this for for the X so when we hit the right wall so this is for the right wall actually just go Collision object right wall [Music] boom actually no uh this is going to be the Collision left wall right so from the left to right getting the same thing for the other ones we go coll Collision object for the right one we just add it and we say 16 boom that's done easy we go uh up we just say up y equals Boom Room height not width and then we go save and then we go Collision objects the upper the bottom one and we say for the bottom one y equal 16 oh wait did we do something up wrong oh whoa whoa whoa no no no no no no no no no no no no this is all right good that was already who oh buddy that's not how it should work good now it works ladies and gentlemen don't forget to do this I hope you didn't skip that and uh I hope I see you in the next one and don't forget to subscribe piggy won't like that at all so there is one extra little thing you can do as well and that is go to draw and go draw and just say [Music] draw [Music] here