Gamemaker DND Platformer Tutorial - #13 Falling Leaves

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 drag-and-drop platformer series last tutorial we added the screen shake which gave those collisions with the enemies a little bit more impact in this tutorial we're going to add an effect that will just make the game feel a little bit more alive we're going to add some leaves that fall from the top of the screen it'll give the game a little bit more atmosphere now if you look in the description you'll find a link to the sprites that are used throughout the series you need to grab that zip file just unzip it into a folder the one we're using is s underscore left or GF so I'm going to drag that in and you'll see there are four frames and it's got a very slow speed over four frames a second now what we want to do here is make sure we set the origin to be the middle Center and close that down and then we're going to make the object for that sprite so create object I'm going to call this o underscore leaf and I'm going to assign the sprite now in order to give to leave some variety I want to change the size of them when they're created and also we can change which direction they're facing just to mix it up a little bit so they don't all look the same so let's add a create event and the first thing I want to do is want to declare a temporary variable and this is what we're going to use to set the size so I'm just going to call it size and I'm going to set it to random underscore range between 0.5 and 1 now with this temporary variable we can then go down and assign it to an instance variable and we're going to assign it to the horizontal scale and then we click plus and we can assign a same thing to the vertical scale so this is going to be sized as the value and size here as well and the reason we're doing it this way is to ensure that the ratio is right for the object we're using the same size value for the horizontal and the vertical now in order to flip it left or right to give it some variety I'm going to use the choose function and drag it in here now we can use choose to randomly pick a value between some set values so I'm going to set the first value to be minus one click the plus and the next one to be one so we're going to use this to say whether the leaf is facing to the right or the left I'm just going to set it to a temporary variable I'm just going to call it facing so when the create event happens facing will be set to either one or minus one size will be set to a value and we're setting it here we also want to time size by facing and that way this minus one or one will be applied to the horizontal scale the horizontal scale which is known by the image underscore XK or keyword is used to scale the object's sprite in the horizontal direction so by default the horizontal scale is 1 so the sprite looks normal if you change the horizontal scale to minus one you can essentially flip the sprite over on its axis which if you recall is what we are doing to the player with its facing variable so if we increase the horizontal scale we stretch the object if we decrease it we shrink the object until it flips over when it becomes less than zero it's also important to note that the flipping occurs on the sprites origin and the last thing I want to do is just add a change to the speed so I'm going to set the vertical speed to be a random range value between say zero point four and one point two so that'll be used just to give some variety in the speed of the how believes the falling great so I set up the initial part of the leaf now I'm going to add a step event and we're going to actually monitor where the leaf is because if the leaf falls beyond the screen limits we need to delete it so remember the leaf is going to be falling down at one point it's going to exit the room size so it's going to exit the bottom of the room and once that happens we don't want the leaf to exist anymore if you don't monitor and destroy instances when they leave your room you could end up having a lot of problems because game maker doesn't care if they're in the room or not it is still drawing them and is still processing the code so you've got to make sure if you don't want the instance anymore you need to delete it so let's run a check here and we'll say if our Y position is greater then the room height well then what we want to do is just destroy the instance great so now we need to spawn the leaves in the room so I'm going to do that in the game object so let's create them under variable definitions I'm going to create some variables that are enable us to create the leaves so I'm going to call the first one spawn leaf initial and this will be set to 30 and this will be the time between each leaf spawning so the next variable I'm going to have is spawn leaf timer and this will just be a timer that counts down when it gets to 0 will create a leaf and we'll set the timer back to the initial time so our game runs at 60 frames a second we're creating a leaf every 30 which means you're creating one every half a second so now we need to go to the step event and we need to create the leaves based on that time so I'm just going to run a script here so I'm going to say execute script and the scripts going to be called SCR Standing a script spawn underscore leaf now I take a copy of that because we need to go and create this script so I right click on scripts say create script and then we'll paste in the name now here's where we actually spawn the leaves so let's drag this bigger so we can see what's happening now we need to look at our timer so record the timer spawn leaf timer and we say if the spawn leaf timer is less than or equal to 0 then we can create the leaf so we need to assign a value and we're going to set the spawn leaf timer and we're going to set the timer back to spawn leaf initial so therefore it'll be another 30 frames before we create another one so now we can create the instance so drag this down we want to create an old leaf object and where do we want to create it well in relation to the X it can be anywhere along the top of the room so let's set this to a random range value between 0 and the room width and in relation to our Y well 0 is the top of the room so we want to spawn it above that so I'm going to set it to minus let's say just 16 so our instance of leaf is going to spawn outside the room and because we have set a vertical speed it's going to start to fall down so lastly we need to set it to a layer let's create a layer called leaves and we'll go do that in a moment now the other thing to look for is if the spawn leaf timer is not less than 0 then we need to take one off this per step so let's go to the else and say if this is not the case let's set spawn leaf timer to whatever it was before minus 1 it's a relative minus 1 now let's go to our room and let's create the leaves just below the enemy so just here click on new instance layer I'm going to click here and press f2 and then I'm gonna call this leaves let's press run and see what that looks like so there we go I've got a leaf falling and they are of different sizes and also they are facing different ways so they should appear below the player and you can drag that leaves layer if you want up above if you'd like above the player and then they will fall in front it's up to you how you want to do that so the next thing to notice is the leaves I want them to fall on the ground and then vanish after certain time at the moment they just fall all the way down the screen and you may want that that may be an effect you're looking for but I'll show you how to make them fall onto the platforms and then disappear so let's go back to our leaves or our leaf object and let's go back to our variable definitions and I'm going to add a time to die here so this is how long left until the leaf will disappear and I'm going to set it to room underscore speed times 5 which is essentially 60 times 5 which is the same as writing 300 so you can do that you can just write the value I'm writing it like this because if for some reason you wanted to change your room speed all you gain timing would be different so if you do it like this the timing won't matter so let's look at a step event now in order for the leaves to interact with the ground we need to do a collision check so we're going to have a look at our if object at place now drag this just above this Y test and we want to look if we're having a collision with a solid and we want to look at our current position so I'm going to check relative on both of these which are not adding any values and if we do find that we have a collision so if we're falling onto a solid we want to stop the object so let's just go and have a look at our set instance variable let's just make this a bit bigger so if we did have a collision let's set our vertical speed to zero so that'll stop moving we also need to stop our animation so I'm going to set our animation speed to be zero and that's so we don't keep cycling through the different frames of the leaf why we're actually on the solid now let's decrease our time to die by one so our time to die we want to set it relative and minus one and that'll take one off at each step now if our time to die is less than zero well then we want to destroy the leaf so let's drag this down and let's say if our time to die is less than or equal to zero then we want to destroy the instance let's try that out so now we should see our leaves falling and they should stop on the platforms and they do and they also stop animating now after five seconds you can see they disappear and you can look at these ones here let's see if they disappear now they kind of pop away you could fade these away and I showed you how to do a fade in the juice section when we looked at fading the explosion so you could add a nice little fade during the time that it's dying and that might be something you want to look at I want to make this a little bit more efficient because if we go back and look at the code the step event here is running every step so this collision is checking every step so even when the object is on the ground we're still checking if we're going to collide an object collision checks are actually pretty intensive and if you're doing a lot of them especially if you've got a lot of leaves or a lot of particles like that that can all add up so let's make a little change here to make it a little bit more efficient and before we run this check I'm gonna run another check and I'm just going to look up here and say what has changed if we are on the ground if we've already checked for this and we're on the ground our vertical speed is actually zero so we don't want to run this if our vertical speed is already zero because we've already done that we've already done the test so let's just check that and say if our vertical speed is zero and if you want to get your vertical speed you can just type V speed that is the same thing as the vertical speed like the variable that game maker knows it as is V speed so if that is not equal to zero well then we want to check if we're actually colliding but if it is equal to zero then we want to decrease the time to die value so instead of putting all of this in here let's select all that with shift right click and say cut and we'll place an else here else just there and let's paste it here under the else that should those three should go under the else so if we consume out a bit and show you that just make this bigger so you can see it so we've got a V speed check we're checking for collision if there is a collision we set our vertical speed to zero and our animation is zero and then we move on down to here but the next step that this comes in these speed will now be equal to zero because we serve it here and our time to die will start to decrease so this is a little more efficient in that we're not running this collision check for leaves that are already on the ground we don't need to check them anymore they've already been checked so let's just run that again and make sure that all works yep so we've got our leaves they're already touching the ground and once again they will disappear after that certain time but they're not running the check anymore now you could add to this if I restart the game with the pressing R you'll see there are no leaves which is kind of odd so you could actually spawn a few random ones in the room before the game starts or at the start of the game just using the random rage and you could do that with something like a repeat so I'm not really going to show you how to do that but I want to say that's something you could work on something you could add yourself so that it looks like the room's already alive and not empty when the game starts so that's all for this tutorial before I go I wanted to mention my patreon supporters I've got a few patreon supporters only but I appreciate those guys and I'm just showing the names on the screen now they're guys who've come in and said look we like the work you're doing and we appreciate that you put some time into it so we are going to reward you for that so if you'd like to do the same you can go over to patreon and just give a few dollars just to help me to do more tutorials like this if that's not something you're interested in but you are interested in doing more GML you can find my GameMaker course on udemy it's currently the highest rated game maker to course on udemy and there's a special coupon code down in the description which you can use to get up to 90% off now that's all for this tutorial I want to thank you for joining me and I'll talk to you in the next one [Music]
Info
Channel: Slyddar
Views: 4,084
Rating: undefined out of 5
Keywords: gamemaker, drag and drop, dnd, collision, platformer, platform, make game, jump on head, enemy ai, gms2, drag n drop, drag, drop, dragndrop, tutorial, peter morgan, one way, oneway, fall, make games, shaun spalding, heartbeast, spalding, yoyo, gms, advanced, learn, vertical, parallax background, parallax, enemy, damage, kill, hurt, mario, jump, damage player, dead state, dust, fx, effects, juice, screen shake, screenshake
Id: d68iuugblnY
Channel Id: undefined
Length: 16min 0sec (960 seconds)
Published: Wed Oct 30 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.