GameMaker Studio 2: Complete Platformer Tutorial (Part 19: Crates & Pickups)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody welcome back before we get started with this week's episode there is a bug that's been prevalent and the latest version is a game maker that I need to warn you all about and you may have already been affected by if you've been following my tutorial err I have been affected by it just by setting up this series and that involves some of you may have noticed rooms disappearing from your game and you haven't and even if you go to rooms and like right-click and add existing and try and sort of add them back the dot YY files back into your game game maker doesn't seem to recognize them as valid files anymore and it just it just loses rooms completely and obviously that's a pretty big deal so you're gonna wonder why that's happening if this is happening to you the reason is because you probably like I did had a signpost from our episode about like three episodes back with a text ring in it that had one of these symbols and at the /n okay so you will have had something like like I had before which was please don't murder anyone slash end for a line-break the park ranger and that was our string before right for this signpost the problem is this variable stuff it all works fine in the object when you edit them but in the room editor when you're editing an instance and this is unfortunate is the most useful version of this when you include this /n in a string it screws with the file that the room saves when you save your project and because it's actually formatted in JSON the every room that gets saved out okay every dot YY like our level one dot y want to get saved out I was like a JSON file problem is that slash and I think also represents like a line break in JSON so it screws with the file format because it literally puts this string in there and then that screws at the formatting with I think a past version of game maker I think that's like the the IDE just before this one so just before two a eight this would just mean you get make it just it wouldn't save it properly a new you wouldn't even be able to bring that room back into game maker so the next time you loaded your project the room would just be gone because you'd included this string now I think that element of it has been fixed but there is still an issue if you do still use this you'll find that when I save and reload this project with that in it it'll come back looking like that in the room edit okay so it'll like truncate the last half for your string which will obviously screw with you if the other and edit that truth is but the data is actually still correct when it comes back looking this way any when you run the game the text will still look fine but you obviously don't want this screwing up in the idea because then when you start to change that it'll then overwrite whatever was there and that's obviously bad so the quickest workaround to this is instead of using this variable window to define specific text for a specific signpost just use the creation code that's why I've done here okay so you click this but we know the bottom of creation code and just type text equals and then the text that you want okay and that'll overwrite all overwrite anything you defined in the variable window for a start so it doesn't matter that this is still here and it'll still work just the same as saying a thing up in this window okay it happens after the create event sikri event happens and then a specific instance creation code happens so this will overwrite anything you defined in the create event as well okay quick home that's a quick workaround to that if you are going to use strings in the room oh just make sure not to use this symbol for now I have been told that this is fixed in the internal dev version that they've got going over area at the moment so when the next version of the IDE comes out hopefully if you check with patch notes for it when it comes out we should be seeing effects for this most likely cool okay sorry that's like the first five minutes this video wasted but it was pretty important to to talk you guys through that all right so we're up to part 19 where we want to go from here we I think honestly we've come a long way and we've covered a lot of stuff we have covered getting your plan to move around got like wielding a weapon if that's the kind of thing you want to do we've got enemies and it's all adding polish to sort of the interactions between firing the gun we've got some signposted displayed like text on the screen and how to do like could see any type things we've got a cameras we've got nice parallax backgrounds we've got moving between different rooms we've got a menu screen and title screen sound effects we've got hopefully I think at this point we've covered most of the bases both in code structure and just general workflow of a game make a project that you should be able to more or less go from here and start doing your own thing start working out what it is you want to make it's not thinking about how you can approach that kind of thing obviously we've not covered everything but I think most of the stuff carrying on in this particular genre of game we're going to be sort of treading over old ground in terms of the code we're actually using but what we're gonna do is I still don't think this game is really finished right so we're going to move towards kind of filling in those gaps of the game's design and just sort of finishing off the project and kind of adding those finishing touches to make it feel like a complete thing so if you are following along we can end this project on something that we can say yeah this is our first complete start to finish game and we can you know make sure we've covered really all of those bases so what are we gonna do today well I'm gonna do some a couple of small things just to sort of set the groundwork for how we want to go on as you've seen I've already kind of redesigned this level this first level and not just because of the book that was killing some of my rooms he can't make but uh because I just don't think more about the designing all this game and because of the way our parallax works obviously our game favors naturally very horizontal levels with a sort of minimal amount of like verticality in life so we don't want Bloods and loads of climbing obviously because then we start to lose the effect that what kind of new nice parallax groans and that kind of thing so I think we're designing a game that's kind of a bit Mario like in that regard it's kind of you know mostly focused and I'm sort of our horizontal kind of progression so I've kind of redesigned it around that kind of flow and what I want to do is I want to introduce the gun mechanic to the player at the beginning of the game I don't want to just draw and drop you in and just be like you've got a gun go I kind of want to add a bit more pacing to it than that so what we're gonna do with this first level is I'm actually going to take the gun away from the player and we're gonna put it on this little pedestal over here and we're gonna block the players path with some crates and the crates that are gonna have to destroy with the gun in order to actually approach seed okay it's a good way to teach a mechanic if you if you if you provide someone with a thing they get thing and then they can't actually progress without using the new thing that they've acquired you still have to be careful with this but it's a it's a good way generally of getting the player to learn a new mechanic okay and so that's what we're gonna do we're gonna we're gonna take the gun away from the player we're gonna create as a little pickup here and we're going to create some crates that you can destroy in here and then both of those mechanics are very reusable and they're nice things to know sort of have to do in code as well all right so the first thing I'm gonna do is just pop onto the gun layer select our gun and delete it you might want to run your game at this point okay just to make sure that everything still works without your gun if you've just been coding everything how we've been coding everything everything should be fine so if I come into the game here yeah I'm fine I just don't have a gun anymore and I just cause I can't shoot I don't even have arms haha I don't think I'm ever gonna change that I think it looks funny with him just running around with no arms when he when he doesn't have the gun but everything else still works you know which is lucky for us that we don't you know we didn't make everything too dependent on dependent on the guns existence depending on what you might have added yourself to the game you've added like a complex weapon system or anything else that's really tied into the gun you might run into some issues where some things I expect some objects you've got my expect the gun to exist when certain things and you'll want to jump into that code and do something like an if a gun exists kind of thing with the code to prevent that kind of book okay we get away with it okay here and you'll notice we do do things sometimes like with a gun and so on one nice thing though when you use the width function so when you do with a player or with Oken etc if that instance doesn't that if in it if there are no instances of that object you don't actually get an error it doesn't crash um it just does that code to nothing I don't think it even runs the code I you can't quote me on how it exactly works internally I think it just skips the code but I think it'll just returns no one the the keyword no one on - for with no instance of that object exists and then the code just doesn't get applied to anything so with is a very useful function in that regard so you don't have to do like if exists every time to be really safe okay so now we've got rid of lying gun what we're gonna do is we're gonna place a gun pickup here that we can just kind of collect so I'm gonna make new object alcohol there press f12 just give some space and call this o gun pickup select sprite that I made earlier just called ask gun one I just decided I didn't want it to be like Horace blue and horizontally exactly the same as my the good news when we hold our just gave it a nice little sort of different different sprite you can draw what have you liked because oops I don't mean to close the workspace all right so with this object what we're gonna do is add the step event and what I'm gonna do is make it float I think that's just a nice a very typical kind of pickup e thing to do right and I'm just gonna write a really simple little chunk of code that will make and I'll get just off float in space by typing y equals y star plus sin get i'ma open bracket close bracket divided by 50 thousand five hundred thousand human sorry multiplied by five and we can just describe this as float I guess here as well so what what what does this do we know where we know what editing a y-coordinate doesn't right that's just moving this on the vertical axis well we're basing we're taking our initial wide addition to wherever we stood and we're gonna add a certain value to it and that value is gonna move between minus 5 and minus 5 so 5 upwards and positive 5 so 5 downwards over time get timer is a useful function it returns the number of any as microseconds that have passed yeah might be wrong though yeah I always get my unit's wrong when it comes to seconds in time that I've passed since the game has started okay obviously there's a million of those in one second so by dividing it by 1 million you would get like you would get a full one from this every full second to the past right where's the 1 by 500,000 we're getting it about 1/2 a so it's like going up to 1 like every half a second or something like that a sign is a special mathematical function if you remember from a trigonometry classes it's really useful if all you really need to know is that it returns a value between 1 and minus 1 in a wave ok depending on the value you put into it between 0 and 2pi right and the peak of the sine graph is obviously 1 and the bottom peak is minus 1 so it's really useful as a function just to get get values that sort of wave back and forth between 1 and minus 1 by just putting in a value that increases over time and this we've gone get time and it can do that for is okay and by dividing my program for a thousand that controls like sort of the time scale with which we want to do that and then buy more applying the final result by 5 we're getting a final result that doesn't wait between 1 and minus 1 which would give us a tiny amount of flow but between 5 and minus 5 that just makes it a little bit bigger so let's just pop that in the room if I just pop into your level 1 on will use the same guns layer and that's fine it'll show up above the player but I soap cakes when we collide with it we're just got to pick it up so I'm just going to run that just so we can see that in action little floating thing you can see there's just sort of bobbing up and down okay I might have to zoom in so you can see more clearly but there we go cool so the other thing we want to do is this is just make it so that when we collide this object with our player we get the gun right so I'm gonna add event collision with a plant Equipe gonna get a description this instance create layer Oh player dot X Oh player dot y on the gun layer make sure it's in quotation marks Oh gun okay that's going to make an instance of a gun on the gun layer we could have even just put a layer in here really but we want to make sure specifically it is on that in case we want to move the layer that this is on later and then we just want to kill this objects instance destroy really really simple and then that'll work well I'd be cool if you're doing your own sound effects as well is to put in a sound here like a check I suppose would have been cool I didn't bother to do it and myself maybe I'll come back and have that later it would be quite good but we pick up the gun and then we've got the gun okay simple stuff it works okay so the next thing I'm gonna do is I'm actually gonna use the fancy workspace shop cut oh oh to create a new object this time whoa look at that created it right away didn't have to click on anything and I'm gonna type oh great it's gonna be the name this object and then set the sprite to be a sprite I made earlier which is s great it's very simple you can make whatever you want whatever you do make though make sure the collision mask stretches to fill the entire box of the sprite that's gonna need a little bit important later and make sure your sprite supports that so it can't be just a weird circle or something like that is good or something it's something that makes sense with a box shape and you'll see why for this particular or gate as we go on I'm right you're gonna put any code in here right away we're gonna inherit all that code from another object but I'm gonna go ahead first of all and place some of these crates in the room at at us I'm just gonna come to the walls layer I think makes sense that's what these are basically going to act as just destructible walls we're not gonna give them any gravity either so you might want to make look something that makes more sense a crate I suppose we're gonna rock or something like that great was just the first thing that came to mind for me for this so were those that when go ahead and close that room at it and now and we're not as I said gonna put anything into okra instead I'm gonna make another new objects present oh-oh I'm gonna call this one tea suitable so what P suitable is gonna do is it's gonna act as a parent object for anything we have in our game that can be shot the reason I'm doing it this way is because we've already done some cool things with our enemy right we've got this cool flash code going on and we track our hit points and that kind of thing and rather than having a duplicate that across all enemies in case we wanted to change how it behaves later makes more sense to just inherit a code like this from from a base parent object okay so what I'm gonna do in OH enemy is I'm actually going to delete in our variable definitions or from the create event if you're in one point X on hit points and flash variable because we just don't actually need them in there anymore or we won't anyway and I'm gonna copy this code from the draw event NP shootable I'm going to define first of all define this object as being the parent off by clicking this plus button next to children make sure you don't click parent or parents that make this the parent of Oh enemy and oh crate okay and then I'm gonna add a draw event and paste that chunk of code in okay and if I come to our enemy now what I can do is actually just delete this drawer event you see it hasn't actually gone away she's turned gray because we have got rid of the enemies drawer event but it's now just inheriting that drawer event straight from this object okay and we can't actually edit it in here but we can edit it in here interests reminder on how parent-child stuff works and the same will be true obviously of a great object it will have that in there as well our enemy has its own way of handling itself dying where it says if it points is less than or equal to zero instance destroy so what I'm gonna do is I'm not gonna I'm not gonna overwrite that event but I am gonna create a begin step in here oh sorry no wrong object I'm going to create a begin step in our P shootable object begins step that just says if H P less than or equal to zero instance destroy just so we have basic code that in case a child of shootable doesn't have anything fancy we want to have happen when this happens okay so you can co-create has inherited this code and Oh enemy has not because our enemy has its own begin step we could write event inherited in here or we could own right-click this and delete it just to get that inheritance back and all sorts of things if we wanted to but we don't want to because we do our own thing with making our corpse and so on for the enemy that we don't want to overwrite okay so that's most of that settle but what we want to do is go into our bullet because as you remember this currently has a collision event with just Oh enemy so what we want to do is change that to be a collision event with P shootable and that will include all of its children so that will include a collision with oak rate as well as Oh enemy the last thing of course we can't forget to do is come back to our piece shootable object go to variable definitions and add back in that hitch p value will set it as a default of four and we'll say flash as zero and you'll notice that that appears as well so if we go to ome again you'll remember this probably from the parenting episode but just to make sure go to variable definitions you'll see hitpoints is in there and we can edit that to be different things if we want and you'll see it's in oak rate as well now there so we can edit those if we want that's fine too you have to do this slightly differently if you're working in one point X but if you got through the parenting episode you can go through this so so we could add it that's nice that's I doubt that for a crate let's give crates five hit points instead okay I'm just so that we've made one of them a little bit different okay once we've done that we've got crates in the room if we run the game now should be more everything for us to run and pick up this gun and see our crates and we can now shoot them they don't disappear in a very exciting way we should probably play some sounds and make them explode and stuff we'll come back to making the explosions of these are they're more polished in a future episode but obviously there's still a problem here and that these don't actually block our path in any way now there is something we should talk about about how we've set this up okay doing things like this where we just add a parent in later on is not exactly the best practice okay not without a more thorough rethink and more thoroughly plan and restructure what you should generally try to do with parents and inheritance is plan these things out more ahead of time okay so we should know that okay our games gonna have a bunch of things that can be shot at maybe we'll want to make a base pair an object for things that can be shot at or vase object for our different enemy types or different walls and that kind of thing and do those things ahead of time and then build your parent objects first and then build everything else outwards wrong there with an understanding of what different things are actually going to be in your game rather than adapting to what you later want in the game and going back and adding things to try and make this stuff work that's not the best practice and that can get your code tied and not we've done that in this instance mostly because that's the nature of tutorials we can cover parent stuff too early on it didn't make sense to so we had to leave that a bit later which meant we had to build this stuff in sort of simpler ways that didn't account for this kind of thing that's just the nature of a tutorial series okay so what I'm just pointing out that what we've done here with people is not the best practice and we're about to see one of the reasons why because what we want to do is make crate collidable right we want to make it so you can walk through this now the most obvious thing a solution for this would be to make this a child of a wall right this is basically I mean this could basically be called P wall this right we can make big assignments an invisible object we basically we use it in the room but fundamentally it's a good idea usually to have a parent object that is just your collidable things and you can make children of all the things that can be collided with but we've already made au crate a child of p shootable instead so how we can't we can't do both and that's obviously an issue with much better planning we could have planned behavior into a wall that could have made certain walls suitable and all that kind of thing that certain walls not collidable and structured this whole thing in a different way but as i said by the nature of how we built this tutorial and how we started off simple and gone gradually more complicated it wasn't really possible to do that in the best best of ways I'm just pointing out so that in future when you are working on your own projects you should know you're gonna run into weird issues like these if we're you kind of have to do little work around you type stuff and start to make your code a little bit Messier if you don't plan out the structure of what you're gonna build some of that's inevitable you can't plan for everything but you should try the best you can to try and think okay what types of objects am I going to need watch they all kind of inherit from want based on get something going to need and just think through the structure of your game project before you just dive in and just start making it all okay it's a very good idea with all that said how are we going to solve this great problem so we can't just make this a child of a wall but what we can do is create a copy of a wall for this particular crate that's gonna be our slightly workaround but fairly reasonable solution to this problem so how are we going to do this in the create event for Oh crate what I'm gonna do is in the description I'm going to call this create war and I'm going to say my wall equals instance create layer X Y layer I just put it on the same layer as this one it's a mare it's invisible and we use the wall therefore these anyway Oh war okay well by doing that we've created a wall object at the place where our craters and we've put its instanceid inside this instance meaning we can destroy it later when the crate gets destroyed okay and that kind of thing what else do we want to do in here we want to affect this wall because I don't notice our walls and actually differently sized to our crates they're 32 by 32 I'll create a 48 by 48 so what we're gonna do is type with my wall open and close brace image X scale equals other dot sprite width divided by sprite width and image y scale equals other dot sprite height divided by sprite height okay while that's gonna do is obviously image scale X scale and is for example 1 means maximum scale and 1.5 means 150% scale etc so by dividing the width of the bigger object which is crate in this case cuz other from inside the wif gives us back our crate right of like 48 sprite with dividing that by the width of the war which is 32 gives us one point something or other right which ends up being the percent by which or the factor by which X scale by width sorry by which the width of the crate is bigger than the Oh wall and by just setting image X scale of the wall to that amount we make the wall the correct size okay you have to be careful with these as well because they date themselves sprite with so after doing image X scale the sprite width of the wall object will actually become 48 there's just something to bear in mind okay because it'll be 32 at the time then it'll become 48 after we adjust our X scale because it takes X scale and Y scale in to account okay if you want to ever get a value that doesn't take those into account you want to do get right or is it it's like sprite get wait for something like that yeah and in class the one and then that gets the width of the actual sprite resource rather than sort of the current sprite width based on image X scale Y scale just something if you don't know later on then the only other thing we want to do in here is add the destroy event and I'd say with my wor instance destroy so that when the crate dies it'll kill the wall and we'll be able to walk through that area of space okay now we'll run this um but there is gonna be a slight problem with this I don't know how evident it will be depending on how the bullets learned but hopefully you'll see it become on pretty clearly okay now this time it's actually worked out pretty well but there is actually a bit of an issue here that can crop up now and again depending on how the bullets land is because we've got a wall and a crate in the same place and that's actually make sure that that worked as well because we didn't actually test what we just did and that you can walk through them but because we've got a wall of that size in the same place just make sure yeah that's working okay and we can walk through cool the exactly the same sizing exactly the same place a bullet has to prioritize one over the other when it lands and so you might find sometimes or if you hit a certain angle just a certain in a certain way sometimes the wall will get hit and the bullet will destroy itself rather than the crate getting hit and the great one taken in damage because we look in Oh bullet we notice we've actually got two different events but it's kind of thing happens okay we've got a collision event with pshew a ball and a begin step where we do place meeting war image or next not equal zero instance destroy okay here weirdly enough when we run it then it be happening it did when I coded this to test but I wasn't happening at all here but that's that's recording for you but we still run the risk of that happening because it's I don't know the event order internally in gaming are quite how if you did in theory I suppose you could make this thing work but rather than try and rely on those ideas let's keep complete control over how these things work in order so that we know exactly what is gonna happen when and we prevent that kind of problem from ever happening so I'm gonna do is I'm gonna copy this chunk of code from the collision with pshew ball and I'm gonna delete this event when we're gonna do is we're gonna do all the collisions parabola in this one begins step rather than sort of splitting off I've become smaller poll ones when we don't know what order that all happens in so before we check for a collision with the wall we're going to do I'm going to paste this code in and I'm gonna do if place meeting X Y he suitable and then instead of doing with other because obviously we're not in a collision event that's not what is that we're not in a collision events that there is no other we want to do it with instance place X Y P sharable which will return the ID of the thing we've just collided with okay because it will do that collision check again and actually get its id place meaning doesn't get the ID you could do if instance place there does not equal no one that kind of thing might be more efficient but this will work and we wanted to okay so and obviously we don't want to just destroy no matter what's and let's fold this inside back collision check as well so your final chunk should look something like that okay so we check for a collision with something that shootable first and then destroy the bullet if that happens and if not then we check for a collision with the wall bank that we do the second means we're never going to end up in a situation with because the crate and the wall overlap where the wall destroys the bullet and it never gets to affect the great okay and that should be all there is to it all right again I mean it seems like fine beforehand but here we just know that we have a bit more control over okay so I just run along grab the gun we can shoot these I can even jump on top of the years it's kind of neat to destroy so it's okay and we go into here says please don't murder anyone the park ranger okay we've lost some of the humor in that joke by not having a bunch of people that you've killed beforehand maybe we'll move that sign later on I don't know but it still makes sense as the intro to the game for me so we have an arrow with no enemies and we're gonna go through let's know what the levels are that moment most of them got lost or that stupid bug but we're gonna make a bunch of those again later but for now we've just got we we just go into this room and then I told us we might look at giving the enemy some weapons that they fight back so our game becomes a little bit less horrible and less about murdering loads of totally innocent people and just about murdering other horrible people with guns that's it's a bit better right so that's something we might have to look forward to but that's all created as a bit more of a bit more of a complete level one so we've got the kind of experience we go you just got us discover this gun you can pick it up we learn how to use it and we shoot our way through here we find the signpost and don't sort of you know for shadows of things to come and we walk through this trigger error and all take us to the next level of our game so that's level one okay thanks for watching this part catch you guys next time on part 20 and probably a couple of weeks and I'll see you then thanks Morgan a huge shout out as always to my patreon supporters without whom I couldn't do any of this awesome work an extra special channel in particular to mark Lin's don't want at been Dan Zephie aflame James Crumm we mark day Cody Hodkinson Rove and Alan Harold Guidry valve nut coat Fisk McTaggart Sam stallion Louis R Pereira Nix lavish Steven Hagen Michael Ward Jason McMillan Vasko Edward Lee CO Shana --then Robert churches oh and Morgan zenon a Bowser the dog TJ and Patrick goofy thank you all so much for your support I'll catch you guys next time
Info
Channel: Shaun Spalding
Views: 58,025
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Tutorial, GameMaker Tutorial, GameMaker, Game Development, Indie Games, Tutorial Series, Game Maker Studio, Making Games, How to make games, GameMaker Studio 2, GMS, GMS2
Id: zrnmegZhLFU
Channel Id: undefined
Length: 33min 14sec (1994 seconds)
Published: Fri May 04 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.