GameMaker: Studio - Basic Projectiles

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
alright guys welcome back now our ship for our side-scrolling shooter can move around easily enough now we need it to be able to shoot so it can shoot our enemies slay them all Brynn is glorious prizes and points so in order to do this I'm probably gonna split this into two parts first part being just how to make your ship shoot generally and then the second part we'll kind of explore kind of more in depth and sort of show the different kind of options we have for like making it so holding down the button will shoot over times and I'll keep pressing in and I'd you know change how our bullets like move around and shoot and all that kind of thing and so sort of you know a slightly different approach on how we did it last time because last time I just kind of went through everything all once so I'm just gonna kind of split this down into two parts well first of all we just cover the basics and then second second of all for those that are interested we we got a bit more in depth and we add a bit of polish and change things up a bit so on a very basic level then we just want to make our ship shoot every time every time we press say I don't know what button we should use will go with could we'll go with the spacebar I guess baseball works I was gonna say shift but people tend to hate it when you shift and it creates the the sticky keys popup on windows you can disable that but I know some people have a problem with it so we'll go with a spacebar I've already created an object here on my obj underscore bullet which we're going to use for shooing if you don't know anything about objects naming conventions or sprites like that please refer to my very first video on game maker basics because you really should know all this stuff by now so and we already have the bullet up here we have a very very simple sprite that's just like a little blue blue laser and I just want to show you where I put the it's very hard to see on but I put the the origin of this bullet to be this bottom center pixel here because there's only three pixel right sprite so I'll put it dead in the center here because if you remember our origin decides you know the exact coordinates from our object on the screen so putting it here and then place will allow us to sort of you know make sure the bullet isn't sort of inside our ship when when it fires because we're going to create the object like on top of our ship so for the origin right to the bottom of the Lille's of that so now we have this object and we basically need to make a salt every time we press spacebar we create that object that's the very first thing we need to do so if we go into our object player over here and go to add event keyboard our space there we go space although no we don't want space because that will do it every time we hold the object so it would create a laser every single frame that we're holding spacebar and that's definitely not what we want right now so keyboard we want to go to a key press even yeah that's the only one key press space so every time you like the game detects the the space is pressed and it wasn't pressed the frame before meaning you just pressed it so like it's it's it's checking spacebar every frame is same like zero zero zero zero zero and then suddenly it sees one because you've pressed the spacebar and it knows that the frame before was you weren't pressing the spacebar so it triggers a press and it triggers these actions so now if we're working we drag and drop all we need to do is go to create instance and we want to create this our origin on our player should be like in the dead center of the object I think if I remember so x0 seems right I'll take this relative box here so where the coordinate is well related to the player object so and set our object to object bullet our X can be 0 because that means it's going to spawn dead in the center of our player but our Y should be something like I think the object is 32 by 32 so if we type - 26 16 and to that I should create the object Luiza where we want it to be which is sort of just at the top dead center point like at the top here that's why we're looking to make that so as you can see here our origin is sick by 16 so X 0 and -16 should be right here and as we can see from the origin of our bullet origin is at the bottom so I should feel free it just sort of sticking out of the top there so I mean let's see exactly how that one looks so I'll stand a movement and now if we press space you can see I'm starting to create bullets and you can notice the obvious problem the bullets aren't actually going anywhere so that's that's what we'll look into doing next so now that we're creating those objects what we need to do is make it so that when this object is created which if you've been paying attention you already know how to do is go to events and go to create so on our create event when the object is created we need to start this object moving so using drag-and-drop that's simple enough using move fixed stick it direction up and say speed want to be fairly fast I guess so eight okay and then that's pretty much it because we set a speed there so that speed is gonna stay at a so every frame the bullet is gonna move eight pixels up now what we also want to do is make it so we don't infinitely generate these bullets forever and that when they pass over the top of the screen we get rid of them because the game doesn't need them anymore so there are a complete waste of memory at that point so if we go around an event and I think it's other outside room so this event will trigger whenever an object not win any object even whenever this object leaves the room these actions will trigger and then it's simply enough one destroy instance that's the drag and drop anyway I'll show you that one just because it's a single line of code actually if we delete that when we just go to control code and we bring off apparently massive execute code browser up all you need to do here is type instance try trying to be as quiet as possible on my mega loud keyboard probably doesn't come across that way but it is very difficult to be quiet on this thing instance destroy Open bracket close bracket because it's a function without any any arguments to pass over so we just close the brackets instantly and then optionally you don't even need that but like it's cleaner to put a semicolon there just to tell the game that that's the end the line of code tick so then that should work pretty much straight away yep so now every time we press space you're shooting you're shooting some lasers and you can see they're spawning in the right place they're moving up to the top of the screen and then every time they're passing over the top of the screen they go away and they're destroyed and that completely completely removed from the game so yeah that's pretty much how you do that we can change this here we don't need to use an action here we can use a GML instead it's very very simple all you need to do is delete this replace it with code that if you remember from our movement tutorial we just need to set our V speed to be equal to minus 8 because you know we're moving upwards so we're lowering our V position or our y-coordinate sorry so we're moving negatively in vertical direction so we want minus 8 and then that's exactly pretty much the same as what we just did a second ago and so on semicolon there as well okay a pile exactly the same no change so yep that's pretty much pretty much everything you need to know that oh oh in this one as well we can convert this to GML really quickly as well creating the instance again it's just one line of code instance underscore create you can find all of these functions just by hitting them I'll show you this now actually if you just hit f1 you'll bring up the help menu if you go like into the index for example like every single line of code is like every function and everything like that is in here all sorts of information you get from here when you're learning the coding and stuff so I mean you can you can find all of these exact all of these little functions and things that like you obviously I'm just sort of pulling out Noah at the moment you can find them in the whole menu so instance create bracket and then we just type in the coordinates it's already assuming it to be no it's not even what am I talking about I was gonna say it's assuming it to be relative but it's not what we want to do to make it relative so obviously if we type something like 50/50 in here that would put it 50/50 on the screen so what do want it to be relative to our objects but we don't like tick a flag or anything for we just reference the coordinates of the object so we type X which is equal to the cool the x-coordinate of our player object because this is the object to it bringing the kodan so we want it to be our X as we discussed before and we wanted it to be our y coordinate minus 16 so now as you might have guessed Y minus 16 and then the object we want to create is obj underscore call it close bracket semicolon and that's that's simply how you do that then we have five press space exactly the same shooting so yeah in part two we'll go over sort of some more tricks for that because at the moment we're just having we're having to press space every time the fire so I'll go over how to make us so you can hold down spacebar to like continuously shoot like every like 10 frames or something like that I'm going to show you how to like I just the sort of pattern the way it shoots make the bullets wave around if you really needed them to or how to shoot at a specific location you know all those kind of things we'll investigate in more detail in part two of the shooting tutorial which will be shooting advanced I guess and this that is pretty much shooting basics so yeah I hope you enjoyed that I hope you learned something from it and I'll catch you next time guys
Info
Channel: Shaun Spalding
Views: 191,983
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Game Development, Indie Games, Indie, Games, Tutorial, Information, Learning, Tutorial Series, Game Maker Studio, Steam, Windows, Making Games, How to make games, Basics, Projectiles
Id: ehqGwY01roU
Channel Id: undefined
Length: 10min 13sec (613 seconds)
Published: Sun Dec 09 2012
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.