Fire Jump - Part 3: Fire Obstacles - GameMaker Studio 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] greetings and welcome back to fire jump this is the third part my name is aaron craig with let's learn this together and today what we're going to be doing is creating the fire obstacles the way to defeat them and we're gonna be adding in some sound effects as well to make the game a lot more fun to play when we're testing it and going through so if you're not sure what we're doing we are creating an awesome infinite platformer now this is the third part out of four so if you don't know what we're doing and you jumped into this video make sure you go back and start at the beginning otherwise you will have no idea what's going on and get lost very quickly other than that let's go ahead and dive right in so we're going to first bring in the fire sprite that we need so we're going to go down to our sprites and i'm going to right click and i'm going to create a new sprite here i'm going to call this spr underscore fire i'm going to click on import and then i'm going to go to art assets animations and we want the spr fire strip 17. the 17 means that it is going to be an animated sprite made up of 17 frames and i'll click open and voila here's the fire i think it looks really nice it's already animated we don't need to change the speed or anything of that we just need to change the origin to bottom center and then we also need to change the collision mask because we don't want the player to collide with parts of this sprite that aren't actually the fire so we're going to change it from automatic to manual we're going to bring this down to just about where the fire actually is at now depending on how difficult you want to make this game you can increase this for a more difficult challenge or you can decrease it to make it a little bit easier for the player your game your choices next we're going to create an object for our fire so i'm going to open up the objects i'm going to right click create a new object called obj underscore fire big surprise right then we're gonna assign that fire sprite to this and then we're gonna go to parent and we're going to select the move parent that we've been using for everything else because this needs to go down off the screen just like all the other objects that we've been using like the civilians and the windows so along with that we also need to destroy this fire when it gets too low and it's off of the screen so we're going to add an event and this is going to be a step event and now let's search for the if variable block drag it inside of here and what we're looking for is is our y position greater than the room height plus 200. so when this is below the room and it's outside by 200 to make sure that we don't see any of it here because remember the origins bottom center so this is where it's actually looking at the y so we need it to be all the way up and it has a height of 205 but you can see there's a bunch of blank transparent pixels at the top so 200 will be plenty to make sure it's completely outside of the room no longer visible to the player so when we are at the room height plus 200 then we are going to destroy this so i'm just going to search for destroy drag it in here and that's all we need on this object it will get created which we're going to do in just a second we're going to spawn that fire on a windowsill when it gets below the room it gets destroyed the window gets brought back to the top and it continues forever and ever and ever just the way we want and now let's jump over to the window because this is what's going to handle the actual spawning and creation of the fire so obj window and we're going to look in the step event and we have a lot of code here so i'm actually going to go ahead and full screen this and minimize the tab on the right here and remember what we've got inside of here we have one if statement that is creating a random number and then we are moving the window based on that x and y that number that we got there and then we're making another number and that number is actually determining whether we create a civilian or not so we have a minimum of zero a maximum of one and we create a temporary variable called chance and then we set the sprite specifically the sub image for that sprite back to zero because if we have case zero it sets it to 1 which is the civilian window instead of just the closed window so we check to see which number we have from this random number chance that's what this whole switch statement does so this is where we're going to want to add creating the fire so if we add another case i'll just search for case and down here under switch we can add another case by dragging it right here and you'll see that now these are clearly connected but all underneath this one switch statement if i set this to 1 this it will now spawn a fire when it's a 1. but we don't necessarily want it to just be 0 and 1 here at least we don't want this number to only be zero and one because that means that we're either going to have a civilian window or a fire window once we get this set up and those two options don't leave a lot of room for everything else there's not going to be any windows to jump on so i guess maybe if you really wanted a challenging game you could do this but we're gonna change it just a little bit to where this maximum number to three which means that we now have zero one two and three that this number could be so there's a fifty percent chance that we're going to have just a default window that we're not going to change a 25 chance it'll be a civilian and a 25 chance that it's going to be a fire window so let's grab a create instance and drag it right down here underneath the case and what we're going to create is going to be our obj underscore fire and where we want to create that is x y 0 0 but they both need to be relative to the window we're on just like the civilian then we're going to change the layer to spawns because that's where we are spawning things at and lastly we want to change the window because if we go back and we look at spr window the first sub image is for the closed window the second sub image is for the civilian and the third is where we're going to put the fire that we just created so i'll go back to the tab over here and then what we're going to do is we're going to set the sprite so i'm going to search for set and we don't want set global variable instead we want under instances set sprite and we're going to set this to spr window because what we're actually doing is just setting the frame to two and then it will change it to that fire now let's go ahead and run it and we can check it out the fire isn't going to hurt us yet but we should start seeing some fire windows along with the civilian windows and there they are and i think it looks really nice it's a nice animation and you can see it's blended in here just the way we want perfect and so what we're going to do next is actually set up so that when we touch that fire we actually lose the game so for that we're going to need another sprite it's going to be the last sprite that we have for our player so i'm going to right click on the player group and create a new sprite this one is going to be called spr underscore player underscore defeated i'm going to click on import we'll go back just a tiny bit into art assets character whichever one you're using and we're going to grab this sprite right here make sure that you've got middle center on the origin if you didn't already change the preferences like i showed you how and that's all we're going to need for this so how we're going to handle losing the game is by when we touch the fire we're going to remove the player object so that we can no longer move around and instead we're going to create a new object specifically for a defeated player and inside of there we're going to have it react just like how a civilian does when it gets rescued it'll pop up and then it will fall off the screen and when that object is completely off the screen we will restart the game to allow the player another attempt so that means we're going to need another object here so i'm going to right click create object we're going to call this obj underscore player underscore defeated i'm going to drag that defeated sprite onto here and assign it to that and then we're going to add a create event and this is going to be very similar to what we did with the civilian so we're going to search for set speed and what we're doing is looking down here in movement and we want this one right here so we want to set the speed and it's going to be a vertical speed of negative 15 not 155 negative 15 and then we're going to set the gravity force so i'll say set gravity and not global variable instead we want set gravity force right there we're just going to put it to 1 and then that will take care of popping the player up or the defeated player and then pulling them back down below the screen then let's add a step event check to see when we are outside of the room so i'm going to add step event and we're going to check that if variable which is right here so it's actually underneath common we don't even need to search for it so we're going to check y is greater than room height plus 50. and that will check to see when we're outside of the room and that will be plenty enough for us to restart the game and so now the only thing we need to figure out is how and where we're going to create this object for when we lose and the place that makes the most sense is actually in the player object so let's go ahead and open up obj player and add a new event this is going to be a collision event with the fire and now inside of this collision event we're going to create the defeated player and then destroy ourselves and we're going to do that exactly where we're at so the first thing we do is we're going to create another instance so i'm going to drag this inside of here and what we're going to make is obj player defeated and we're going to make it at 0 0 relative to ourselves so it's exactly where we are we're going to put it on the player layer and then search for destroy instance drag it down here now it might look like we're destroying the instance we just created but what it's actually doing is destroying ourselves unless we go in and we specify another instance to destroy destroy instance always is just talking about ourself so let's run the game and check this out because now we should have a pretty full gameplay loop here where we can rescue civilians and when we touch the fire boom we die except we forgot one thing we didn't actually reset the game so let's go back and inside of obj player defeated we're gonna want to restart the game so just search for restart game drag it right here and that's everything we need to do to now when this is outside of the room the game is just going to completely restart and so now let's go ahead and run our game and test it out when we touch the fire we should switch into a new state essentially a death state which is what we want and there we go game restarts exactly the way it should and so that's the core gameplay loop the other way that we can lose though is when we actually miss a ledge and we fall off right now nothing happens except essentially we can no longer do anything because we're just falling indefinitely so what we're gonna do is add a way that we can actually lose when we are outside of the room and since we already have this all set up let's go ahead and right click on obj fire and we're going to duplicate this event but we're going to turn this event into an other an intersect boundary event so essentially if we move off too far to the left or the right or we fall all the way down we will now die and so let's go ahead and run this and check it out so if we go to the left we'll die because we've touched the boundary if we go down we die and if we go too far to the right we die exactly how it should work so duplicating events like this is really handy so if you have one that you know works like when we were doing the key down left and right that would have been one that we could have pretty easily duplicated just showing you another way of being able to quickly and efficiently get your code up and running game maker is great at getting your games working and running quickly one of the really great benefits of working with game maker studio now the next thing we're going to tackle is being able to shoot foam so that we can put out the fires because right now there's really no way of actually getting above those flames so essentially when we encounter one of them uh it's kind of game over unless you've really narrowed that down and made it kind of easy so you could jump on the edges of the fire ledges which could itself be a pretty interesting mechanic but we haven't done that and so we need a way of putting out the fires that we are encountering right above us so now let's go ahead and get that mechanic set up in our game we're going to need a new sprite for that and i'm going to right click on sprites create a new one this one is going to be called spr underscore foam i'm going to click on import art assets and this is going to be an animation so this is going to be foam strip 20. i'm going to bring this in and here's the animation for you it's a little poof of foam that we shoot that's going to go right above us so we can put out fires so we just need to make sure that the origin is in middle center and that's everything we need for the sprite now we need an object for it so that we can create it so i'm going to right click create a new object called obj underscore foam open it up let's drag that sprite inside of there set the parent because we want this to go down just like everything else the difference is we want it to go down after it has already been shot up so we're going to add a create event inside of here and we're going to set the speed when it gets created so not gravity force it's under movement grab the set speed vertical and we're going to give it a value of negative 40. this way it shoots straight up when it gets created and then if this ever goes outside of the room we want to destroy it but the thing is it's a little different than everything else we've been doing all of the other objects we've been using a step event checking the y position of that object if it is outside of the room specifically below the room and that's because a lot of those objects are actually being spawned at the top of the level outside of what we can see and so if we use the event which we're actually going to use right here under other outside room if we used this event on the windows or the civilians or the fires or anything else like that it would trigger even though it's above the room and it's coming down into it so we can't use those there which is why we've been using the step event but for this foam it's actually being made inside of the room and so then time it goes outside of the room we want it gone so let's go ahead and add this event inside and all we're going to do is just destroy it as soon as it's outside of the room and next we need to actually be able to do something with the foam we've got the object made it's ready to go but we can't actually create it so let's go into obj player and we're going to add a new event and this is going to be under key pressed so it's just going to trigger one time each time you press this key and we're going to use the space bar so the space is for the space key the big one on your keyboard and it's just going to trigger every time we do this so what we want to do is create our foam so let's go to instance and we want create instance right here and it's obj underscore foam and we're going to do a relative x0 and y0 and we're going to spawn it on the layer of spawns and we're almost ready to test this out but before we do we actually need to set up the system that when the foam touches the fire it puts out the fire and it destroys itself so let's go into obj fire now and we're going to add a collision event with the foam so collision objects obj foam right here and now what we're going to do in this collision event is drag a destroy instance and another destroy instance so we actually want to destroy the foam we're colliding with and ourselves because we're the fire so i'm going to click on this little arrow and i'm going to select other instead of self and you can see it has kind of a purple border around it now and it says it destroys other on other so this indicates that we are destroying two instances the fire and the foam let's go ahead and run our game because now we have the mechanic to actually put the fires out that we encounter so if we press space right here we create this and it goes up pretty fast and it doesn't come back down because when it goes outside of the room at all it dies and now you can see we can put out these fires just like that so what we're going to tackle next is creating a really cool particle system effect for whenever we put out the fire but we're going to do this a little bit different instead of just using a sprite like we've been using for the fires civilians everything like that we're actually going to use the built-in particle system that game maker studio has and the particle system in game maker is very powerful very flexible and it looks awesome it can be used for so many different things and i'm going to show you just how to use it one way here to create a beautiful particle effect now we are going to have a sprite to help us with that so i'm going to go ahead and right click on sprites create a new one and i'm going to call this one spr fire particle i'm going to click on import and it's going to be the one called spr fire particles strip 17. bring this in here and this is what this looks like for now all we need to do with it is bring the origin down to the bottom center just like we have for everything else we've been using on the windows here now we're going to create an object that's going to manage the creation and the setting of the effects for our particles so i'm going to go to objects right click and create a new object and this is going to be called obj underscore game and i'm going to go into our room and i'm going to create a new instances layer and rename it effects and then i'm going to drag this object into here this one's not going to have a sprite it's not one that we're ever going to see it's going to manage the the effects and the particles that it creates but the object itself as you can see in here it doesn't have a sprite and when you don't have sprites traditionally you take that object and you put it in the top left corner that way you know where they all are oftentimes you can have many objects in your game that don't have sprites things that manage your savings system things that manage your particles your scores all of that sometimes they are huds like this like we have in our game sometimes they are objects in the background and you just want to group them all together so you know where they're at now let's go ahead and open up obj game because inside of here we're going to be working with the particle system and there's a lot to it so we're going to break it down just one step at a time so there's a particle system which actually manages the particles and then there are the particle types there are a lot of different types but what we want is one that looks like fire so let's set up the particle system first because we need the system before we go in and create the particle types so i'm going to add a create event inside of here and i'm just going to search for particle and you can see that they are all right here there's a bunch of particle code blocks here but the one we want is the first one create particle system so we have the layer which we just made called effects so make sure you type that in there we don't want this to be persistent which means that it would stick around and go through room to room we only want it to be in this one room and the target saves the particle system right here inside of a variable and we're going to call this particle system and we do not want it to be temporary so this is going to make a particle system and save it inside of a variable called particle system we're really clever at namings around here next up we're going to have the particle type so we already have all of these right here so now we're looking for particle type what this is actually gonna do is create a blank particle which is basically it's undefined and we're gonna define it later with a bunch of these other code blocks but for now we're going to save this in a variable called fire and we do not want it to be temporary but we do want to blend this together blending is it's an additive blending and you want to use it whenever your particle is one that gives off light fire is something that gives off light so we want to have blending enabled and so now that we have the system and the particle type it's actually time to define what this particle is going to act and look like so there's going to be a lot of options here so i'm going to go ahead and full screen this because we're actually going to use a lot of these so the order here doesn't matter the values are going to create something that i think looks like a pretty good fire effect but i definitely encourage you to experiment and change these around because the more you do that the more you'll actually understand what each one controls how they interact and how to create different kinds of particles inside of gamemaker because you can use them for well really any kind of particle system so think of things like snow and rain and dust and fire all of these can be used with particles and as you play with them you'll make them look better and more realistic for what you want so change it around because remember this is your game so the first one we want is going to be set particle sprite so we're going to have to go through and look at all of these because well there's a bunch here and right over here is the set particle sprite so i'm going to drag this inside of here the type that we want for all of these is going to be the variable that we created so if i type fire you'll see that it says it's a variable because we created it right here and so we're going to set the properties of this particle variable this particle which is referenced by this variable fire we're going to set all of those with what we're doing right now so the type will always be fire then let's find set particle life which is right over here past set particle alpha i'll drag this in here again the type is fire the minimum life is going to be 10 the maximum life is going to be 15. so this is how many frames this is going to last for and it will randomly choose between the minimum and the maximum range then we want particle speed which is actually right after particle life so i'll drag this inside of here type is fire the minimum speed is going to be 2 the maximum speed will be 4. the increase will be negative 0.01 and wiggle is going to stay at zero and so this is going to determine the speed of every particle that gets created and we're going to decrease that speed over time because we want it to be dying because we just put out the fire then we want particle direction which is right after particle speed so i'll drag this in here particle direction the type is fire the minimum direction stays at zero the maximum stays at 360. the increase is one and the wiggle stays at zero so this controls the direction of the particle that gets created we're going to have it be able to move anywhere so 0 to 360 is an entire circle so it can essentially go in every direction and we're going to increase that value by 1 over time that way it gives it some randomness and gives it more like a real life feel next up we want the particle size which is closer to the front here right after destroy so we're going to set the particle size type is fire the minimum size is going to be 0.7 the maximum size will be 1.2 increase is going to be 0.04 and wiggle will stay at zero so this controls the size of the particle between those values and how much is going to increase over its life which is 10 to 15 frames which we've already set so if you add this increase too much it can get really really big so make sure that this one doesn't get too large but again definitely experiment with these different properties that we're setting the last one that we need here is the set particle alpha which is pretty close to the middle right here it's after color and before life so we'll drag particle alpha put it on fire the start will be 1 the middle will be 0.8 and the end is going to be 0. alpha is the transparency so we want it to start fully visible at one in the middle it's starting to go opaque and then by the end it's completely gone so that's a lot of different settings we've created the particle system and then we have completely set how we want this particle called fire to look run and work while it is alive we've also set it for how long it's supposed to be alive and now the last thing we need to do here is make sure that we actually clean up and destroy these particles after they're done because game maker is allocating memory when it creates something new while the game is running such as these particles and if we don't destroy them when they're not needed we can create something called a memory leak which is when we are pulling memory but not releasing it and if you do this too much your game will crash because you only have access to so much memory and if you don't control it and maintain it properly well you get really bad crashes and errors in your game so whenever you make a particle system and a particle just remember to clean it up and we can do that by going back to our particle and there's an event called cleanup so we're going to add that and i'm going to drag this tab into this tab up here so you can do that if you have some tabs outside in the workspace and some in this full screen it can be a little confusing but you can move them between to put them all together which helps and inside here we're just going to search for destroy particle so down here we actually have a destroy particle system and a destroy where is that at particle type so we're going to drag the particle type first because we created it as the system and then the particle so we want to destroy it as the particle and then the system the one we're destroying is fire because remember it's a variable and it's not temporary or local so we can access it in this cleanup event and then we want to destroy the particle system which we can actually see it was called particle system so i'll type out particle underscore system and that actually destroys it and takes care of what we need no memory leaks everything is perfect and so now that we've taken creating and destroying them what we need to actually do is spawning them inside of our game the way we're going to handle that is actually inside of obj fire in the collision event with the foam we need to use a special code block called burst particles and we can put this right down here at the end and we need to be able to access obj game though because that's where the system and the type are located and we can do this without using a global variable because we can actually just say obj underscore game and we can use a period and then we can access the variables inside of that object now if there were multiple game objects we might not know which one we're accessing it would be totally random but because we only have one game object because that's how we've set it up we can do this without worry so we want the particle underscore system and you can see even the autocomplete starts showing it up right there and the type is object fire and that's the name of the type and we're going to have it 0 0 relative and the count is going to be 4. change it to whatever you want to experiment but that's everything we need for that so let's go ahead and give this a try because we've spent a lot of time working on this particle and now i'm excited to see it in action so it'll happen when we collide with the foam in the fire so there we go and i think that looks really really great so that is the particle systems in action inside of game maker they're very versatile really handy and anytime you need any kind of particles just small graphical things that move around randomly and you don't want to draw a sprite for that because you want it to be dynamic and ever-changing particle system is what you want to think about now the last thing for this part is to add in some sound effects because we haven't had any noise inside of our game and it's getting kind of boring sound effects add so much to a game the music the effects everything it brings it to life right now we've got great looking art but without any sounds it feels dead so let's go ahead and fix that let's learn how to work with sounds it's really not that hard it's a new kind of asset though so we have a special group for it sounds i'm going to go and right click create a new sound and the prefix for it is s n d and we're gonna call this game music we're gonna have several different ones that we're bringing in here but we'll start with some game music so to do this we can choose the sound file inside click on this you'll need to jump back out of art assets and actually into the audio assets and the one we want is called sound game music so we'll open this up and then we can preview it this is the sound editor right here so we've got the name the volume the playback controls the position of the music and then we have a bunch of attributes down here which for the most part unless you know you need something changed go ahead and just leave it the way it is so i'll go ahead and press play and we can preview this [Music] and i think it sounds really good it's very fun and we've already heard it before because we played the game in the first part the finished product which had this music in it but now it's time to put it into our game so let's go ahead and open up the obj game object because that's actually going to handle playing the music as well so this is going to be a very versatile object so we're going to open up the create event so what we're going to add in all the way down here is we're going to search for stop all and what we want to do is stop all audio right here and this is just going to stop any music that was playing now right now it doesn't make much sense because we don't have anything else playing but once we get the main menu set up then we'll have audio that carries over and we don't want to have that we want to kill everything else so we want to stop all audio and then we're going to look for play audio and drag that down here so the sound we want is sound game music we only have that one so it's pretty easy to find we do want it to loop which means when it ends it'll go right back to the beginning forever and ever and that's everything we need to do to just play audio in our game and so now if we run this we can actually listen to that audio and we'll hear it inside of our game awesome so now what we need to do is set up the rest of the sound effects for this part so we're going to need five more sound effects so i'm going to click on sounds and i'm going to click plus for creating assets change this to five click sounds and press create so the ones we're going to want are the player jump player defeat player shoot civilian rescue and fire out so we'll go and grab those right now so the first one up here at the top is the civilian rescue so i'll go ahead and open this up and we'll rename this to sound civilian rescue and then we'll go to the next one here which is the fire out rename it to sound fire out and then sound four is going to be sound player defeat sound player defeat sound five is going to be sound player jump sound player jump and lastly is sound player shoot so this is the foam that we're shooting out all right we've got all of these right here and my guess is you probably already have a good idea of where to put these because you already know how to play sound effects and music but i'll go ahead and show you where i'm going to put them and see if we line up on that same page so first one we're going to do is the player sound effects let's go and open up obj player add in a play audio and what we want to search for is sound underscore player shoot so this is when we shoot the foam out and we don't need to loop it and we don't need to have any target here and that's everything we need to do to play that audio now we can do the rest of them as well so when we collide with the window we can go to right down here and just play audio at the bottom sound underscore player jump and then we also have one for when we're defeated but we don't want to put it inside of this object we actually want to go to obj player defeated and in the create event because when it gets made we've touched fire and we've lost so we're going to search for play and we're going to play the sound player defeat sound effect but we also want to stop the game music for just a little bit until the game actually restarts so then let's search for stop and we don't want to stop all audio because it'll actually stop the audio that we just tried to play we want to search for just stop audio and we can pass in that sound game music specifically and it will stop it next we'll go to obj civilian and when we collide with the player anywhere inside of here if we play that sound effect it will work exactly like we need it to so i'm going to look for this play audio drag it in here and we're going to search for sound civilian rescue now there's a lot of code happening here but it all happens nearly simultaneously game maker will go through and check each thing but it's not actually going to play this audio earlier if it was up here it all gets run on the same frame so whether the audio is down here or up here it's going to work exactly the same just make sure it is inside of the if statement and you'll be all set and make sure it's not inside of one of these specific cases because if it is then you'll have a problem where it only plays a sound effect on civilian rescue 0 1 or 2 which is not what you want then let's go to obj fire and in the collision with the foam let's go ahead and play an audio right down here it's going to be sound fire out so this is when it goes all the way out and now let's test the game with all of the sound effects we've got in here because it should sound and look great cool now let's find some fires to put out there we go rescue civilian they're all coming along perfect and we lose exactly what we're looking for so that's how you play audio in game maker not too complex but it does have the ability to loop or just play it one time and you can start and stop specific sounds if you put their name inside of there and so that's the end of part three great job on getting this far don't forget to ask questions if you're stuck and we will help you to the best of our ability in the next part we're going to tackle some really exciting things like how to change rooms sequences creating a menu both for the starting of the game and the end and setting up a high score screen and some ui effects to make our menu a little more fun to look at and interact with i hope you'll join me for the last part where we can finish up fire jump until then keep making keep learning and i'll talk to you later
Info
Channel: GameMaker
Views: 1,691
Rating: undefined out of 5
Keywords: YoYo, Games, YoYo Games, GameMaker, Game Maker Studio, GameMaker Studio, game, maker, GameMaker Studio 2
Id: RkcYgq-FoBg
Channel Id: undefined
Length: 39min 9sec (2349 seconds)
Published: Wed Oct 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.