Basic Space Invaders Clone in GameMaker Studio 2 Drag and Drop [DND]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay in this uh quick tutorial we're gonna make a game which looks something like this where we have a number of enemies in the bottom which are automatically shooting we have a player and the player can shoot back and obviously we got a score counter there which is incremented once um the enemies have been hit and if we look at the player when the player is hit by the enemies uh bullets this score obviously then decrements and it goes back down so this isn't going to be a very complex game it is actually going to be a fairly simple game the graphics in here are obviously going to be very basic but the reason for this tutorial is just to show you some of the basics that uh it can do and to show you how to sort of implement a really basic score counter how to get things working at random and how to get objects moving without user input okay so let's get started so the first thing we're going to do is we're going to create a sprite so i'm going to click my sprite folder right click go to create and then go down to sprite and what we're going to do is going to call this one s player and there are that set so the size of the sprite here is 64 64. i just gonna be quite small not too big um i am on a high resolution screen at the moment so it is going to be fairly sort of small towards the center if you are using a lower resolution screen it'll be bigger i'm leaving it at this by default now what i'm going to do is i'm going to click on edit image and we're actually going to draw our sprite so i'm going to draw a little um sort of alien spacecraft so let me just use some of these tools now if you haven't used uh this before this is a lovely little interface if you've used a gimmicker 8 or anything a little bit newer then you can be fairly familiar with this so what we're going to do is we can start off by using this uh sort of ellipse tool or the circle tool um i'm going to if you notice it's sort of in half so you've got this one here which is a solid fill we've got this one here which is an outline only so i'm going to click on the solid fill here and i'm going to choose a fairly darkish color which is there and i'm just going to draw that out like so okay lovely so that's my start of the base now one of the things that you might have just noticed is in the the right hand corner here this layers property this is really really really useful and i'd encourage you to use this if you are building up uh something within game maker so i'm going to add in a new layer what we're going to do is we're going to make a top now for my little spacecraft and to do that i'm going to click on the ellipse tool again and we're going to go for the outline and i'm going to choose a darker color and i'm just going to draw like so lovely now you look there's a few things with that um if i wanted to move this now i can use my rectangle tool and i can select it and i can then move it and do what i want with it now the downside with this at the moment is it in front of my base so what i'm going to do is click on the layer and just drag it down there you go it's as simple as that now if you wanted to make this um sort of circle a little bit thicker if i just delete this layer what we can do is if i add the layer back in and we click on the ellipse tool you can change the size of the brush at the top here and indeed if you are using a really big canvas you can increase it then manually but what i'm going to do i'm going to make it to 3 and we're going to make this then a little bit bigger so there are it's like that and again i'm going to drag it down there's one last thing i'm going to do once final touch i'm going to click on my paintbrush tool and i'm just going to put in just a few little things here um i'm going to add this onto a new layer and then drag the layer up and then we're just going to add in one two bits and bobs like that there are that's done so i'm happy with this this is my final player i'm gonna close this now and that saves it you can see there that's what it looks like um everything's good so far so let's close that now our player is like a costume it's what we wear so we now need to make an object so because we control the object so if i right click on the object go to create and go to object i'm going to call this o player and what we're gonna then do is select the sprite so click on those break at the moment click on the sprites folder and then click on the s player and that sets the uh sprite so if i close that down now we can add the sprite to the room all right sorry not the sprite the object of the room sorry we add the object to the room so i'm gonna open the rooms folder and double click on room one now by default it has a black background so we're going to change that and to do that i click on the background layer and again we've got layers here in the top left hand corner and by default there i have a color now if i select the color and then select say a uh gray and then click ok that's pretty much ready to go now you'd be tempted just to click on this object and drag it in but you might notice this little x to it now if you did leave it go it just brings up a bit of a warning so what you need to do is you need to create instance layers so it's a really good idea so if you just watch what i'm going to do you to separate things like enemies and players out into different layers so i'm going to click on this here could create instance layer and you can see it's made now instances one so i'm going to right click on that and go to rename and we're going to call as player so all i've done i've typed and president that saves it now what i can do is i can drag my player on and i can dump it i'm dumping it roughly in the center there now if you want to see what this looks like on the top there is a play and if i click on the play it compiles the program for me and this is what our game looks like so far now we can't do anything can't move anything so i'm told it how to move but you see it loads without any sort of problems so that is good in its own right so let's close this and let's get our player to move now to get the player to move what we are going to do is double click on the player object to the old player and we are going to add what's called events now with game maker we have events and then from the events we have something called actions so if i click on add event and then i go down to key down what we are going to program it to do is move when i press the right key it's going to move to the right and when i press the left key it's going to move to the left so i'm going to do the right key first now the way i do the right thing act is going to be slightly different because i'm going to show you two different ways it doesn't matter which way you do it but i'm going to show you two different methods so i'm going to go to the right and what you can see then is we've got an event and then this is the action here now if i just make this a little bit smaller and move this over it'll get more bit on the screen there okay so what we're going to do is drag some things in here because this is what my code is now the easiest way that i always find is if i drag in this assigned variable and what i'm going to say is the x value so the value of x which is uh think of it like a graph you've got an x and y so what i'm basically doing is i'm assigning x a value of five and i'm gonna basically say that's relative now what that means is it keeps on adding five to wherever the x position is now if i play this and hold down the right key you can see now my object moves over towards the right which is good now if i take out this relative just to show you what it does now if i just press the right key watch what happens now to my player it goes over to the left there which is actually position five or five pixels in i think it is something like that so it's not actually do anything i can press the right key as much as i want it's not moving so you need to make sure this relative is checked if you are gonna do it this way now the other alternative is to use something called direction and speed so what i can do is if i go to add event and key down and do left some people prefer to do it like this where we use this direction and they say right we're going left and then they use the speed option and i say speed of five now these two are very very similar right you don't need to do the relative on this one but you will learn this one so these two things do pretty much the same thing there is one difference though if you use this method and i'll show you what you'll need to do now so let's compile the program and if i press the right key it moves to the right if i leave goal it stops if i press the left key and then leave go it keeps on going so what you need to do if you do use this method all right you also need to add in another key down which basically says when there's no key pressed right so when no key is pressed we basically don't do anything now it doesn't matter which one you use there's no real difference between them you can either use the uh x or you can use the direction i think probably for a beginner perspective this is a little easier to understand because you can see where things are going but it really doesn't matter okay so we've got our player moving so let's now add in an enemy so to do this we're going to add in a sprite so i'm about to create right click create and then sprite i'm going to call this one s enemy and again i'm going to go to edit image now for our enemy what i'm gonna do is i'm gonna use a and i use an outline here we're gonna make almost a little delta symbol there you are and i'm gonna add in a shape on the bottom and i'm gonna use the fill tool this time and set the cut to black so we have a little delta symbol there and that's really cool so i'm going to close that and what we then need to do is make an object for our enemy so right click create and then go down to object so we're going to call this o enemy select the enemy here in the sprite this is my enemy ready to go now what i'm going to then do is go back to my room i'm going to create a new instance layer and this time i'm going to right click put a rename and we're going to call it enemy and then i'm just going to add in a few enemies now a quick way of doing this if i drag one in and then hold the alt key down on my keyboard you can see when i press the alt and leave go holding down the alt key and clicking is a really quick way to get um sort of a duplicate to the same object they've put in already okay so i've now put a few of these in and i've lined them up and it doesn't really matter where you put them you can put them close to the cabin space them further apart you can put them at different lengths if you need to it doesn't really matter your choice entirely you do with whatever you're comfortable with okay so we've got our enemies in and we've got our player now if i just play the program again just to make sure everything works there oh yeah doesn't seem to be any issues with this so that's all working really well now what i need to do is get away so that when i press this basic path my little alien here the player can shoot and it can shoot the enemies so to do this we are going to create another sprite so i'm going to right click and i go to create and we're going to click on sprite i'm going to call this s player bullet [Applause] and i'm going to do something a little bit different this time i'm going to change the size of this bullet so i'm going to say another bullet the sprite so i'm going to click on this option here the resize and what we're going to then do is we're going to resize the sprite itself now by default if i do change this the width to say 32 watch what happens to the height when i click and height it also goes down to 32 now the reason for that is we are maintaining our aspect ratio so if i take the tick out of this and then change say the width to 16. you can see now that hasn't updated that hasn't changed and that is essentially what we need so let's apply that and what you're going to see then hopefully the screen recorder can pick this up but you've got a really faint line uh going here so let's click on edit image and we're going to make a really sort of little bullet which is coming down and let me click on that one there the polygon and i'm going to choose a dark color for this it's about roughly center and let's choose another color there yeah that'll do i'm happy with that okay so let's close that and let's now create an object so let me close that let's create right click create object so this time we're going to name this o player bullet don't forget to select sprite and that is that so let's close this and go back to our room now what we want to happen is every time i press say the space bar i want the player to create a bullet which shoots so to do this i'm going to open my player i'm going to add an event and this time we're going to say right when the key is pressed so when the the when the space key is pressed so when the space key is pressed we're going to do something now what we want to do is create an instance now an instance is create like almost like a person right so you want to create one of so you can see here it's a light bulb so if i right i'll just drag that into the main area here you can see it says right create an instance what's the object well the object is going to be the bullet so if i go to object and then go to bullet and then we need to look at this the x and the y right so where do we want to create it this is important because we're creating this in the inside the enemy no sir inside the player we need to make sure it's what's called relative so it's relative to where the player is otherwise what will happen is we don't want the bullet to be created over here if the player is here so we need to make sure that our bullet is created wherever the player is it's going to be placed on the instances layer which is fine we've got one over here and that's now pretty much ready to go so if i just play this just to show you what's going to happen now my game's loaded if i move it over to the right and then press the space as an example every time i press the space it is creating a bullet which is fine but you look these two things you look this way the bullets been made so the bullet's been made in the top left hand corner and the bullets not moving so there's a few really easy things and easy fixes for this so the first thing we need to do let me stop the game running and let me just close all the other windows down for this what we need to do is change the origin of the bullet and the player so i'm going to open the player sprite first and you might have never seen this before but in the top corner here you've got what's called the origin and i'm going to set to the middle center so that's basically where the middle of this sprite is so if you remember when the um when the bullet was made it was always made in the top here so now the bullet's going to be made in the middle and then it'll fly down now if i wanted to i could move it down closer here and that would be fine as well i can open the bullet and what we're going to do with the bullet is we're going to change the origin and i'm going to make the bullet in the top center there now when we play this can you see now what it's done it's made if i just move it there the bullet now has been made right pretty much in the center where i put those origins but it still doesn't move so what we need to do is alter what's called the create event for the bullet so if i double click on the bullet what i'm going to do is i'm going to say add event and then a create so when this object is created what we're going to do is we're going to tell it to move so i'm going to use my fixed direction i'm going to then say right you're going down and then we're going to set the speed and speed is going to be say 10. let's try that okay so let's see what it's going to do lovely so you can see as i move and press the spacebar the bullets are flying down which is good now it's really good practice to remove anything that's outside of the room so as an example when i press this you can see the bullets go in and then it goes off the edge of the room now it's not going to make too much difference in our little program but if you've got a really big program with lots of objects off screen and it can slowly compute to them so what we're going to do is just add something really small which says add event at the outside room so when my object is outside the room we're gonna just destroy it now it's gonna have no effect on the visuals on your game but they will have an effect in the back end of your game so with our basic game so far we've got player movement we've got a firing system and our bullets are going off on their own and obviously they go and then they've been destroyed when they go off screen we needn't set up what's called a collision so when a bullet hits the enemy we need to remove the enemy right so the way we do that it's fairly simple if i go into my enemy and what we do is we say right add event a collision with the bullet so what i basically say is when the bullet hits the enemy then all we're going to do is we're going to destroy that instance so let's try that so let me go above here press that bang gone bang on lovely now we're going to do it slightly different um the other way around and i'll show you what we'll do later when we actually have the enemies firing back so that now has obviously got rid of everything the game still runs we haven't actually told the game how to uh how to actually end so what we're going to do now is you can add score countering right now i'm going to use all the built-in variables because obviously this is a big enough tutorial so i don't want to go too in-depth then so let me close that for a moment and let's go back to our game now what i'm going to do is add in a object so i'm going to right click on object go to create and then go to object and i'm going to call this an o game manager now i tend to use this quite a lot if i'm storing things like scores or if i'm storing lives or health or anything like that so it's almost like an object which needs to be there it's just it it's calculates things for me so what we're going to do is add this into my room now what's what happens when i drag this on now it's going to go my instances layer but when i drag it on because we haven't actually assigned it to sprite it just comes up with a question mark that's absolutely fine it doesn't mean it doesn't work it's absolutely fine so what we are going to add in now is our draw event so i'm gonna do two things i'm gonna click on add event and then i'm gonna go down to draw and we're gonna add in a single draw here okay now under this draw i have this option here in the toolbox called drawing and one of these is called draw value now if i drag this over by default it says right caption so we change this and don't forget this is in speech marks so don't delete the speech marks and you can see i put score in five we're gonna change that a little bit your score is now we've got that so the value is gonna be score now let me explain this here is just a piece of text that there is a variable called score now if i just go back here and start typing it again you can see game makers helps you there's a built-in value called score it's what's called a global variable so you don't need to define it anywhere before you use it now you might have seen in one of my other tutorials i've had to define variables before i use it because score is a built-in variable i don't need to uh define it first right now the x and the y is where we want to position it so the x i'm going to put down as 5 and the wiring of it as 10. now let's just see what that does right when i play hopefully it should come up and say score zero lovely now it's really faint at the back there but you can kind of see his here hopefully the screen recorder is picking it up now what i'm going to do i'm going to change the color of that and i'm going to change the font and the size of it as well now to do that fortunately it's fairly easy on the right hand side here i have a font folder if i right click go to create and then go down to font we're going to call this f score and then presenter and choose a font i don't really mind what fonts you people use as long as it's something that's readable so i'm going to go with something like that and i'm going to go and increase the size so this is going to be 28 that'll be fine so if i close that and let's go back up to my game manager now what we need to do this is a linear program so we need to set the fonts up here now the font settings all done in this red are these red options here so the first thing we're going to do is we're going to set the color and the color is going to be uh black so if i click on that and we'll go for a really dark like a charcoal type color and let's add in the set font option and you can see there look it's currently set to none let's click the drop down list click on the font click on f score and we've also added a text alignment in there as well i probably don't need i don't buy that popped up so i'm gonna get rid of that really quickly so let's click on the play and let's see what that does lovely so you can see now it says my score is zero and you might need to move no it's actually done it's okay so let's do something here now you'll notice it doesn't actually do anything which is a little bit disappointing the reason it doesn't do anything is because we haven't told it to do anything so let's close that let's open my enemy up and you can see we have a collision event with a bullet and all we're telling it to do is destroy the instance so what we need to do is add in this variable and i'm going to put it just before we destroy it and we're going to basically say score is one relative so what that does is every time the bullet hits or when the bullet hits the enemy it's gonna add one to my score and then destroy that instance okay so let's try that now let me just move this over and press the fire button lovely so you can see there now one comes up lovely one more over here excellent lovely so we can see that works our score counter increments all the way up to five which is really really really good that's what i want okay so the next thing we need to look at now is getting our enemy these here uh ideally these need to be firing back at this because obviously we've got a mechanism to score and so we need something now that takes points away so what we're gonna do is we're gonna basically say well if the enemy hits us we're gonna take one point office okay so potentially we're gonna lose a lot of points so let's look at how we can do that so the first thing we're going to do is we're going to create another sprite so right click go to create and then go down to sprite and we're going to call this one s enemy bullet we're gonna do the same sort of thing they did um with the player one now i could if i want to do copy it i'm not it's a good practice do things again so i'm going to take off the aspect ratio we're going to set the width to 16 the height is going to be 32 and then i'm going to click apply we're going to edit the image and this time obviously the bullet is going the other way so let's draw something out really quickly in fact i'm gonna go with a gray with this one wow that is quite difficult to see so we'll add a little bit of a fill in and we'll add this great shaping well we're on the looking bullet okay so let's close that and let's close this workspace we don't need it and let's now create another object so right click on the object go to create and let's call this one o enemy bullet and select the correct sprite lovely so essentially my bullet is going out towards my player i say it's going towards it's not doing anything at the moment so this is what we need to do currently in our room this player will fire a bullet every time we press the spacebar now it's a little bit difficult to do because we have to think of a way to automate this process now the way we do this is we use something called an alarm and an alarm is a process which can occur sort of at a set time think of an alarm clock which wakes you up it'll wake you up at a certain time well alarms are useful in game maker because essentially we can tell it to do something every so many seconds right or every so many minutes and we can also randomize it which is kind of what we're going to be doing so our enemies are going to have alarms now what we're going to do for this first part is on our enemy we need to basically create what's called an alarm so i am going to add in add event go to alarm and it's going to be called alarm0 that's the first one and what i want to do is basically get a random number now if i don't use a random number they'll all fire at the same time right so ideally i don't want to do that let me show you what i mean so i'm going to do for the first part of the chord which is this here create an instance and the instance is going to be the instance is going to be the enemy bullet and i want it to be relative i don't mind if it's on the instances layer it's going to be relative to the enemy which is fine now we also need to make sure our enemy bullet moves upwards so i'm going to add event create and what we're going to do is add that and the speed so we'll do 12 here so the enemy bullet is faster than ours and what we're gonna say is that when the alarm basically runs we're gonna create one of these bullets now in order to run the alarm right we need to basically have a create event and then what we can do is we can use there's a set alarm option here search for set alarm there it is now this will actually only run once right and i'll explain why it'll only run once now so when this enemy is created it'll wait one second before running this alarm and then once it's run the alarm once there's no actual way to reset it so what you really need to do is add this in as well that in there right now watch what happens when we actually play the game so hopefully the screen recorder is picking this up but they're all firing at exactly the same time they're not randomized it's just firing at the same time so what we need to do is stop that and we need to randomize this a little bit all right so i'm going to get rid of this set alarm here and i'm going to go back to my create event and i'm going to get rid of the set alarm here now what we need to do is we need to basically get a random number and there is one here faces with some get is up there's an option here get random number so i want an integer and what we're going to do is we're going to give it a random value from 60 which is sort of one second and between 180 which is obviously three seconds right so what this does then is it basically will generate the random number and we need to give it a target now we're not given a variable target but we are going to say alarm brackets one now i'm going to take a copy of this and i'm going to put in fact no it's not alarm when sorry it's all on zero so i'm going to take a copy of this and i'm going to paste it into alarm one as sorry alarm zero as well now this is a little bit it's not too complex but it's just a little bit of logic you need to get so let's play this lovely so you can see now they're all fire in it different times and some are firing quicker than others which is absolutely fine now you can also randomize the speed the scores if you want i'm not going to do it in this tutorial but you can if you want now the downside of the moment is that when our bullet hits the um player it's not actually doing anything so that's the next thing we're gonna need to look at so let me just stop this running and we are going to open our enemy bullet and what i'm going to say is when the bullet collides also yeah when the brother collides with our player what i need to do is we need to say score and then i'm gonna say minus one relative now there's gonna be a bit of an issue here let me just show you why so once this starts now then as this as the bullet hits the player what's happening is the the score count is going up by more than one because as soon as the bullet touches the player it goes to minus one then it was a little bit further there was a minus two then minus three then minus four and so forth so what we need to do is basically when the bullet hits the player we need to destroy the bullet it'll still minus one but it won't then increase as much as what it has then so if i just go back here and then just put the destroy instance which is this here let's try that let's try it now lovely so you can see now it's only happening one and if we were to fire back at these you can see the uh score and i was incremented back to zero from the minus figure that he was okay so we've got our player working we've got our score counters working quite well and we've got our enemy firing now the only thing you might notice is the um there is a little bit of an offset issue here so we're not firing straight from the um from the player we're actually so from the enemy we're not firing from the tip we're firing from the left hand side easy to start if we open the enemy let's move this origin and we're gonna put it right to the top here let's see i'm gonna do the same here for the uh enemy bullet i'm just going to move this right down here and there that'll solve that a little bit you can have a custom origin you don't have to actually have it to the middle center so forth let's just have a look here well that's perfect just coming straight out and hitting our player there now what we're going to do to make this a little bit more difficult is we want to make these uh move so i'm going to get it to move one way and then get it to move back the other and just keep on going backwards and forwards so to do that we're gonna use another alarm now if i open my enemy what we want is our enemy to move stop then go back the other way stop and then go back the way it was coming so to do this i'm going to create a variable and i'm going to call it enemy speed so i'm going to drag that in we're going to call this enemy speed and i'm going to give the value i'm going to do the value of three all right so it's gonna it's not gonna be too fast but it'll you'll see it move no problem now we then need to basically set the alarm right so we need to tell it to move now i've already used alarm zero don't use alarm zero again so we're gonna use a fresh alarm and it's gonna be called alarm one now because i'm doing this all within one um object i can call my variable i just made so in my alarm what we're going to do is i'm going to say right set the speed and we're going to set the horizontal speed to enemy speed so what happens is this here enemy speed variable is given the value of three and then within this alarm and basically saying look just use whatever enemy speed is and there's a reason for it and i should be right now in a moment now we're gonna start this alarm [Music] so this is a long one fairly quickly so leave a countdown 30 it'll be fine so that's half a second so see what it does lovely so they're all now they're just moving good so we can see the first part that works now what we need to do is get them to move stop and then move back because obviously now they just come off the screen and they're probably sort of over there somewhere so let's open my alarm again and what we're going to do is we're going to use a little piece of logic and whenever you multiply a positive number by a negative number so negative one as an example it really makes a negative number so if we have five multiplied by minus one it makes minus five if we have minus five multiplied by minus one it gives us a positive number so what we're gonna do is we're gonna say enemy speed and then in the value of enemy speed this is where we switch so we say enemy speed multiply by minus one so this little piece of logic here is where we flip enemy speed all right and then what we're going to do is we are going to set the alarm then to run again [Music] so alarm1 and we're going to basically run it every one second now if you want two seconds or something like that it'll be 120 so let's just see this run in see what it does so there are they've moved and they stop and they go back okay so they're now bouncing back and forth and they'll continue to do that until obviously there becomes a time when they don't need to or you stop the program or whatever okay so our game so far i've always been 40 minutes tutorial it's quite a lot we've got quite a lot working we've got a score counter working we've got bullets working we've got enemy bullets working and we've got our objects moving on their own it's looking fairly good now what we need to do is we need to work out really how to sort of end the game a little bit okay so what i'm going to do is in my o game manager um i am going to add in one or two things so i can either add this i could probably add it into a step event but i'm not going to i'm going to add it into a draw gui event so if i click on add draw gy what i'm gonna do is i'm gonna say right is there any instances of the enemy left right are there any instances of the enemy left if there are instances then you know just keep on playing if there's no enemies left then obviously we've shot them all so in my game manager there's option here so that says if instance exists so i'm going to drag that in and what we are going to do again a little bit of logic and we're going to say look if the object enemy does not exist notice i've just ticked this not then we need to do something else right so what are we gonna do well let's create a rectangle so first of all i'm going to add in a color let me just double check what color is my room white okay so my room is white so let's add in a dark color and we need to set it then to be relatively large now the way we do this is the left the top left is gonna be zero i need to go over to the right so the right is gonna be our room width because that's the total width of our room and then the top is going to be zero and the bottom is going to be the room height and we need to make sure that's a fill as well now what i'm gonna then do is i'm gonna have our score displayed prominently so let's instead of now setting the draw color let's set the draw color again to white and then we're going to add a text and then we're going to say your score and then we're just going to say score and what we're going to do put this in the center right so let's say room width divided by two and then room and let's go height divided by two so i should put it right in the center and don't forget because um we've changed we've got a nice little font let's put the font in there as well let's set the font lovely so our font is here after that let's try this out now see if this works okay so i have to be fairly quick on this so i'm just kind of trained lovely so that's destroyed them all obviously the reason why that just went down to three is because there was still a bullet flying towards me and it literally just hit it as my bullet hit there so you can see that's not great because that's off a little bit so um what you can do with this you can play around with the numbers here or if you wanted to center the text there's a text alignment option here so you can tell it where you want to align it i'm not really going to do that too much um or if you wanted to specify um an exact position that you would want this so you could say as an example um where was that 76 you could see where i'm going to say 300 on the y value and so forth okay now the other thing we need to do is we need to have a little bit of a check right um because ideally what we need to do is look at our game and if our if our score counter goes below zero then really what we need to do is restart the game okay so to do this what we are going to do is we are going to use what's called a step event and step without runs sort of every step of the game and what we need to do is basically just check to see um if the score has gone less than zero so if i double click on my player and i click on add event and then we go to step and then step what we can then do is we can basically do a logic test so i'm going to use an if yeah so i'm going to say if the score is less than zero then really i want to restart the game right so i'm gonna look for the restart option if you can't see it just search now you've got two options you need to restart the room where we start the game it doesn't really matter what we're doing for this option but if i do restart room for this all right so i just literally grab this and put it on to be right hand side here now let's see what happens when we run this so okay so i'm gonna shoot one layout my score is now one let's get shocked by this so we lose a point there are so it must go zero and all of a sudden my game crashes and the reason being is now we're in what's called an infinite loop right the issue is the score is now minus one the this has triggered this event here so if the variable is less than one we start wrong and this now is in a constant loop it's just loop and the reason for it is the score never gets reset to zero okay so what we need to do is in my create event for my player so i'm going to add create what we're then going to do is we're going to say right set the variable score ooh scroll set the variable score to zero so every time when we restart the room and the play is created the score will always be reset to zero so there are we got one so let's get shot there are let's get shot again there are so you can see there it's restarting and every time we do get shot it just restarts time time again so that there is it works it's good so just a quick quick recap of this game obviously the graphics aren't brilliant on it um but it's there just to show you and proper point we've got our player which can move left and right player can shoot on demand and our enemies are moving on their own back and forth and they are shooting at random order we've got a score counter which is working we've got a method to end the game as well the only thing that we haven't done is essentially when the game ends so when we clear all of the enemies we can then obviously restart the game as well now we could do um let's put a little logic into say that when we press the enter key and if we start obviously you can do that on your own if you want to play with it if you've got any comments please leave them in the box below or if you've got any questions i will try my best to answer them
Info
Channel: A bit of everything
Views: 71
Rating: undefined out of 5
Keywords:
Id: m8f-qVTxnO0
Channel Id: undefined
Length: 49min 19sec (2959 seconds)
Published: Thu Aug 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.