Gamemaker DND Platformer Tutorial - #14 Collectibles

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you're interested in making a detailed platformer just like this one with in game maker using drag-and-drop then keep watching [Music] g'day gamers and welcome back to our dragon drop of a platformer series last tutorial we added some falling leaves to make our game feel more alive in this tutorial I want to add the object that helped define platforming games the collectable item whether it's coins to spend in the shop random pieces of fruit all that sneakily placed hard to get yellow star they are an integral part of a platformer so for our game let's add a queen object for the player to collect so let's get started in the description you'll find a sprites package and you'll be able to download that and unzip it and that will contain the sprites for the project what we're going to drag in is the s underscore coin image so I'm just going to drag it in the game maker and that'll bring the sprite in and I'm going to make sure that we middle Center the origin for the coin now let's also make an object for that so that's our sprite and that's right there I'm going to make a object for that here so right-click create object and we're going to call it o underscore Queen and make sure you assign the sprite so if we look at our room remember with our game we have enemies and the enemies we jump on to destroy so when the player jumps on an enemy then I want some coins to spawn out of the enemy and I want the coins to bounce on the ground and interact without our solid layer so if you remember we have a collision layer and that is where our solids are so I want the coins to bounce onto that so in order for the coins to bounce onto those solids we need our collision code and remember we have a script for our collision code so we can use those so we don't have to rewrite any code and that's the great thing about using your scripts is that other objects can use them now we also might want to create other objects later that also interact with the ground whether it's a heart or something else that falls out and bounces on the ground so because of that reason I'm going to create a parent object so right click create object and I'm just going to call it o underscore item and underscore PA are standing for parent but we want to go down to parent we want to look at the children and we can drag out a coin down here and then that becomes a child of this object and that means any code that we add for the parent is also applied to the child so let's add a step event to the parent and in here I want to run the collision code so let's go to execute script and I'm going to select firstly the calc movement because that will enable the gravity that we applied to the coin and then we'll do a copy in a paste and we'll also select the collision code and that will enable it to bounce off the ground so we've got our calc movement which is working at a gravity and also applying some drag to the coin and then we've got our collision which will unable to interact with the ground now in order to use both of these if I go into them we have a calc movement we're using things like vsp and hate SP in here so if we don't have those variables in the object then we're going to get an error so at the moment this object doesn't know about VSB or HSV we need to give those variables to this object as well so under variable definitions we want to create a HSP variable we're going to create a vsp variable and we also need a drag variable and here I'm going to set this to 0.96 and the drag is how fast it slows down over time when it's moving horizontally so if you remember in our cow move Montera drag gets applied so if we want the coins to appear when the enemy gets jumped on let's go to where we have a player and enemy collision that's right here and at the point where the enemy gets destroyed let's go down and have a look and that happens down here we set the enemy to be in a dead state and we shake the screen so at this point let's spawn some of the coins so I'm going to use the repeat function so I'm going to drag that there and then we're going to use our instance create and how many times are we going to create them well let's do an i random underscore range and this will do an integer random value between two numbers so I'm going to do it between 4 comma 6 so we're going to generate either 4 or 5 or 6 coins at a time now here we want to create the instance so let's select our coin now same thing for the X I'm going to do a random range so let's just do a random underscore range between minus 10 and 10 and that means they won't always spawn at the X of the enemy it'll spawn near the 10 to the left or 10 to the right and make sure you click relative because we're adding this value to our X now for the Y I'm going to use a variable that is built into objects and it's called our B box variable I'm gonna set it to be box top and that means it'll be the top of the mask for the enemy so that'll spawn from the top of the head now we need to put it onto a layer I'm going to create a layer and they're going to call it coin so that's all we need let's go do the coin layer so I'm just gonna put that just directly under the player it's going to create a new layer here I'm gonna click on it and then press f2 and type coin now at the moment when we create the coins they're just going to fall onto the ground because the coins don't have any vertical speed so let's change it so they have some vertical speed when they spawn but let's go to our coin let's get about variable definitions now we are inheriting these three definitions from our parent that's why they're grayed out so if you want to edit them you can actually click this and you can make a change to them I'm going to click this and I'm going to set our HSP so that'll be our horizontal speed to a random range value between -5 and 5 so it means it'll start out either moving to the left or the right or up somewhere between negative 5 and positive 5 now for VSP I'm going to do a similar thing and they're gonna say random underscore range and remember a negative value for our VSP will move us up so I'm going to set it to negative 6 comma negative 3 so we will move up when the object spawns now we've set up quite a lot let's see what it looks like in the game I'm going to press play or f5 now when we jump on an enemy we should see the coin spawning we do and you can see that they move off the center of the enemy and they slow down over time same thing here you get a screen shake and we get the coins spawning looks great so what we need now is a way for the player to collect the coins but let's have a global variable that we can use to keep track of the coins the player is collected so I'm going to go into our game and we're going to go to the variable definitions and here we're going to add a new variable and it's going to call global coins now I'm putting it into a game because this is actually the object that's going to draw the amount of coins later on and I'm making it a global because that enables the player to easily access that variable so now we need a way for the player to pick them up if you look in the sprites folder there is an S coin pickup image that's the animation when the player picks it up so I'm going to drag that in and if you see I've just drawn a little little animation that plays when the player grabs it so make sure you Center the origin and we're going to make an object for this as well so right click create object it's called o underscore coin underscore pick up and we're going to assign the sprite now when I played the animation you might have noticed if I go back to it here you can click on one of these to edit it it's always the like a cross where when it plays so let's give some variety to that let's add a create event let's just go down and set an instance variable here for the rotation so image rotation and let's set it to random and then in brackets are going to put 360 so that way we'll get some variation each time the coin is picked up so the other thing I want to do is add an animation end so it kind of other and get an animation end so when the animation of the coin has played we don't want this object anymore we want it to destroy itself so we're going to say destroy instance and just drag that in so the idea behind collecting in this situation is that we have a coin object and when the player interacts with it it will change itself into an Aucoin pick up instance and then after it plays its animation it'll destroy itself so we need some code in here in the coin for when the player interacts with it so we're going to go to collision and then collision with the player - firstly increment the variable we have and the variable is global coins and we're going to increment it by one relative so that will add one to our total coins and now if you type in change you can actually have a code block that changes this instance into another one and we want to select the coin pick up so this instance will become the coin pick up it'll play and then at the end of this animation it'll destroy itself so let's test that out so it works but you can see there is a problem all the coins get collected as soon as they get as soon as they touch the player so what's happening is they are instantly spawning and then basically being collected by the player so there's no time for them to bounce in the air so let's correct that by allowing them to bounce on the ground first before we can collect them and by adding a bounce to the instances it'll actually make it look a lot better as well so let's go into our item parent and let's have a new variable here and I'm just going to call this bounce I'm going to set it to 3 and bounce it's just a variable that will allow it to actually interact with the ground before it stops bouncing and then we'll use that to determine whether we can pick it up or not so I've added that here and we're going to change the collision script so it accepts it but if we do that we've also got to go and change Oh entity because that also uses the collision script because remember entity is the player in the enemy and they also use the collision script so if we are referring to the bounce variable inside the collision script we've actually got to add it here as well so I'm just going to call it bounce and just set it to 0 so let's go into our collision script and see where we can use this new variable okay so we need to go look at our vertical check which happens down here and we need to see when we are setting our VSP to zero and that's here so at this point here that we want to determine if we should set it to zero or if we should allow the object to bounce so right after we set our collide to be true I'm gonna have a check in here and we're going to say if our bounce variable is greater than zero so if our object still has about bounces left and what we want to do is not set VSP to zero we don't want to stop the object moving vertically down instead what we want to do is set our VSP to be half of itself which means the speed the object will fall and bounce and if it's if it still has a bounce variable greater than zero it'll actually go up and it will only go up half of what the speed is that it's moving down now we also need to set this as a negative because if our VSP is coming down it's a positive value and we want to push it up we want to give it a negative value and the other thing we want to do is look at our bounce variable and we want to decrease it by one so it only has has less bouncers now to do now if this is not true I'm going to put an else in here and if it's not true well then just set VSP to zero we don't want to bounce then it can just stop now this is kind of tricky so I have a look at it what should a few times and you'll see what's happening is we're basically just allowing the bounce to happen and bounce a little bit all we're setting it to zero so now over with our coin and our collision with our player we don't want to allow this to happen if our bounce variable is still a positive so let's look at this let's put pay if check in here and we'll say if our bounce is let's say less than two then we want to allow the change to happen we want to allow the coins to be added and we want to allow the pickup icons or pickup graphic to play so let's test it out press play so now we should have the coins coming out and actually bounce on the ground and then we can collect them same thing here and they actually got a little bounce still and we're still able to collect them because it has we set it to be a less than two that's great so now we need a way to show how many coins have been collected so let's have the OU game object draw that to the view now when drawing information like the amount of coins collected or lives remaining you want the player to see them all the time they should never be hidden by objects over them and for those situations we have a draw GUI event that will draw over top of the drawer event the drawer GUI layer has its own resolution so you can make the quality of what you draw there higher than the actual game is running at so for us let's go to a game and let's add a draw GUI event so an event and the draw due to a GUI now here we can draw the coins and I want to draw the coins up the top left - how many we have so let's create a font to draw with so over here under the resource tree I'm going to right click and say create font now you can choose any font you like to do this with I'm gonna call it firstly FNT underscore coins and I'm gonna choose something that most people on a Windows PC should have as a font I'm just going to use say Bookman bold style and I'm gonna set it to 30 now if you're using a font that's not a common one and unlikely to be on all pcs you can't copy it to the project and that will then copy the font across to the project as well but for us that's fine that should be a font that people on Windows will have so now let's go back to our game and let's have a look at our or draw a GUI event here but firstly I'm gonna get the font so I'm going to set the font and there it is there and I select it and then we're gonna set a draw color oh here I want to set draw color now I'm gonna draw it in a yellow and I'm just gonna pick a yellow color that's to say like that that's fine and now we can actually draw the amount of coins so if you type in draw you'll see there's a draw value and we have a caption so I'm going to write coins there and here's the value on a draw we want to draw a global coins and the position that we want to draw them at now up the top is 0 0 in the game so I'm going to draw it at 22 which is just a little bit in and 11 which is also a little bit down so let's press play and see what that looks like right so it's there and when we collect the coins the value adds up now it looks a little plain so let's dress it up a little bit now we can give it more impact by drawing a shadow now how we draw a shadow is if you think of this value being drawn and we want to have a shadow under it then before we draw this we need to draw a black version of this so if I take that copy and paste and this time the one above we draw in black so for that reason I'm going to actually take a copy of the set draw color as well copy that and paste that below so this one here we want to draw it in a darker color so I'm going to choose black and then change the Alpha value to something low press okay and make sure use alpha is set at true so this will be our shadow and then further down we are then drawing on top of that the yellow version so we need to have a little bit of an offset of the X I'm going to move it left a little bit and just up a little bit but let's try that you should see that the font will now have a small shadow and there it is there it just it makes it stand out a little bit more so one other thing we can do to define it more is actually draw a black rectangle around that area and that will just make that area stand out and define it as the area whether we are showing the information to the player so let's go here and let's set a draw color again let's grab that set another draw color and that's also set say a dark black with an a low alpha and this will be for our rectangle now we want to draw a rectangle drag that here so when we draw the rectangle what we're trying to do is draw a rectangle up the top here where we are then able to display our information so we need four points for the rectangle so when we go back here the left is at zero the top is at zero our right is all the way over here and the position of the right is actually and I'm going to write it out it's actually display get GUI width and this will give us the width of the GUI and the bottom is how far down I'm just going to set it to 55 now we want to fill that in and if we press play there we should get a little rectangle at the top that then we are able to see our values over and that makes it feel a lot better now we're actually seeing an error up here that is defined as the GUI area now the last thing I want to show you is that instead of writing the word coins you can do what most games do and that is to just draw the icon of the sprite that you're collecting so as you can see here I have an icon of the coins and it also has a shadow on it and it just makes it look a lot more professional now if you're interested in how I did that you can head on over to my patreon account that's a bonus video for patreon members only and I'll show you there how to add that to your game speaking of patreon if you want to support me you can head on over there and become a patreon and that enables me to create a lot more content these are my current patrons and I want to give a big shout out to Dylan Jackson who became my first legendary patreon and as a legendary patreon member you get access to all of the bonus content as well as the source code as well as my existing courses and any future courses that I release on udemy so that's the end of this tutorial if you want to create additional items in your game you can use the same structure you just take a copy of the coin object and then you make it into a new object and that way it'll still be a parent of item parent and therefore it'll still bounce on the ground and have all the same properties as the coin you'll just need to have a collision with the player and then you add the new code in there for whatever you want the object to do to the player now don't forget to subscribe and like the video and that helps me to know that you enjoy the content and it also helps me to create more put a comment down below showing what else you'd like me to do and the last thing I'll mention is my game maker course we just had a Black Friday sale and we've had a huge a number of people coming to the course if you're interested in the course it is the highest rated game maker to course on udemy I actually have a section in there where I create a gem and when the gem is collected it explodes into all of these little crystals it's a really cool effect you can check it out on the intro video over on udemy and there's a special coupon code down in the description where you get over 90% off of the course that's all for me right now thanks for joining me I'll talk to you in the next one [Music]
Info
Channel: Slyddar
Views: 5,129
Rating: undefined out of 5
Keywords: gamemaker, platform, platformer, drag, drop, dnd, dragndrop, drag n drop, tutorial, peter morgan, one way, oneway, fall, make games, shaun spalding, heartbeast, spalding, yoyo, gms2, gms, advanced, learn, drag and drop, collision, make game, jump on head, enemy ai, horizontal, collisions, coins, collectible, items, objects, slyddar, peter, morgan, 1.4
Id: OZrbFn-VRn4
Channel Id: undefined
Length: 22min 49sec (1369 seconds)
Published: Thu Dec 05 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.