How To Make A Space Shooter Game In Godot 4 (Complete Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there friends in this tutorial series we're gonna build a space shooter game in Godot 4. we're gonna create a player controller that can move around and shoot lasers we're gonna create two different types of enemies and an enemy spawner we will keep track of the score and the high score we're also going to create a cool looking scrolling background effect using those Parallax background node there's more that we're gonna cover so let's get right into it okay create a new project and let's start building this game first we're gonna create the game scene this is going to be a 2d scene we're going to rename this to be the game and let's save this and I want my scenes inside a folder called scenes so I'm going to create a new folder here and save my scene in there next up let's set this scene to be the main scene to do that we can just simply Run the game and pick the select current option here this will make the game scene the main scene and as you can see we have a blank window here I want this game to be like a mobile game so I want the window size to be like this so let's go into the project settings and fix that we need to go into the window tab here under display and we're going to set the viewport width to be 540 and the height to be 960. I also want the stretch mode to be canvas items okay now if we run the game we have this mobile like aspect ratio which I want great next up we're going to create a script here and I'm going to create some testing functionality to make our lives easier okay so let's first create the script I want my script inside another folder and this will be the scripts folder let's create one here and let's create the script and in here first I'm gonna go into the project settings again to the input map here and create a couple of input actions the first one is going to be quits and the second one is going to be reset I will assign the Escape key to quit and the r key to reset we're going to use this inside of the game script inside of the process function we're gonna do a check for the quit and if the quit action is pressed we simply want to quit the game so we're gonna say get three quit else if the reset action is pressed we want to reload the current scene so this is just so that we can test the game a little bit faster when I press escape the game will quit just like here so I'm going to press escape the game quits and when I press R the game will basically reload the current scene which we can't test yet because our scene is empty so to fix that let's start creating the player we need to create a new scene for the player so let's do that the root node is going to be a character body 2D we're going to rename this to be the player and save this scene inside of our scenes folder in here I'm going to create a Sprite 2D and the Collision polygon 2D for this Sprite we're going to use a texture so let's go ahead and import our assets I have some assets here that I prepared these are from Kenny there's a link in the description if you want to use the same ones let's drag these into the game here and as you can see I have audio fonts and textures I'm gonna take a look inside of the textures so this playership one dot PNG is the one that I want to use for the player so let's drag this into the texture slot and this looks okay let's instance the player inside of the game scene to get an understanding of the size of the player I'm gonna put it at the bottom here and Run the game it looks good but it's a little too large in my opinion so let's go back to the player scene and let's set the scale of the Sprite to be Point um 0.7 maybe let's run the game again I think this looks nicer we can change this in the future if we don't like it but for now I'm just gonna go with this and now let's create the Collision polygon I'm going to click on it pick the create points tool here and start creating the shape we don't need to be perfect I just want to roughly get the shape of the player here I usually use a collision shape instead of a polygon but for this I'm feeling like creating a little bit fancier you know a collision shape that is a little bit fancier so this will do and we also want to create a script here but before we do that let's click on the character body and I'm gonna set the motion mode to be floating instead of grounded so grounded is for platformer like controls and floating is for top down stuff which is what we have now we can create the script this needs to be inside of the scripts folder and in here we're gonna make the player move so to do that first let's create some input actions we're gonna have four different actions move right move left move up and move down we're also going to have a shoot action in the future so thinking ahead let's also create this one right is going to be the D key left is going to be the a key up is going to be W and down is going to be S feel free to use different Keys these are just the keys that I like shoot is going to be space for me okay now we can use these input actions and to make the player move we're going to use the physics process function because the player is a character body and character body is a physics object in video and when you want to make physics objects move you need to use physics process instead of just regular process here first we want to get the direction that we want to move in so we're going to create a Direction variable here and this is going to be a vector 2. so let's set this to be a vector 2. and for the X and the Y we're going to use a function called input dot get access this takes in two input actions as strings the first one is going to be the negative one in our case move left the second one is going to be the positive one which is move right in this case we're going to do this again for the Y component of the vector 2. and this time we're going to use move up and down instead of move left and right and move up is going to be the negative one because as you know in Godot up is negative in the y-axis and this line here will basically give us the direction based on which key is being pressed okay I'm now going to explain this in further detail but first let's print it to see what this looks like I'm gonna run the game by default we're getting zero zero if I press W we're going to get 0 negative one if I press s we get 0 1 and if I press a we get negative one zero if I press D we get 1 0 and I can also press them at the same time as well okay so what is going on here input.getaxis returns negative one if the first argument is pressed the negative one in this case move left and it returns positive one if the second one is pressed so we're taking advantage of that and we're creating this Vector 2 here called Direction now we can use this direction to set the velocity of the character body so we're going to say velocity equals Direction and then we also need to do a call to move and slide to make the character body actually move if you don't call this this wouldn't work but of course Direction by itself isn't enough to make the player move at a considerable speed so we're going to create another variable here called speed and that's going to be up here I'm going to set this to be 300 and let's also make this an export variable so now we're getting the direction and we're multiplying it by speed to set the velocity and then recalling move and slide which will use the velocity and make the player move okay let's give this a shot now as you can see when I press up the place goes up and down left right okay great so we don't have to print the direction anymore this is working and finally I want to get a reference to the player from the game script and to do that I'm gonna go into the player node here go to the Note Tab next to the inspector groups and in here I'm going to add the player to a group called player now I'm going to go back to the game script and inside of here I'm going to create the ready function I'm also going to create a variable up here called player and let's set this to be null and at the start of the game inside of the ready function here I'm going to say player equals get tree get first noding group and this will take in a group name and I'm going to say player here so this call Will basically look at all the nodes in the game and find the ones that have the group Player and return the first one in our case we're only going to have a single player at any given time so this will always return the player to us I usually don't do it this way I usually just go in the game scene here inside of the script I usually just create a variable up here like onreadyivar player and just set the player to be like this but this is also an alternative way to get the player so this is just a different way of doing the same thing basically and we could also say assert player isn't null and this assert will basically create an error if the player is not found basically and as a final thing we can go back inside of the game scene here we can create a marker node here and I'm gonna rename this to be the spawn position player spawn position and I'm gonna put this at the center here so let's say the X position is 270 and Y is 850. and then we can use this inside of the game script to set the player's position so even if we had the player somewhere in like stupid in the scene like here we can automatically set it to be at the spawn position at the start here by first creating a reference to the spawn position and then after we get the player we can simply say player.globalposition equals players spawn position dot Global position now if I run the game even though the player is up here it's gonna start here so that's just the cautionary measure to make sure we start the player at the position that we want okay great so we have the game scene we did some setup we also created the player scene and also we created the player's movement code if you found this video helpful please leave a like comment and subscribe if you want to learn more about Godot I have a course for beginners where I teach everything you need to know in a much slower pace so if that's interesting to you check the link in the description thank you for watching I will see you in the next one Hello friends in this video we're going to create the laser scene and shoot it from the player in the end it's gonna look like this I can hold down the spacebar and the player is shooting lasers let's get started the laser is going to be a new scene so let's create one this is going to be an area 2D because we simply want to detect when a laser touches something else and then area 2D is the perfect use case for this I'm gonna rename this to be a laser and save this inside of the scenes folder next I'm going to create a Sprite 2D here and the Collision shape for the Sprite we're going to use this texture that I have called laserred.png and by default it's probably going to be too large but let's see I'm actually gonna instance a player here so that we can see the laser next to the player and it doesn't look too bad but still I want to make it a little smaller so maybe let's go for 0.8 in the scale let's move it down ah I think it looks fine I'm gonna get rid of the player and let's create the Collision shape so this can be either a rectangle or a capsule let's go with a capsule it is a nicer shape I think and that looks fine we also want to create a visibility visible on screen Notifier here so that we can delete the laser when it goes outside of the screen and we can put this at the end here I'm gonna make it a little smaller we'll put it at the bottom here a little bit below the end of the laser so that it gets deleted just a little bit after the Sprite and the Collision shape exit exits the screen okay next up we need to create the script to create some functionality here let's put this inside of the scripts folder and let's create this script inside of here we're not going to do anything complicated we're going to make this move so we need to bring physics process back and in here we're just going to access the global position because this isn't a character body this is an area 2D so we don't have the convenient move and slide function we need to access the position manually like this and in this case we're only interested in the Y component here because we want this to move up we don't care about the right and the left directions we're going to add this each frame a speed which we're going to create and we're going to multiply this by Delta because we're trying to add something each frame and to make that frame rate independent we need to multiply it by Delta and this speed is going to be negative because up Indo is negative and in this case laser will go up let's create the export variable speed and let's set this to be hmm so the player moves at 300 so this should at least be 600 I think and even this might not be enough we'll see okay so this should be enough to make it go up so before we start spawning this from the player let's go to the game scene and let's instance a laser here and let's put it at the bottom and let's run the game yes we can see that it is going up that is all good now we can think about instancing the laser scene from the player or first we can use the visible on-screen Notifier that we created here what we're going to do is we're going to click on it take a look at its signals it has the screen exited signal which is emitted when this visibility Notifier exits the screen we're going to connect this signal to the laser script so when the laser exits the screen we don't need it anymore so we can just call Q3 and this will take care of the lasers that we shoot and miss the target okay now we can go to the player scene and in here we're gonna spawn the laser when the shoot input action is pressed I'm going to create a marker 2D here to I'm going to call this muzzle and this is gonna represent the point that the player shoots the laser from we're gonna use the global position of this basically and inside of the script I'm going to create a variable to hold the laser scene and we're going to pre-load the packed scene here laser.tscn we're going to create a function called Shoot and in this function we're going to shoot the laser in fact we're actually not going to do that we're going to create a signal up here called laser shot and we're just going to emit the signal here because if we instance the laser here inside of the player and add it as a child of the player then the position of the laser will be affected by the player and we don't want that what we're going to do is we're going to create this signal emitted when the shoot action is pressed and then in the game script we're going to connect this signal and instance the laser there and add it as a child of the game scene okay so I'm gonna bring the process function here because this is in a physics thing that we're doing so we don't need to use physics process we can just do this inside of regular process and in here we're going to do a check for this action just press shoot so when the shoot action is pressed in this case the space bar we're just going to call the shoot function that we created and in here let's do a few things actually Let's see we can either instance the laser here and send the instance with the signal or we can just send the pre-loaded packed scene with the signal and then we can instance it inside of the game script let's do it that way so this signal will actually take the laser scene and the location that we want to put this laser on an in-shoot we can simply say laser shot which is the signal dot emit and then we need to give the arguments the first one is going to be the laser scene that we pre-loaded here the second one is going to be the position in this case we're going to give the position of the muzzle so let's quickly create a reference to it up here and down here we can just say muzzle.global position and the shoot function is basically complete we're basically emitting the signal and we're passing the laser scene and the position of the muzzle the global position of the muzzle now we need to go to the game scene and we can either connect the signal from the inspector or we can just do it inside of our script here because we already have a nice reference to the player here so why not connect the signal in here as well I'm going to say player dot laser shot dot connect and we're going to connect this to on player laser shot of course we need to create this function which I'm going to do down here and this will take in the laser scene and the location so we are being past these remember we gave it to the signal here and now we're getting it back and in here we can simply create a new instance of the laser by saying laser scene dot instantiate I hope I spelled that right then we need to use the global position set that to the location that we got passed and finally we can add this laser as a child and instead of adding it as a child of the game I'm going to create a new node here this is going to be a node 2D called laser container so that it is all nice and tidy inside of our main game scene let's create a reference to this and we can simply say lasercontainer.ad child laser let's try this and see when I click space a new laser is instanced and everything seems to be working let's take a look at the remote tab this will show us the running game and inside of the running game we shouldn't have any lasers and we don't good that means the lasers that went outside of the screen got deleted and we can see that in action here if I start shooting you can see that we have some lasers but they immediately disappear because they're being deleted great so a small little recap inside of the player well first we created the laser scene obviously and area 2D we have the visible on-screen Notifier to delete it when it goes out and in the physics process we're simply making it go up in the y-axis the speed seems to be fine as well at 600 so this is the laser scene then we went to the player scene to the player script we created the muzzle first and then we have the laser scene here as a preload variable this can also be in the game scene the game script I mean but this is the way we decided to do it we have a signal called laser shot which takes in a scene and a location which is a position 2D we're checking for the shoot action that we created in the previous lecture and when the shoot action is pressed we're calling the shoot function which simply emits the laser shot signal here and passes in the laser scene and the position of the muzzle finally inside of the game script we connected the player's laser shots signal to a function that we created here and in here we're simply instancing the laser scene that we were passed we're setting the position to the position that we were passed in and finally we're adding it as a child of the laser container everything is good finally I want to make it so that we can hold down the space bar and keep shooting because with this setup we need to keep clicking keep pressing the space barge to shoot and I don't like that I like to hold it down hold the space bar down and keep shooting so that's going to be very simple to do actually we just need to create a variable here called Shoot cooldown I'm going to say CD for short and we're going to set this to be false at first so this is going to be a Boolean when we press the shoot action we're simply going to check if should cool down it's false which I'm gonna say not should cooldown which means The Shield cooldown is false we're gonna shoot but before that we're gonna set the Shoot cooldown To Be True and after we shoot we can just use the weight keyword create a timer here with get recreate timer and let's set the timer to be like point two five and we need to wait for its timeout signal so this will basically turn this function into a core routine what this means is and after this I'm going to set the shoot cooldown to be false what this means is we're gonna when we press the shoot action we're going to set the shoot CD to be true shoot and then we're gonna wait for 0.25 seconds and then we're going to set the shoot cooldown to be false again so until this await is done we're not going to get into this if statement because the shoot cooldown will be true we also need to change the is action just pressed to is action pressed because just pressed only checks the action once when you press it but is action pressed we'll keep checking it as long as you have it pressed okay let's try this out I'm gonna hold the spacebar down and as you can see I'm shooting and when I let it go I stop shooting and you can play with this 0.25 here to achieve different effects for example if you set this to be 0.1 we're gonna really fire rapidly as you can see we can actually make this a variable as well we can say rate of fire here which is going to be an export variable as well up here and we're going to set this to be 0.25 okay so this is going to be it for this lecture now we have a laser scene and we're shooting that laser scene from the player and everything is looking good if this video was helpful please leave a like comment and subscribe if you want to learn to do I have a course where I teach this stuff in a much more slower pace for beginners so be sure to check that out there's a link in the description again thank you for watching I will see you in the next one welcome back friends in this video we're going to create the enemy scene in the end we're going to have this enemy that goes down and we can shoot it with our laser let's get started okay so the enemy scene is going to be very similar to the laser scene so let's create a new scene first and we're gonna make this an area 2D just like the laser but this one we're gonna rename it to be the enemy let's save it inside of our scenes folder and in here we're gonna have a Sprite 2D and a collision shape 2D for the player we use the Collision polygon this one I'm gonna go with the simpler option which is a shape but feel free to create a polygon for this as well for this Sprite we're going to use the spaceship one PNG that we have I have a bunch of these I'm just going to use the first one let's click on the inspector first and let's drag this here it is a bit too large probably just like the player let's go into the game scene and let's instance one of these and next to the player it does look a bit too large so inside of the enemy scene let's set the scale to be 0.65 let's say and let's take a look at it and that looks fine okay so the enemy just like the laser needs a visible on-screen Notifier but it is going to be on the opposite side because this one will be going down instead of going up I'm gonna put this at the back just like laser so that we have a little bit of lag between the time this goes outside of the screen and the thing gets deleted let's also not forget to create a shape here I'm just going to create a circle this looks fine and we of course need to create a script here let's put this inside of the scripts folder that's created and in here we're going to make this go down so let's create the physics process function we need to access the Y property of the global position just like we did for the laser in fact we can copy this and use this and it will work but in this case we don't want to say negative speed because we are going in the opposite direction let's create the export variable speed here as well and let's set this to be like 150 so this is going to be slower than the player okay with this much the ship should be going down if we run the game and as you can see it is but we can't really shoot it so let's work on that okay we need to start creating the interaction between the laser and the enemy and the enemy and the player because we also want the player to die when an enemy touches the player I'm gonna go into the project settings scroll down and go into the 2D physics section here underneath layer names in here we're going to create some Physics layers the first one is going to be the player second one the enemy and the third one is going to be the laser and we're gonna go into the each scene starting with the player click on the character body and set the Collision layer to be the first one which it is by default and this will look for not for the player mask but for the enemy so because the enemy won't be shooting lasers we don't need to check for laser but if in the future we decided to check for the laser as well we'll also check this one okay so that's the player scene let's go into the laser area 2D here into the Collision options this will be on the third layer and the laser will look for the enemy and finally let's go to the enemy Collision here and this will be on layer 2 which is the enemy layer and this will check for the player and also the laser okay so we have the physics layers configured the second step is going to be detecting the Collision between the laser and the enemy and because we made these area 2DS that's going to be extremely simple we just need to decide do we want to check that in the laser script or the enemy script so I'm gonna do this in the laser script to check for the laser hitting the enemy and then we'll do the enemy hitting the player inside of the enemy scene enemy script so inside of laser here we're gonna go and check the signals and we have an area entered signal here we can simply connect this to the laser script and we know that the only area the laser is going to interact with will be the enemy but just for you know some extra checking we can go into the enemy script first and add a class name here and set this to be enemy with a capital E this lets us go into here and say if area is enemy and we of course need to save it first inside of the enemy script so the class name setting a class name like this lets us use this name enemy to check if this area is an enemy or not so in here inside of this if statement we know that the laser hit an enemy so what we can do is we can delete the laser with Q3 and we can also delete the enemy which is this area here but instead of freeing it directly I'm just going to call the die function of the enemy which we didn't create yet so let's go into the enemy script and create a function called die and in here we can simply say Q3 for now in the future we're probably going to have a signal here that we're going to emit to the game script but for now we can just call Q3 okay so now when the laser touches an enemy the enemy and the laser both should be freed so let's try this I'm going to shoot the enemy and they both get deleted that's good that's what we want and now finally we also want the player to be deleted when the enemy touches a player that is also going to be simple to do we just need to go into the enemy scene here and because enemy is an area 2D it has all these useful signals in this case we're going to use the body entered signal because the player is a character body so the body entered signal is the correct one in this case let's connect it to the enemy script and in here we can do the same thing we did for the enemy we can go into the player script create a class name attribute here so that we can check for it inside of an if statement here we can say if this body which is the argument here the body that the enemy interacted with if this is the player we can call a die function on the player which we're going to create and we can also call the die function of the enemy save it and of course we need to create that tie function inside of the player script here and for now we can just call Q3 we will also most likely have a signal here in the future but for now this will do are we still getting an error here no okay great so with this now we should be able to touched enemy with the player and they both get deleted which is exactly what we want okay so the next step is going to be spawning the player but we're gonna do that in the next video probably but let's do a small recap and then we can end this video we created the enemy scene which is just like the laser it's an area 3D it has a script and in the script we're making it go down instead of going up and then we created the interaction between the player laser and the Enemy by creating some Physics layers and using the signals of the area to the enemy and the laser so inside of laser script we're deleting the enemy and the laser when they touch and inside of the enemy script we're deleting the player and the enemy when they touch finally I think we forgot to use the visible on-screen Notifier here so we can quickly connect the screen exited signal and inside of here we just need to free the enemy and this should result in the same behavior as the laser when the enemy goes outside of the screen it should get deleted okay great like I said next step is going to be spawning the enemy so that we don't have to add it manually to the game scene like this we can also get rid of this laser here and I'll keep the enemy until we create the spawner okay great thank you for watching if you liked it please leave a like comment and subscribe if you want to learn good though I have a course where I teach the basics of Godot at a much slower pace for beginners if you're interested check the link in the description again thank you for watching I will see in the next one welcome back friends in this video we're going to create a new enemy type and implement the enemy spawning functionality let's get started we created this enemy scene and this scene has all the basic functionality that we want now I want to create a new enemy type and I know that the same basic functionality is needed for this new type I could go ahead and create a new scene and recreate everything that we have here and add the extra functionality that I want but instead of doing that we can just use an inherited scene let me show you what that looks like to create one we need to go to the scene menu here and click on new inherited scene next we need to pick the scene that we want to inherit from in this case it's going to be the enemy scene this will create a new inherited scene for us and it will look exactly like the enemy scene in fact at the beginning it will be identical I'm gonna rename this scene to be the diver enemy save this inside of the scenes folder when you create an inherited scene you will get all the functionality from the scene that you inherited from so this scene even though it's in different scene than the enemy scene has all the notes that the enemy scene has and it also has the script the enemy script attached to it the nodes that we inherited are written in yellow as you can see and I can't really change these from here for example I can't delete an inherited node as you can see it is telling me can't operate on nodes this current scene inherits from so we can't really delete them and change their position but we can change their properties in the inspector so for example for this enemy I can use a different texture let's use this spaceship 4. and the Sprite is a little bit larger so I'm going to make this 0.5 for the scale as you can see we can change the properties from the inspector but we can't really mess with the nodes in the scene tab but that is like I said only for the inherited nodes we could create our own nodes here if we wanted to so for example I could create a new node here and with this one I can mess with it delete it it's only the inherited ones that I can't really change and also if you make a change in the parent scene in this case the enemy so for example in here if we change the name of the Sprite here to sprite from Spy 2D and Save as you can see that change is reflected in the inherited scene the diver enemy okay great so because we did that I think the Sprites texture property got reset because we made a change to it from the parent scene so you need to watch out for things like that so let's do that again and give this guy the crack texture and put the scale back save this so yeah enough about explaining the inherited scenes and let me talk about what I'm trying to do here so this is a new enemy type that we're gonna have this one will be significantly faster that is why I called it the diver enemy I'm gonna go to the root note here and set the speed of this to be 400 instead of the 150 of the regular enemy so if you go back to the game scene and instance one of these here you will see that it is significantly faster so that is just a new type of enemy that we're gonna have and because I now showed you how to create a new enemy type you're free to create 10 different types of enemies here so by creating an inherited scene just like this we have a new type that has all the same functionality as the normal enemy and it only took us like 30 seconds to make this so in a case like this this is okay to use but this can get messy if you try to make changes to the to the bass scene and down the line like I said this this can get messy so I don't really recommend using inherited scenes too much but in certain cases they're helpful you can also create a script here as well and inherit from the enemy script if you want to create more you know functionality inside of a script but only for the diver enemy you can also do that we're not going to do that in this case but yeah now that we have a different enemy type we're gonna move on to spawning this enemy and the regular Enemy Inside of the game scene okay so let's go back to the game scene and in here we want to spawn enemies from the top in random locations We're not gonna need these enemies anymore so I'm gonna delete these and in here I'm going to create a new node to the and this one is going to be the enemy container so just like we did for the laser we're gonna have a container nodes to have the enemies in so that the game scene is nice and tidy inside of the script I first want to create an export variable here up here let's create a new variable and this is going to be the enemy scenes and this is going to be an array so I'm gonna give this a type and this is going to be an array of packed scenes and it's going to be an empty scene by empty array by default and if we take a look at the root node this is what that looks like in here we're going to set the size to be 2 because we only have two different enemies if you have more be sure to set this to the amount of enemy scenes that you have and then we're going to go into our file system scenes and then we're gonna drag our enemies here so we essentially have the enemy scenes the packed scenes inside of this array and now I'm going to create a timer node inside of the game scene so let's create a timer here we're gonna call this the enemy spawn timer I'm gonna set this to be auto start and the wait time is going to be one I'm gonna put this at the top and let's create a reference to this even though we don't really need it now that I think about it let's see we might not need this but okay I'm gonna connect the signal yeah I guess I could use this to connect the signal or I can just do it from the inspector here both ways are okay so let's connect the signal the timeout signal and whenever this timer times out we want to spawn a new enemy we have the packed scenes inside of a inside of an array here so we want to pick a random packed scene instance it and add it as a child and we're going to add it as a child of the enemy container let's create a reference slot as well and down here we can create a new enemy instance I'm going to call that e this is going to be the enemy scenes dot pick random to pick a random packed scene and then we're gonna call the instantiate function I think I spelled that wrong let's see instantiate okay so this will create a new enemy instance for us and then we want to well at the end we of course want to add this as a child of the enemy container but before we do that let's give this a position for starters I'm going to set the position to be let's see what was our window width 540 so let's say 270 by zero in fact let's say 50 so that we can see see it actually so this will create a new instance set its position and add it as a child of the scene okay let's run the game and see if this works and you can see that we're spawning an enemy every time the timer times out and it is a random one between the regular enemy and the diver enemy scene great now the next step is spawning these at the top at a random position and a little bit above the scene so that we don't see it spawning like these guys here okay that is going to be this line here so instead of giving it a constant value like 270 here we want to pick a random X position so the X X is going to be random but the Y is going to be the same so the x is going to be a random F range this will give us a random floating point value from a range that we're going to determine and the range is going to be from well the window width is from 0 to 540 right but we don't want to use the full width we want to have a little bit of a margin so I'm going to say 50 to 500. and we can change this if some enemies are outside of the screen or something like that and the Y is going to be well let's leave it at 50. at first now as you can see respawning the enemies at a random X and the only thing we need to do now is taking the Y and you know spawning it above the screen and to do that we can simply say negative 50 instead of 50. this way we can't really see the enemy when it spawns and that's exactly what we want okay so that is going to be it for spawning the enemy there's also one thing I want to do for the different enemy types actually that I forgot to do and that is giving them different hit points So currently both the enemy and the diver enemy has a single hit point they they both die with a single laser but that kind of defeats the purpose of having different enemy types that just makes the diver enemy much more stronger than the regular enemy so what I want to do is I want the regular enemy to have two hit points so that it's a little bit more difficult to kill but in turn it is slower and I want the diver enemy to have a single hit point so that it is more easy to kill but it's faster so it kind of balances it out to do that we're going to take a look at the enemy script here we're going to create a new export variable called HP and I'm going to set this to be one by default and for the diver enemy we're gonna set this to be 2 in the sorry for diver enemy it's gonna be one it's for the normal enemy we're gonna set this to be two okay and in here inside of the script when the laser touches an enemy We're not gonna call die we're going to call a function called take damage and then inside of the enemy script we need to create this new function called take damage and this will actually take in a variable called amount so when this function is called what we're going to do is we're going to say HP minus equals amount so we're going to subtract whatever amount we were passed from the hit points of the enemy and then we're going to do a check so if HP is less than or equal to zero this means the enemy just died so we can call die otherwise we're not going to die so now from the laser script we need to give this a damage I'm going to just say one we can also turn this into a variable here so some lasers can have more damage so instead of saying one you can say damage here and if you want to create different types of lasers you can give them different amount of power from here okay great now when a laser touches an enemy it applies damage and if the enemy's HP goes below zero or equal to zero it dies so now if we run the game we should be able to kill the diver enemies with one hit oh we can't why is that well the regular enemies seem to be fine but for some reason diver enemies also have two hit points let's see uh oh yeah they have two hit points here why is that hmm did I no I did set this to be one oh it's probably because they're inherited yeah see okay that's funny because they inherit from the enemy even though enemy has this you know even though the enemy script has it won as default because we changed it in the inspector and because the diver enemy inherits from the enemy scene it also got the change as its own default value so it's kind of complicated there but we just need to set it to be one in the diver enemies inspector variables here now we should be able to kill the diver enemies with a single laser yep and the normal enemies should be two laser hits yep that seems okay okay so that's gonna be it for this lecture in this one we first created the new enemy type using inherited scenes we gave it a different speed and a different spy texture to you know differentiated from the regular enemy we also created this HP variable for the enemies and the diver enemy has one HP and the regular enemy has two so that was the different enemy type we also did the enemy spawning code inside of the game scene here we created a timer node and connected its signal in here inside of the game script and whenever the timer times out we're creating a new instance of a random enemy that we pick we're giving it a random position and we're adding it as a child of the game scene and that's going to be it for this lecture if you found it helpful please leave a like comment and subscribe if you want to learn though I have a course where I teach the basics of Godot at a much more slower pace for beginners if that is interesting to you check the link in the description again thank you very much and I will see you in the next one welcome back friends in this video we're going to create the scoring system and the UI to display that score in the end it's going to look like this I have a label that keeps track of the score and whenever I kill an enemy the label is updated let's get started okay so before we create the scoring system I want to clamp the player's movement currently if I want to I can just leave the game area and that shouldn't be allowed so let's go into the player script and in here we want to write some code inside of the physics process so after we call move and slide let's make sure that the global position of the player isn't outside of the game area so we know that the game area in the game scene here starts from 0 0 and it ends at the window size basically because we don't have a camera here and the game's left Edge is at zero zero we know that the right Edge on the x-axis is 540 and on the y-axis it is going to be what did we set it to 960. so this bottom right edge here is 540 to 960 and the top left Edge is at zero zero so we want to make sure that the player's Global position is inside of this rectangle here okay so inside of the script we are going to use the let's see global position equals so Global position is a vector 2. and a vector 2 has a built-in function called clamp you can call it by simply doing Dot clamp on any Vector 2 and this will take in two values the first one is the minimum value in this case it is going to be vector2.0 so this is simply a vector 2 that has zero in X and zero in y and the next argument is going to be the maximum value and this one is going to be the we're going to call get viewport rect dot size and this will return a vector 2 that is the size of the window the viewport rect essentially in our case that is going to be a vector 2 with the x value of 540 and Y value of 960. so this clamp will return a vector 2 that is above 0 0 and below the screen size and this will make sure that we stay inside of the game area so let's run the game and see this looks like so I'm trying to go out right it doesn't work can I go down it doesn't work can I go left make sure I don't get killed doesn't work it doesn't work but like half the player can go out I think that's fine I don't want the player to stop like here I don't think that looks natural that feels natural oops we died okay let's try the up as well hopefully before Oh I died again but I just try to go out for a split second there and it didn't work so uh don't worry this works okay now we can move on and create the scoring system so that is going to be inside of the game script we're going to create a new variable here called score this is going to be an integer and we're going to set this to be Zero by default we want to increase the score each time the player kills an enemy but currently we don't know when an enemy gets shot inside of the game script at least inside of the laser script we know that the enemy is killed in this function and we know that the enemies take damage function is called here so actually it isn't in this function it's in this function here that we call die we basically need to let the game script know when the hit points of the enemy goes below zero to do that we're going to create a signal here called killed and we're going to emit the signal inside of the Let's see we could do it inside of the die function here or we can do it inside of take damage let's do it here so before we call dive we're gonna say killed dot emit now we can go back to the game script and inside of the timeout signal callback here before we add the enemy as a child we can connect the killed signal of the enemy to a function called on enemy killed let's create this function okay now we have access to the exact point in time when enemy is killed so in here we simply want to add to the score I'm gonna add a hundred to the score each time an enemy is killed feel free to use a different value here it is completely arbitrary at this point and then we can print the score for now just to see that this is working so I'm gonna start the game and shoot some enemies and as you can see each time I kill an enemy our score is increased by a hundred one cool thing we could do is inside of the enemy we could create an export variable here called score for example or points let's say and let's set this to be a hundred so for the default enemy the points are 100 but for the diver enemy we could do this we could give it a higher value like 200. and when we emit the signal killed we can actually send these points and from the game script we can also receive them here and instead of adding a hundred we can just add points now when we kill the diver enemy Let's see we should get 200 points and if we kill a normal enemy we get a hundred as you can see it is working great so that is the scoring system in a nutshell now we just need to create the UI to display it to the player okay to do that we're going to create some new nodes and a new scene here so inside of the game scene let's create a canvas layer because we want the UI to be on a different layer even different drawing layer I'm going to call this the UI layer and I'm gonna put this at the top it doesn't really matter because if you take a look at the layer here it is at layer one by default everything in Guido is displayed at layer 0. so because the UI layer is at layer one everything that is a child of the UI layer will be displayed above everything else and in here we're going to create the HUD so let's create a new node here and this is going to be a control let's rename this to be the HUD and I'm going to turn this into a scene right click save Branch as seen and we're going to save this inside of the scenes folder let's go to the scene so this is going to be our HUD I'm gonna make this full react and in here we're not going to have much we're only gonna have a label here so let's create a label node this will display the score so I'm going to rename it to be the score I want this to be the top wide anchor preset here and in here we're going to give some text let's also set the alignment to be in the center and I'm going to say score is nine nine nine nine I'm gonna create some label settings as well here so that we can change the font size let's make it bigger like 64 Maybe uh maybe 48 we can also use a different font I have one here inside of my assets I'm going to use this one that looks nice and now we want to create a script here for the HUD so let's do that as well make sure to put it inside of the scripts folder and in here we want to create a reference to the score label and I'm going to create a set function here and whenever someone tries to set this score variable here I'm gonna change the text property of the label instead of changing the label I'm going to say score.txt equals score plus the string version of the value so instead of setting the variable whenever someone tries to set this variable we're going to change the text property of the label and you'll see why this will be you know easy to use for us okay now we can go back to the game script we can create a reference here to the HUD and now we can use the Hud's score property whenever we want to change the labels text so in the ready I could say HUD DOT score equals 0 and if I run the game this would set the score to be zero I'm gonna do a similar thing here inside of the game script as well I'm going to create a Setter for the score and whenever someone tries to set the score variable we first will use the value that was passed to set the score and then we're going to set the HUD score variable to this score as well with this setup we don't even need to call you know to set the HUD score variable anymore we can just set our score and it will automatically set the HUD as well now I can say at the start score is zero and whenever the enemy an enemy is killed you're adding to the score so this will automatically work now let's take a look at this so at the start score is zero and if I kill an enemy as you can see the score label is being updated and like I said this is because whenever score is set we're setting the HUD as well okay so great this is going to be it for this lecture you know feel free to play around with the HUD here if you didn't like the font size for example feel free to experiment there I'm not going to waste time with that in this one we created the scoring system and the UI to display the score we also did the player's clamp code to make sure the player stays inside of the game area thank you for watching if you found the video helpful please leave a like comment and subscribe if you want to learn more about Godot if you're a beginner I have a course where I teach the basics at a much more slower pace so if that's interesting to you check the link in the description thank you very much for watching and I will see you in the next one Hello friends in this video we're going to create the game over screen and the high score functionality in the end we're gonna have this game over menu that we show after the player dies and it has the current score and the high score let's get started currently when the player dies nothing really happens the player is deleted but other than that the game just keeps going you want to display a game over screen here so let's start creating that that's going to be a new scene that we're gonna have inside of our UI layer so let's create a new scene this is going to be a user interface scene so we're going to have a control node here as the root node I'm going to rename this to be the game over screen and let's save this inside of our scenes folder we're going to set this to be full rect and in here we're going to create some user interface nodes firstly I want to create a color right here and I'm going to make this full rect as well and set the color to be black I'm going to set the alpha to be like 125. and I'm going to go back to the game scene and instance a game over screen here inside of my UI layer so when the game ends I want the game over screen to pop up and I want everything else to be kind of tinted black so that's why I created this semi-transparent color rect here okay next up I want to create a panel here this is going to be in the center so let's set the anchor preset to be Center I'm gonna make this larger about the size and I want to go into the theme overrides Here the Styles and create a new style box flat this will let me pick a custom color from my panel and I'm gonna make it a bluish color more like a cyan I guess let's increase the saturation and that looks fine I'm also going to give it a corner radius of 25 pixels for each corner so that the corners are nice and rounded like this and that's going to be it for my design for the panel feel free to you know mess with this more and inside of this panel we're going to create a couple of labels and a button so firstly let's create the game over label we're going to rename this to be game over and I'm gonna put this at the center top let's create some label settings here let's give it some text game over we're gonna make the font size much bigger but first let's set the font to be the Kenny future font and then let's start increasing the size 44 seems to be 45 seems to be good maybe 46 okay 46 seems good let's move it down a little okay next up I'm just going to duplicate this label and this one is going to be the score label uh let's see let's put the high score first so this is going to be the high score I'm gonna anchor this to the center and move it up above a little so the text is going to be high score equals 999 we of course want the label settings to be different so I'm gonna right click on it and make it unique because we duplicated this if you don't do that when you make a change to the label settings it's also going to affect the game overs label settings I'm going to make the font size smaller here maybe 32. 36 let's try 35 34. okay that looks fine let's duplicate this as well and this one is going to be the score and I'm gonna put this a little bit below the high score and instead of saying high score this will be just score and I'm gonna align this to the center I'm also going to align the high score to the center as well okay I'm actually gonna maybe move these slightly up like that and I'm gonna make the panel smaller I feel like it's a bit too large but not like that like that maybe and then of course I should move these down a little okay finally we want to create a button here so let's do that let's create a button and this is going to be the restart button we're gonna put this at the center as well and move it down and this is going to say retry let's say retry that's a better word than restart and we need to go into the theme overrides here and give this a bigger font size and a font so the font size is going to be 32. maybe 35 and let's also make the button bigger as well like this okay that looks good okay what else I still want to make the panels smaller so maybe like this and put this in the center again and move it up a little a little bit more and let's also put the high score in the score down like that let's see I'm gonna make the game over label bigger 48 let's say maybe 52 and let's make the panel wider okay I'm getting a little OCD here and I'm gonna stop okay that looks fine so this will be the game over screen we're also going to create a script here put this in the scripts folder inside of here we basically want to create two different functions to set the high score and the score we also want to connect the restart buttons press the signal so let's start by doing that and so this signal will be emitted each time the button is pressed and when that button is pressed we're gonna reload the current scene foreign simple and like I said we also want to create some functions to set the high score and the score so first I'm going to create some references here actually I'm not going to create references I'm just going to create the functions set score let's say this will access the score node just like this and set the text to be score equals string value and for the high score we're going to do the same thing but the function name is going to be different and we're going to access the high score instead of the score there okay so this will be the game over script now we simply want to use this inside of the game scene so in here if we play the game now we will immediately see the game over screen which is not what we want so let's set this game over screen to be invisible when the game starts and when the player dies we will show it inside of the script when the player dies do we have a signal for that doesn't seem like it okay so we should go into the player script here and create a new signal called killed or maybe died I'd say killed it's fine and inside of here let's see we have a die function good so here we can just say killed dot emit now we can go back to the game script and here we're connecting the player's signals good we'll also connect killed here to on player killed let's create this function down here so when the player is killed we can basically just set the visible property of the game over screen to be true so first let's create a reference to it I'm just going to shorten this and say gos for game over screen and down here when the player dies we can simply say gos Dot visible equals true and let's also do an await here and create a timer for 1.5 seconds and wait for its timeout signal this is just so that we don't show the game over screen immediately after the player dies we're gonna have a 1.5 second delay to create a better game field okay let's see what this looks like so I'm gonna go ahead and touch an enemy and okay we got an error here what is going on okay I misspelled create try this again let's see okay let's die wait and the game over screen pops up great the next step is setting the score here and then the next step will be setting the high score okay to set the score it's not going to be difficult actually so before we set visible to true in fact before we start waiting we can say gos Dot set score and we can just set this to be our current score this way let me shoot some enemies first before dying so we have a score of 700 let's die and now the score is correct the next step is going to be setting the high score the high score is going to be a variable inside of our game script just like the score variable we have so underneath this one let's create a new variable called high score and each time we kill an enemy we need to do a check so if the score is greater than the high score we're going to set the high score to be the score so let's say the high score was 100 each time we kill an enemy we will check our current score and if it is greater than 100 in that case the high score is going to be the current score that we have in this run of the game and we can stop printing the score here okay so this is okay but the problem is each time we reload the scene the high score will be resetted and even if we you know fix that inside of the game let's say we're keeping the high score in a separate you know Global script and auto load script let's say a Singleton we would still run into the same problem when we quit the game and launch it again so we need to save the high score to our file system to do disk and load it each time we start the game to do that we're going to use the file access API of Godot so underneath the ready function here let's create a new function called save game and in here we're going to try to open up a file with the file access API like I said using the open function in here we need to give it a path and that's going to be user save.data and then we need to give it a file access mode and that's going to be right so this file path here is a special path Godot uses to save data on a user's machine so this is the path this user path is the one that you should use whenever you want to save something on the user's computer res is the resources folder it is the file system that we have here and this one is for the files that you have inside of your project you shouldn't use this file path to save something on the user's machine you should use the user path here and in here inside of user we're going to create a file called save.data file access.open will try to open this file and because we're trying to open it with write it will actually delete whatever it's in there and open up a new file and we can store this file file handle in a variable here called save file and then we're going to say save file store 32 high score and this function call Will store our high score inside of this save file that we just opened up so because the only thing that we want to store in our game is the high score we can just you know delete whatever was inside of the save file and store this high score value that we have so this is for saving it but we also want to load it at the start of the game and to do that we're gonna do a similar thing in here we're going to say save file we're gonna access the file access API again open the same path save that data but this time we're going to use a different mode this time we're going to try to read it because read won't delete the file right will basically destroy whatever you have here and create a blank new file for you in fact we can probably read these inside of the documentation here yeah so read opens the file for read operations right opens the file for write operations it is created if it doesn't exist which is exactly what we want because at the first time you play the game the file won't be there so right will create it for us and it will truncate it like you see here but anyways let's go back to the game script and in here inside of ready we're trying to open the save data file and we can check if this worked or Not by saying if say file isn't null so if this works the save file won't be null so inside of div statement we can just get the high score by calling get 32 this time instead of store 32 so the high score that we stored here we can get it back with get32 and if this file is null that means we don't have a save file so this is probably the first time the user is playing the game then we can just do a save here it's not really necessary but we can just do it to create the file and then we can set the high score to be zero in fact we should probably set the I Score first and then save that and that will create the file for us okay the last thing we need to do here is when the player dies we of course want to set the game over screens set high score function to the high score and we also want to save the game okay let's see if this works I'm gonna run the game so the first time we should have the save file now but we should have a high score of zero so when I die we have a high score of zero that's good I'm gonna retry and get a high score this time of 300 let's die again and this time high score is 300 but let's see if this stays when I retry so I'm going to retry and die again and as you can see high score is still there that's good let's try beating this high score try getting higher high score let's die this time as you can see high score is correct again and let's die one more time to see it there okay that also works finally I'm gonna quit the game and launch it again and let's see if we still keep the high score as you can see we do the high score is still there great so that is how to create the high score in our game and that's going to be it for this lecture in this one we created the game over screen and we implemented the logic inside of the game scene to show it when the player dies we also created the high score thank you for watching if you found this video helpful please leave a like comment and subscribe if you want to learn video I have a course for beginners right teach everything you need to know to make games if that's interesting to you check the link in the description thank you very much for watching and I will see you in the next one welcome back friends in this video we're gonna do some finishing touches to our game we're gonna create a scrolling background effect along with some particles to make it look cool and finally we're going to create some sound effects let's get started okay so the first thing that we're gonna do is making the game more difficult as you play because the difficulty curve right now is linear respawning an enemy each second because the enemy spawn timer is set to 1 and chances are if you're good enough to play the game at that difficulty you won't lose and that makes the game pointless to play for a long period of time we can fix this by making the game more difficult as you play so that there's actually a point in getting a high score we're gonna achieve this by decreasing the wait time of the enemy spawn timer each frame we're gonna set it to be 2 at the beginning of the game so that the beginning stage is relatively easy and as time goes on we're gonna decrease it until we reach 0.5 seconds and we're not going to go below 0.5 seconds because that would be just too difficult in fact it would probably be be impossible but you can experiment with this and see for yourself we're gonna cap it at 0.5 seconds like I said so let's set this back to B2 and let's get into our script and implement this okay I think we have a reference to the timer right we do good now we just need to inside of the process function here we just want to access the wait time of the timer and subtract from it each frame we're going to subtract Delta let's rename Delta real quick times let's say 0.005 so because process is run each frame possibly for 60 times per second we don't want to subtract too big of a number here because that would decrease the wait time really fast and the game would get difficult immediately so that's why we want to subtract a very small number here like 0.005 and obviously we need to multiply Delta here to make this frame rate independent we can also print this to see the wait time as it gets less and less so let's play the game and as you can see at the start it was two now it's going down it's currently at 1.97 and as time goes on it is going to go down down down to 0.5 at that point we want to stop it from decreasing anymore to do that we could use a clamp here like we did with the player's position I'm just going to do an if statement here and I'm gonna check for wait time if it is less than 0.5 or let's say it's greater than 0.5 let's decrease it otherwise if it is less let's set it back to be 0.5 let's actually make this an elsif else if it is timer.grade time less than 0.5 let's set it back to 0.5 and if it is 0.5 we'll just leave it alone so with this we should not go below 0.5 and that's good but to test it this you know uh005 isn't going to be fast enough and I don't want to wait for two minutes just to test this so I'm just going to set this to B 0.5 just so we can see the end result real quick and as you can see we reached 0.5 and stopped decreasing the timer's wait time and as you can see the game is currently way more difficult and yeah okay so this is what we want but we obviously don't want it to go down that fast so I'm gonna leave it at .005 I think that's a good number but feel free to experiment here okay so that is the difficulty next up we're going to create the scrolling background currently the background is empty and it looks horrible so let's fix that we're going to use a parallax background node for this and the reason is this has a scroll offset that we're going to use to create a scrolling background effect a parallax background needs a parallax layer and inside of The Parallax layer as a child of it we're going to create a Sprite this Sprite is going to be the purple stars which is a texture we have inside of our assets folder here the purple.png I'm gonna drag this here as you can see it is a square I want this to be not centered and I'm going to turn on region here and we're going to set the region to be the window size which is the width and the height here I'm going to say 540 by 960. and that's basically gonna stretch the Sprite to cover the whole screen but as you can see currently it is not being repeated we can fix that by going into the texture settings here and set the repeat to enabled that way the Sprite is repeated and it looks nice so just this alone would look fine if you play the game but I want the background to scroll so that you know the game feels more alive I guess and we can do that with the scroll offset of The Parallax background and we're going to do that from our script so let's go to the game script here I'm quickly going to create a reference up here called Parallax background let's say PB and like I said this has a scroll offset so inside of our process here let's stop printing the wait time inside of our process here we're going to say PB dot scroll offset and this is a vector 2 if I'm not mistaken let's take a look at it yep it is a vector two so this has a y property we're going to add to this each frame Delta times let's create a variable called scroll speed and up here let's create that variable [Applause] let's set this to be a hundred okay so this will increase the scroll offset each frame which is what we want I also forgot to do something here inside of The Parallax layer we need to go to the motion settings here and set up the mirroring so this will make it so that when the background is scrolling it mirrors itself so that it looks like an infinite never-ending texture if we play the game now without mirroring you will see that the background is just you know going down and there's nothing behind it nothing coming after it but if we set up mirroring here and the way we do that is we're going to say 960 for the Y and we don't care about the X because the background will move from up to down and it will never move left and right so the X mirroring doesn't really matter in this case but for the why we wanted to mirror itself at the end of the window here so let's take a look at it again and you can see that with the mirroring it is repeating itself as it Scrolls and this is the final effect that we want this looks fine as the last thing I'm gonna check the scroll offset actually because currently if we print this let's print the Y value actually you'll see that it just keeps on increasing and that's fine and if we leave it like this I don't think we would see any problems but you might run into some issues if you just let the game running for a long period of time so let's be responsible and fix that as well so we know that the screen is 960 pixels so we can simply say PB scroll offset dot y if it is greater than or equal to 960 we can just reset it and because we're resetting it at the exact moment it mirrors this shouldn't be you know visible that's also printed so now when the scroll offset goes above 960 let's wait for it it should reset and you know there's no visible difference and that's good and that is the scrolling background effects next up I'm going to create some particle effects to enhance the look of our background let's create a GPU particles node here and we're going to call this Stars star particle effect I'm going to move it up here we're going to create a process material here and I'm going to put this at the center on the x-axis which is 270. and I'm going to move it up a little let's say negative 50. you can see the particles being emitted there we're going to set the amount to be like 20. and I want the emission shape to cover the whole x axis of the game area so we're gonna go into the material here and set the emission shape to be a box and the extents are going to be 270 on the X so that we're emitting at the full width of the game screen let's set the gravity to be zero we don't need it and I'm also going to set the spread to be zero because we want these particles to go straight down we don't want them to you know have a spread and the direction is going to be actually negative 1 on the Y because we want these to go down okay let's give these guys some velocity so the initial velocity I'm going to say negative 1000 I want these to go down rather fast so both of these are going to be negative thousand now we can see them going down I'm not going to use this default texture for the particles so down here we have a texture slot I'm going to use the star.png that I have and this is going to create this effect basically finally I'm just gonna change the lifetime of these to be 1.25 I'm gonna pre-process them for like maybe five seconds let's say and I think that's going to be all for this effect so now if you play the game we have this nice you know star effect that makes it so that the game just feels faster now it feels like we're going through space really fast okay good and we can stop printing the scroll offset here okay so that is the star particle effect and finally as the final touch to the game we're gonna create some sound effects let's take a look at our audio folder here so we have an explode hit and laser sound so we're gonna have all of these inside of the game scene here I'm going to create a node called sfx let's put this at the top and inside of here as a child of this we're going to create an audio stream player for each of our sounds so three audio stream players here the first one is going to be the laser sound the second one is going to be the hit sound third one will be the explode sound so the laser sound is going to be for the player let's give it the laser.ogg file the hit sound is going to be when the laser hits an enemy and the explode sound is going to be when the player dies okay let's go into our script and create a reference for these sounds okay now we simply need to play these at the right time so the laser is going to be in the player laser shot function here so at the end here we can say laser sound dot play the enemy hit is going to be different because we currently don't have a signal for when the enemy gets hit so let's do that last and the explode is going to be for when the player gets killed so up here let's say explode sound play so with these alone we should have a laser sound and we should also get a sound of the player dies and we do apologies if that was a bit loud uh but okay so finally let's go into the enemy script and in here we're going to create a new signal called Hit and we're going to emit this inside of take damage so if the enemy got hit just emit the hit signal if the enemy got hit with the laser and if it didn't die let's just emit the hit signal and back in the game script when we spawn an enemy we're gonna connect the signal to a function called on enemy hit let's create this and in here we can just play the hit sound and now when we hit enemies a sound should play it didn't let's see why hmm okay the problem is obviously I'm not emitting hit and the enemy is killed so we're only getting it the first time we hit the regular enemy so my mistake there so we should also play this when they get killed we can also emit the hit signal when they get killed as well but I'm just gonna do it this way so now when we hit them should get the hit sound both when they take damage and when they die okay great so that is the sound effects and that is going to be it for this lecture this is all I wanted to teach in this series feel free to take this game and create something of your own practice makes perfect and it is the best way to learn if you found the video and the series useful please leave a like comment and subscribe if you want to learn video I have a course where I teach the basics of Godot for beginners if that's interesting to you please check the link in the description thank you very much for watching guys stay tuned for more videos and I will see you in the next one
Info
Channel: Kaan Alpar
Views: 24,360
Rating: undefined out of 5
Keywords: Godot, engine, godot engine, godot 4, tutorial, game, development, game development, game dev, gamedev, how to, godot tutorial, unity, unreal, game engine, learn game dev, course, online course, udemy, skillshare, godot, space shooter, how to make space shooter
Id: QoNukqpolS8
Channel Id: undefined
Length: 96min 0sec (5760 seconds)
Published: Fri Apr 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.