 So the other day I did a video on a balloon popping game, which also runs on your phone here So you can pop Bubbles on it or balloons on it. We're gonna improve it. We're gonna give it more colors we're going to add a scoring system up to the corner and Yeah, make a few other tweaks So this is to follow up making our game a little better because it was a very simple game that I did just to do a quick Tutorial, but I think kind of a fun simple game. I know I'm not the first one to make a game like this We're gonna worry. Um, but um, yeah, just gonna prove upon it more balloons. So I hope you enjoy this story Okay, so improving our balloon pop game So here it is it's up on git lab again git lab comm fort slash metal x 1000 port slash balloon dash pop dash game I'm just gonna clone it here. You can you can pull down the zip file from here or tar file Whatever you want. I'm gonna clone it. I'm gonna push it back to the server I'm just gonna use this clone with SSH because I get set up You don't have to get set up then you might want to use another route or set up git for me once I copy that I have an alias to I Just type clone and it pulls what's from my clipboard, but you would probably go git clone Put in that URL you just copy So now that I have that I can move into my balloon pop game Directory and then into its source directory and at this point I can use Godot to open up the project file and then Here we are Okay, so now I want to bring in some assets here So I'm gonna move these over here and I was gonna drag and drop our new assets I have a font the license for the font and I have a cloud I made which we may or may not get to in this tutorial So I'm gonna drag that right into here and then I can get rid of that Okay So again, let's look at some of the things I want to change Let's go into our main script here one thing that we had is I had it where the balloons are appearing faster and faster And the fastest they got was a half a second intervals. I felt like that was way too slow I'm gonna to go ahead and set that down to a Point two so that's like an eighth of a second from doing math, right? Okay, so now this time goes on that when they get to their top speed They're going to be appearing faster now. Let's go ahead and open up our balloon scene here And we have this hue shift, which is a shader that I did not create But here we go Right here. Let's go ahead and just turn off this That but turn this off so I can see the balloon a little better I'm gonna choose our sprite here and under the inspector if I go down to materials and click on material shader Right here. I have shader parameters And if we put this between number between zero and one, so if I do like point five it shifts it halfway point six Point seven that gets us like a darker blue if we do point two, it's gonna be like a yellow So that's how we adjust it in the editor here But if we go into the code here, you can see that I have used and again This is code that they came along with the shader create a random hue if they're using this Mathematical equation right here. I'm gonna change that one thing we can do basically It's getting a random integer getting a number divisible by three dividing it by two and then dividing it by 3.2 as a float so it's gonna get us a decimal You could up this number to like six or seven and we give us a bigger range But you can also just put a random range with some steps in there Like I'm just gonna go ahead and just say seven get something I test out there So basically it's going to give us instead before we had three colors We're gonna have I guess seven different colors possible here I think it's how that breaks down, but we're gonna get more colors in the balloons We're gonna get some teals some purples maybe some pinks and some darker blues So if we go ahead and hit at five this time our game will start there We go we have a green which we had last time there So that's more of a pink where before we had just a red but we'll still have red There's a teal color. So we're getting more more colors now Okay, we can't pop them because I turned off that 2d area so we want to make sure we reactivate that okay So we have that let's set up a scoring system We need a singleton which is like a global script that all our scripts all our scenes can access So I'm gonna come down here. I'm gonna right click on our resources and say new script and I'm just gonna call its Global you can call it whatever you want and then in our project settings. We're gonna go over here to auto load We're gonna choose that script Global and yeah, I'll just call it global with the capital G there. It's added now We can call what's in there from anywhere. So I'm gonna open up that script by clicking on it here I'm gonna go ahead and clear out some of this We're just gonna create variables because I want to start keeping a score. So we're gonna say Var score equals zero var Missed Equals zero so when we miss a balloon it will count how many we have missed Go ahead and save that now if we go back into our main function Actually, if we go into our balloon function every time we pop one what we can do here is we can say Global and this is case sensitive. So it's capital G because that's what we set in the project settings dot score plus equals one and Then we can also say when one leaves the screen so on exit screen we're gonna say Global dot missed Plus equals one. Okay, so now we're keeping score But we need to display that somewhere right now the game is gonna work like normal But you're not gonna see it so we're gonna go back to our main scene 2d view here And we're gonna add in a child node of a label We have that here. Let's go ahead and just put in some placeholder text. We'll just say score Miss but you can make it say popped or escaped or whatever you want to call will say zero and zero and You're not really gonna ever see that but I just want to because as soon as the game loads We're gonna run a script that updates that but I want to be able to see what it will look like on my screen here So that's why we're typing it here But now we have this label selected I can come down here and I can go to custom fonts click where it says empty And say dynamic font and then click on dynamic font go to font and we can drag This font over here, which is a free font that I got we're gonna go to settings and up this to 64 I think we'll be good. We'll give it an outline that's black And I think that looks pretty good. So now if we start our game, we'll be able to see that up in the corner here But it's not gonna actually Update we need to tell it to update. So we're gonna go back into our script here And we're gonna create a function. That's just called update score or something like that and We're gonna say here that our label So actually we need to grab our label so we could do dollar sign label is one way to do it But I think it's better if we actually set that as a variable up here. So I'm gonna say on ready Var label and we can do dollar sign Label or I think it just looks better I'm not sure if there's any benefit doing one way or another other than I just think that this looks a little bit better Even though it's longer, but now that we've done that anywhere in this script here We can call label just by typing label and it will be that label and we're gonna say that label dot text Plus equals actually let's just do equals so that will clear it out every time this this function is called It's going to basically Overwrite the text that's there and we're gonna say score colon and we're gonna say plus and The score is an integer. So we want to convert to a string So we're gonna say plus and then the string function here. We're gonna say global dot score And I'm just gonna copy that and paste it down here, but we're not going to want to override it We're gonna say add to that. I'm gonna do backslash and for new line Missed ends this score. We're gonna say Missed and if I typed everything right. Oh something. I already realized I forgot we created that function But we haven't called it. We want to call this Every time our game loops. So we're just gonna do that so it's on the game loop So multiple times a second theoretically 30 or 60 times a second. It's going to check the score So here we go. Oh We crash for some reason global GD type string So it's saying the value of type string and that's on this line. So maybe I don't have to Guess I never actually said it as an integer which technically is something to be correct. You should okay Okay, let's let's put this back and look at our global script here Var score it should be saying it as an integer since I gave it zero here Let me read that error again real quick So I'm saying well, let's run the script so I can see what the error says exactly. It's saying invalid set index text on Node global with value of string as far as I know I'm doing everything right. Let's go ahead and Comment out the second part of this line go ahead and hit f5 to run it. It's still It should be label. That's our label and it should be text. Oh Well, okay, let's undo those comments This is my fault up here for some reason I chose global instead of label when I was setting this I guess I was too busy talking to you guys now. Let's try it Okay, so we have a score of zero missed zero and I'm going to pop Like I got score one that one goes off the screen. It should oh Why did it say to already? Oh, okay, so let me pop a few here Am I not freeing the cute when I'm popping them? That should add If I click that and that and I'll see it's still counting them when they go off the screen So let's go into our balloon here and we're saying when it goes off the screen exit screen We're gonna say miss when I'm killing it. It's cute. Maybe I'm waiting too long on this There's probably a better way to do this. Let's see I'm gonna pop that one. I'm gonna pop that one. It's still saying Miss when it goes off the screen. So I guess when I'm popping it It thinks that it's going off the screen. That's interesting. I didn't think that it would do that So let's go ahead and see I have a variable here called death dead. Did I ever use that somewhere right here? If not dead okay, so input event if not dead pop Here I'm gonna say the same thing I'm gonna say If it's not dead Let's give that a try so I pop that one pop this one So when I pop them It's immediately saying that they're dead. So it should not recognize and it seems to be working. So let's let some go off the screen now Okay, that's working Let's let a few more go off the screen just to check There we go. There we go. Boom and I can pop some okay. It's working there might be a better option to freeing up our um Our balloons Uh, but we're we're good so far on this but actually that's good that I did that because I'm actually not going to Free them when they go off the screen. I think what I'm going to do is have them go back down to the bottom of the screen And that way if you the more you miss the more come on to the screen does that make sense? So I'm going to do here instead of freeing them when they exit the screen. I'm going to say Set their position y which is up and down. So position dot y equals um Our screen width so we got our screen width in our main function here So let's just control shift f and I'm going to say size So I do this sometimes to look so I have viewport rectangles. That's the command. So sometimes we do this. So I'm going to say get viewport Dot size And I think is it just dot y or is it like this y plus We'll say 300 Now let's say 500 Oh, I think it was already giving me an error there. Let's go ahead and let them run up the screen here again I've had these ideas. I haven't actually done this yet. So this is kind of there we go It did crash so let's go ahead and do this So that's getting our screen height So even if we resize our screen, we know the screen heights and we're going to add to it So that's the balloon. So we see this pink balloon going up here in the green balloon going up here once they go off the screen There it is that one just came back and we should be seeing the green one coming back up So if you the more you miss they're going to go to the bottom of the screen and come back up So you're missing them But then you have another opportunity to get them but the more you miss the more they're going to be coming So that's something I wanted to do last thing I want to do with this code is um add some clouds So I added a texture of a cloud here So let's go ahead and I don't know how this is going to look it may look horrible But we're going to give it a try we're going to say new scene I'm going to say 2d and I'm going to say I'm going to call it a cloud And I'm going to change that to be Change type some people leave these as node 2ds and I'm not sure the reasoning for that I'm going to change type to a sprite Just a regular sprite. It's not animated and I'm going to go ahead and grab my cloud This is the cloud texture. I drew and make it its texture here And I'm going to add a script to this so attach a script We're going to call it cloud Again, if you have a larger project, you want to put your scripts in one directory And your sprites and another is a very small project If it got bigger, we would want to move it into there But what I'm going to do here is I'm going to say Var speed equals and I'm just going to give it a speed at first here of 100 Then I'm going to say function process delta And then I'm going to say Position and it's basically what we did for the balloons but in the opposite direction So I'm going to say it's position y Plus equals wait plus we want to go down so minus equals Speed times delta again delta is basically a time between loops Think of it that way and what we're doing here is and just saying move at this speed We're saying move at this speed times that which might be a fraction It just helps if you have different speed machines keeping a consistent speed of your item So if you design this on a very slow machine, you play it on a faster machine The clouds aren't going to be moving super fast And if they're on the other way around If you design a faster machine, it's not going to run super slow on a slower machine It should keep it at a consistent speed So if I do that if I hit f or I should have said f6 f5 Starts our game f6. Yes, save it Save it We should see the cloud. It went real fast. So let's put this down to like 10 Let's see see up in the corner here. There we go. It's moving up off the screen We might adjust the speed a little bit more, but that's our start and then we're also going to say We're going to add in a child node Visibility notifier and we're going to say here with that selected we're going to go to node and we're going to say On exited screen, we're going to run this function within our code. So when it goes off the screen We are going to say Position dot y negative Oh video finished rendering negative or equals negative Let's see. We want these coming down from the top. Oh, I actually did it the other way I want the clouds coming down not going up. So they're going to go to negative. We'll just say 200 just to get it off the top of the screen I'm going to say plus on this one because we want the clouds going down And real quick just to test this out. I'm going to go to our main system I'm going to add in a child cloud and I'm just going to put it right here in the center of the screen Start up our game and see what the cloud does good. It's going down Which is great. So, but we definitely speed it up a little bit. We're going to get the variable speeds Let's go ahead back to our clouds here with our cloud selected. We're going to transform it I'm going to make it a little bit larger. I'll say four four And actually my squares my my clouds very squarish. So let's actually just do Three on that there we go. That looks good, but just depends on how I draw it We're going to go in here to script and then we're going to say let's just do 50 for right now There we go the clouds moving down now. We also want to make sure the cloud stays behind the balloons. So that's important So let's go here and for our balloons Choose our balloon go to um z index. We'll set this up to something higher like 50 And we'll go to clouds and we'll set its z index to Negative 50. It doesn't really matter how big the number is, but just want to make sure there's a difference there And uh, let's go in here back to our cloud script And for their speed, let's do a random range of 50 to 100 So our clouds all move at different speeds And then we can code it for them to show up and make it a little random But let's go ahead and just set some into our game So i'm going to put one here. Let's set our score our label here. It's index Oh, you know what it's a label so they don't use the index they use something else I'm not going to worry about that right now our clouds might be in front of unless we do this There we go that works. So I have one cloud there So the problem with manually Oops Okay, let's put this back up here for now. Actually, let's put it back down here and lock it in place Right, so I'm going to choose this and say locks. Now. I can't drag that around The problem with manually setting our clouds is we're not really taking the size of our screen into account so I'm putting this out like this But if somebody had a Screen wider than this it may not work out too well. Let's just go ahead and I'm going to add one more Right down here So they should all be moving at slightly different speeds see my screen is wider than I had anticipated and that's problem with manually doing this and uh But they should get kind of spread out over time Because they're all moving at different speeds I'm doing it. This is the cheap way. Normally I would code something like this Here we go. We got clouds all moving in the background. I don't know if I like that if that's too distracting From the balloon popping, but I'm going to leave it for now because I did it But uh, we have these clouds now if you don't like that the game's open source You know where to get the source code go ahead and remove them Uh, but that's it. Uh, I hope you enjoyed this tutorial. I hope you visit my website films by chris.com That's chris the k there's a link in the description go ahead and check that out And as always, I hope that you have a great day and I hope that you learned something Thanks again for watching and I hope to see you in the next one. Okay, so hold on. Do you remember how we increased these? Right at which the balloons appear with that and the balloons looping around it does get a little out of hand We could do something there where it counts how many balloons are on the screen and sets a max But I think I'm just going to go back into my script here my main script And change this delay back to a half a second Uh, because that seemed pretty good before it was a little slow But now that our balloons are looping around when you miss them, uh, I think it will Even out and the only way to really test this is to you know, wait a minute or two and see what the balloons do Uh, but I might tweak that number a little bit But I just wanted to go back because as soon as I stopped recording It's like all these balloons started coming on the screen So it starts off kind of slow, but we'll increase in speed again. Thanks for watching and I hope that you have a great day