Godot Wave Shooter Tutorial #11 - Blood matches Enemy Color + Power ups

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to another way shooter tutorial we are at tutorial number 11 and in this tutorial we are gonna be setting it up so you have different colored of blood so the blood will be in different colors when you kill the corresponding enemy so if you kill a red enemy the blood will be red and if you kill a yellow underneath the blood will be yellow because in our current implementation we did not have that we actually just only have the red so we're gonna be fixing that and we're gonna be setting up a powerup system that will allow the player to shoot faster when he grabs the green will power up for a little bit of time so let's get right into it okay so just open up your blood particle scene I've already set the color to light so just make sure you set your color the white and that will make it easier so we can actually set the colors correctly when we have the different colored enemies so the thing with this solution let's go into our enemy course crypt where we actually instance blood the thing with our solution is we can't just set the color of the blood straight to the enemy color because if you have enemies above that blood it's gonna be very hard to differentiate which are in the museum which are blood because there's no outlines so I've come up with a solution for this that should be relatively simple we do blood particles instance dot color actually dot modulate because that's the color of it's actually modulate if you do color like this instead of modulate this just generates a color that can be used in a modulate if you just write color though it's not going to actually set that color of this right I hope that makes sense color is just more of a data type modulate actually sets the color of the current sprite or whatever you're changing so we're going to be doing color but we're gonna have to do dot from HSV just hue saturation and value so here we'll basically change the color so if you have like red you can change it to green saturation makes it so is goods darker and value we'll make it so it kind of fades out to white what we're going to be using is our current color key so you have our on ready variable that sits to modulate so you just use current color from this color datatype you can just do color dot H and get the Q value of that color so it's basically you're going to be the same as doing current color H which gets the hue of our current color then we can do for the saturation I found 0.75 if it's a good value hue and saturation all these values will actually go from zero to one it's usually zero to 255 go thought likes to use 0 to 1 so 0.75 will make it a bit darker and value will just leave at current color dot V and you can see now that we have our script setting up our color and basically parsing it all together except for the value color which should make it a bit darker so you can differentiate the blood from the enemies again I'm not an expert at color so if I say anything incorrect you can correct me in the comments you can go back to your arena scene hit the play button so we got yellow enemy coming in I shoot them and look we got blood coming up actually this isn't darker I actually said it a bit lighter so again that was that was kind of my bad but I think that works just fine I actually like the lighter blood a lot better but when I was talking about the color values before I now realize that I switched saturation and value so saturation will make it fade to white and value will actually make it darker so if you want a darker blood you can change this value right here for now I like changing the saturation we could save that and we have enemy blood working so it should work with every enemy that you set up and it should all be modular so whenever you set up you don't have to change any code to get the color working now we won't power ups into the game so I have a solution so we can't just use our enemy spawn system for our powerup spawn system because if you remember the enemies actually spawn outside the screen we you want power of spawning in the screen so you can actually see them so we're gonna have to make a new spawning system just for the power-ups we'll be reusing lots of the code from the enemy spawning first before we set up the power of spawning let's actually set up our base power up scene so we're gonna click the plus button add a new scene I'm gonna do an other node and this is gonna be a sprite and I'm just gonna be using our same square sprite which basically every spray in the game is gonna be the square unless it's blood then it can be circle but you have it's basically just a lot of placeholder art that we're using here so I'm actually gonna rotate this say negative 45 and you have a different look for these power drops because now they're rotated and so the player should be able to see the power-ups and be able to differentiate them against enemies or bullets here we go we got our powerup and you can set the color the power up to however you want I'm gonna set it to like a light green I like that there you go you got our power up in I'm gonna rename the sprite and we're gonna call this so my idea for this powerup is it's gonna make it so the player shoots faster so I'm just gonna kiss a powerup reload there we go well now we have a sprite in we need to actually have collision detection because right now even if we wanted to hit collisions we would not not actually be able to tell if we are colliding with it so we are going to be adding in area 2d and under this area to thee we are going to be adding a collision shape to thee I'm going to be setting this shape to a rectangle shape and you can see it's all nice and that the collision shape actually rotates with it because it's inheriting this rotations degree property and the spray I'm gonna turn on use pixel snap and I'm just going to try to get somewhat there you go you have a collision shape on top I'm going to hide the collision shape so I don't see it and then we can rename this area to thee two hits box so now we're going to be adding a script to our powerup reload and hit create and we can remove all of this placeholder stuff I'm going to go back in to scene select the hitbox when I go over to the note signals I might connect area entered back to the powerup reload script we need to make sure that we know what our player is when we enter it so I'm going to go back to the player hitbox I'm gonna go to groups and you see we won't be able to detect if it's a player because we don't have a player group assigned to that hitbox so I'm just gonna be setting player and add that to the player hitbox remember you have to have a hitbox selected and add the group so it can actually detect correctly because if he added it on top and that was the player that you added the group it won't be able to see it okay so now we can go back into our script and we can check instead this pass we can do if area that is in group and I'm just gonna write player that's cuz what that's the same name of the group that we set before then we can do Q free for now it's not gonna do anything for now we'll save it but you can see we can't actually modify the player shooting speed because the player doesn't have that as a variable and we'll need a variable so we can actually modify it on the fly while the game is running so I'm gonna be setting up in our variable and call this shoot speed and let's see where actual shoot speed is oh let's go reload sphere I'm actually gonna call this reload speed as the variable and looks like we have it set to zero point one so we just set that zero point one and we haven't read about speedin now we need to actually have it in action so go down there player script and when they reload speed times out we're just gonna do dollar sign reload speed dot Waits time equals reload speed that way it's actually setting up its wait time equal to the the reload speed but what's gonna happen is once we saw their speed back to a faster speed like 0.05 and we want set it back it's not gonna know what the default reload value was so we can do is we can write our default reload back to reload speed so basically default reloads to be the zero point so you might not need this variable if you're gonna have different weapons like instead of actually doing a powerup you could just do a weapon that drops then you just basically keep that reload speed and change it from weapon the weapon but for now for this project I'm just gonna be setting up a reload speed default variable so we could save this and we can go back to our powerup reload now when we collide with our player we want to do area dot gets parents the reason why we use area dot get parent is if you go into the scene tree it's gonna be detecting the collision detection on this hitbox but it doesn't contain our script you have to go one node up in the scene tree which is the parent node of the hitbox which then has our script that we need to change those variables so we're gonna do area that get parent dot and we're going to be giving our reload speed variable dot reload speed equals we'll just set reload speed to 0.05 which will be twice as fast as what we currently have but right now it's gonna permanently set their reload speeds we want to have a cool-down so once the once we set the reload speed there needs to be a timer that cancels that we'll set that back so we're gonna be doing this in the player we're gonna add in their timer I'm gonna call this timer powerup cooldown and just set one shop a true on that timer so it doesn't keep going once it's played and that's all we need we could save it you just leave at one way time now if we go back to our powerup reload script then we can actually set a area dot get parents dots let's say get node and we're gonna be getting our powerup cooldown I'm gonna copy this paste that in and when I said that weights time equals I'll set that to we'll just have at a one second a default and you were probably saying you probably don't need this line because we already have the timer set the one second but let's say you want to have different cooldowns on each powerup this is going to allow us to have different cool downs I'm also gonna do area get parents get node powerup cooldown we're doing the same thing and we're gonna tell it dot start that way the powerup cooldown actually gets started and this gets queue freed that's why we can't have a timer and the power up because the powerup gets destroyed so that timer would never actually go off so you could save that and in our player when you get our powerup cooldown and I'm just gonna connect the signal timeout back to the current player now when this goes off I'm gonna have to say set our reload speed back to its current value so let's say we had multiple power-ups we already have our reload speed powerup well if we had a damaged powerup well as soon as this goes off we set all of our values back to default in that and if we collect another powerup within that same time frame it's not gonna do anything it's gonna get reset so how do we fix that well we're going to be using an array for that so I'm gonna be sitting a nerve variable I'm gonna call this power up power up resets and we're just gonna be setting up this array as empty there's gonna be nothing in this array and so now we have our power up reset array and now we can go back to our powerup reload and we have to tell the player you want to set this array value to our powerup reload because that's the only value we want to get reset when the players cooldown goes off so we're gonna have to do is we're gonna have to say area that get parents dots and we're gonna be using this same array value right here powerup reset we're gonna be saying powerup reset dot append and we're going to be adding a string and we're gonna say this power up reload so what append does is it adds this value to the end of the array and it doesn't it honestly doesn't matter where this value is in the array because we're gonna be searching the entire array to see if we have it so now we can go back in our player script and we can say if power if power up reset dot find and we find the value that we set over here which is powerup reload copy this and we'll paste that in there so if we find this value is not equal to null meaning exists then we can say that we want to reset our reload speed so we just do reload speed equals default reload speed which is what we set up before which will set it back to the last reload speed that it was set at when the game started so now this will only make sure if we have multiple power-ups that only one of the variables actually get reset so this will make sure that once I grab a reload speed powerup if I try to grab an damage powerup right after it doesn't get reset too early and we need a set power up reset dot find now we need to do dot erase power up reload which means that this value will not get reset anymore if we grab another powerup so it's a bit confusing using arrays but I hope you guys kind of get the gist once we set up multiple power-ups and now we have the system in place so let's go into our Reno script were responding enemies and let's make in our export array packed scene and we'll call this variable power-ups and in this arena we're actually gonna be setting up another timer which is just gonna be the scene tree now we're gonna say this power up spawn timer and we could set a powerup spawn what you guys think every five seconds spawns a powerup I think that sounds good we'll do auto start and we'll connect the timeouts back to the arena so we're basically gonna be using lots of same code from the enemy let's actually copy this enemy number they never doing up here and we could paste that down here and I could say instead of enemy number I can write power up number we're saying power up number to ground random range zero to power ups dot size minus one so now we've picked up we've picked out a power the powerup that we're using the index of that ants now we want to instance it so we can do global dot instance node our ups and we can write power up number so we're instancing that power up now and then we need to set the position so the position we want is going to be vector to random range is our x value from zero I'm going to show you guys another project settings go down to window and we're going to be using our width so 0 to 642 644 our Y value let's play comma here and we'll do random range 0 and then we're gonna be using our height of our window which is 360 for me and we do 360 so now it's gonna be instant seeing it anywhere on the screen because these are all the values that are on the screen from in between 0 and 6 40s on the screen 0 this 360s on the screen now we want to just set ourself as the as our parent and you also need another parentheses there to finish off the vector 2 and this doesn't need to be there so we're picking out a powerup number and we're instancing that powerup that corresponds with that number at values in between the top of the screen all the way to the rightest part of the screen and then from the top of the screen all the way to the bottom of the screen and that will make it so it spawns a powerup anywhere on the screen and you will be able to see it and we will be the parents of that powerup so now we can save that and that should all be working once we go into our arena and we serve power-ups it's it's size to 1 and I'm just gonna be dragging power up reload as the zero value so I'm I'm save and you can see there you go you have a powerup that spawns so I'm gonna be shooting just to show that it will shoot faster and you can see it shot faster just for a second and I'm gonna stat the power-ups spawn I'm gonna set that to 10 seconds I think every 5 seconds is a bit too much you can see you're shooting faster every time you grab them so let's let's fix our powerup spawn timer it set that the 10 see how that is okay we got one down here I'll just shoot just the show it gets faster for a couple second maybe we could set the power up duration a bit longer to think that would be better so it's just some minor adjustments by masa our wait time to like two seconds and then I want also spawn power-ups every 15 seconds now we got a power a basic powerup system working but we want to make this expandable just like we did with our enemies with the inherited scenes and stuff and so usually when we were setting up our I'm gonna rename powerup reload this script right here and we're just gonna call it power up because this we're about to make the script Universal to work with all power ups and I can close this old one and now our doesn't empower up Gd so for these values we're gonna just use the export to change these values so let's say exports now let's do string var and then we're gonna call this variable player variable modify and now we're going to be setting up a couple more export variables to export float of our player variable set and so now we're going to be incorporating this into setting our player variable and setting this our end value to that player variable so I'm a set player variable set to here and instead of just doing got reload speed we're gonna do dot set and I couldn't write player variable modify comma player variable sets so what this does is it takes two arguments it takes this player variable modify string which you'll get this string and it'll actually find a variable that uses that that is exactly named just like the string so if I named this export variable modify and the editor right here if I name this exactly to our reload speed variable let's do that right now let's go into a powerup reload set player variable modify we're sitting at the reload speed and go back to our powerup script what this is gonna do is it's gonna fit it's gonna find that reload speed variable in our player using the string and it's gonna set that value to this other variable that we have called player variable set so it's setting the reload speed back to this value which we want the 0.05 exactly the same and we're also going to be saying a-another exports floats variable I'm gonna say this is gonna be for our wait time variable and I'm just gonna say powerup cooldown and we'll set that to powerup cooldown I'm just gonna set to 2 by D by default and so that will set how our up cool down to our actual corresponding powerup cooldown and we did do a pend powerup reload right here we set that as a string but that's just more work trying to make another export very export string just to get the name of it we just use the native name up here because it's the exact same as the variable we set in here and the one that the player is checking for so instead of just doing powerup reload we can say append name which will return the string of our name and that way we just set our name and then the player will have to find that corresponding name and so that just makes it a lot easier when setting up these multiple power-ups so you could save everything and we'll run the arena and everything should run exactly the same as we had before and you see we have a powerup that spawns I grab it and you can see it's shooting the exact same as it was before everything reacts the exact same reload speed changes and all it is is it's a universal script now that we can set these values and it works on any powerup so this is awesome because now we're able to make a damaged powerup but first we have to set up the damage variable in our player so we'll be setting up another variable or call this damage I'll just set it to one and I'll set up a another variable called defaults damage and we can just set that to damage when the enemy gets hit we'll have to change a couple things because the enemy automatically subtracts one health am i right from that boy but it won't be able to see our damage variable because our damage variable is in our player so only instance of bullets we're gonna be using we'll set that to a variable I will say bullets instance that way we can set a variable in the bullet instance well instance thought damage equals and we could set that to our damage variable which will set that same damage to our damage which then in our bullet will have the change that code a bit too so I'm just gonna go to bullet GD I'm gonna set in our variable and it will call it damage so now this will set to the player's damage which then in our enemy Corps our enemy damage er is going to be our bullet right here it's cool it's colliding with our enemy damage or instant and now instead of saying HP minus equals one we can do HP minus equals let's do area that get parent remember we can't just say area dot and then give the variable because the area doesn't have the script so we have to do area dot get parent dot damage which is getting our bullet damage from right here which was then set from our player when the player shoots the bullets that way the variable is kind of tossed around but it's able to see it now and the enemy can subtract based on the player's actual damage variable right here now we set that up in our system we can now go up to an hour powerup reload so now we can do scene inherited scene off of powerup reload so now we can select a powerup reload the TSE n open it makes a duplicate that's inheriting from the original powerup reload we can rename this to powerup damage and we could set this color to more of like a pink color like that for a player variable modify we can say damage which is the variable where modifying and we're going to be setting or damaged to double the damage we have before and we'll just leave the cooldown that one so now I could save that and we have powerup damage so you see how easy that was to just set up the power up that's that's why I like when we set up a system that's that's letting us use and reuse the same code but also make it so it's expandable it just took some setting up of variables on the player side so now we have to go here and we can say else if power up reset dot find let me can say power up damage is not equal to null damage equals default damage and I could say power up reset erase power up damage and you could even automate this right here is this is actually it's basically like the exact same thing just using different variables and so even if you wanted to we can automate this I'm just gonna leave it here for now and you can see now we have a damaged powerup we can just go into our arena increase the size of to and I can drag in my powerup damage and drop that there and we could play the game and now you're gonna have a half a chance of dropping a normal power up reload and we're gonna have half of the chance of dropping a powerup damage so now we have a reload nice shootin faster now got another reload coming in well you can see there's damage power up right here and if I grab that I am now doing a lot more damage to them one more thing before we end this tutorial let's make it so the power-ups look nicer when they spawn in because they just kind of up here and so we're just going to be adding an animation player and in this animation player you can click this animation button we'll make a new one we'll call this up here so now in this animation we can say okay let's modify the scale of it we'll set scale to zero zero and I can insert the key with by hitting this key button press create I'm at zero the zero frame right now and if I go up to 0.1 and then I set our scale to 1:1 naik C and I play it back it goes up and we can make this animation a little bit better by I'm gonna be saying am i snapping right here there's a snap right here it's at the zero point one I'm gonna set that to 0.05 that way I can make some more fine adjustments and right here I'm just going to set it to 1.1 1.1 and then I'm gonna set it back to 1 1 the next at 0.2 so you can see it kind of has a bounce to it when it goes on fades in it looks really nice I'm gonna be setting the time right here it's a 0.2 that way it ends right here and what else I may be saying cubic 2 cubic interpolation that way it's just kinda it's more of a smooth it's kind of like an ease curd to each of the animation keys it kind of adds a more of an easing curve and I think it just looks nicer but there you go you got fade a pure animation there's an a right here that will make it autoplay and so when it's created that will automatically play this animation so you want to make sure when we start when we end this scene before we save the scene you want to move this track right here all the way back to zero that way when it starts it will actually be completely shrink so you won't be able to see it so I can close that scene now we have it saved and you can see now that I saved that one reload our damage powerup will have it applied to it as well this is not the nice thing of having these inherited scenes is I just need to do it in one I don't have to do in all the power-ups cuz you can imagine if I made 10 power-ups it would take forever to get those all synched up so just doing this inheritance works really well so just make sure you have a track key at 0 and we can run it and you can see they're fading in looks really nice man it looks so much better than having them up here and that simple animation player just does a lot and especially adding that little balance to it when it fades in I think it looks really nice technically it's not fading in it's more like scaling it but you know it's same thing you have it so you can easily set it up and do whatever you need and add content to the game in next tutorial we will be setting it up so the blood will actually fade out so thanks for watching guys I hope you guys enjoyed and I will see you guys in the next one
Info
Channel: PlugWorld
Views: 2,829
Rating: undefined out of 5
Keywords: godot, game development, godot engine, godot tutorial, game dev, GDscript, godot tutorial 2d, game polish, game feel, godot 3.2, tutorial, top down, shooter, wave shooter, learn gamedev, series, godot 3
Id: QyFaqdWhpsg
Channel Id: undefined
Length: 29min 19sec (1759 seconds)
Published: Thu May 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.