Hello and welcome to the 12th tutorial in the caucus to the x floppy versatile plus series. And in this part we're gonna be looking at scoring points. We'll be using the source code as usual from the previous part. So if you don't have it, don't worry, there'll be a link in the description to the source code, we essentially have a basic working game without any scoring system, our scoring system will just be like Flappy Bird in that when the bird or soliloquy in our game, passing in between the pipes, the player gets a point which is added on to their score. Firstly, we will create a hash define the definitions head out for the school collision bitmap. So if we go to our definitions here that you can copy and paste this will change obstacle to point.
It's made it unique by changing the two to three at the end. Now let's create an empty node and a body to attach to it. We'll be doing this in the pipe dot cpp because you'll be rendered with the pipe. So what we're going to do is Auto print node equals the reason we're just doing that empty no Norris broad anything because we're not going to see in this not just going to use it to detect if the player has a path for the pipes and then we're going to create a body so our physics bodies appoint body people physically physics body colon colon create and we're going to use the crate box function and for the size we're going to specify size and the width we're just going to have add one we want the minimum we're going to use broy colon colon create and what with what we're going to do here is we're going to get the point of the ball or the player whatever it is get content size, dot height, and what we're gonna do is time that ball in the pipe gap and if you remember, we had a pod gap in the definition header which at the moment said Which is basically the gap between the pipes is 10 times the height of the bird or the player or whatever you want to call it.
And let's set up the body so it isn't dynamic like the pipe, assign the collision bitmask and set the contact tested mask to true. So collision can be detected. So point body navman, two, point body. Collision bitmask. One thing I do want to mention, though, we're doing this in a very particular way, there's no right or wrong way as long as the result is what you intended to be. So experiment with the code 20. try and do things differently.
You may want to use gravity more or actually we're not using gravity at all the drawing system you might want to use then you may be able to make you better by ease and then more efficient. So experiment with it. Not logs no really wrong right wait there are better ways though. So just again just experiment. Okay the physical body in their setup and can be attached to the point node. And the point now will be positioned in between the pipe and added to the chart to the left.
So point note set physics body this will specify the point body that we're going to point to node vision online, new the one way you do point but that's just personal preference again, it's whatever you feel comfortable with. And for this for the position and do top pipe get position okay. And therefore why would the top pipe get dish y minus top pipe get content sois the hype deploy to so now this position the at the moment in the y axis just literally at the bottom of the top pipe aka the middle part of the point no but we want the top part of the point knows that what we need to do is minus and in here, we're going to be doing and quite complex please bear with me break con con create from the thing that we just did before so board clean G and then here get content sois dot white, torn boy pipe the app but we're just gonna do void this by two, because we only want half of a position there because if we have the entire thing position down, it won't be directly in between the points.
And now, what we're going to do is actually add the other child to the layer. So layer, add child, and we'll do point to no final thing to do. Final thing to add in the pipe class is the action to move the point note similar to the pipe action. So auto point no action equals move by the column column create. And this is academic exact same as this so we can we can literally just copy and paste it no point taking the risk of making a mistake. What we're going to do now is point to node run action Pointing no action.
And now if we run this you'll actually want to stop running. And I want to run it in an iPad run. One thing I found is they are the other night but even do this that on Xcode when you probably similar to fanatical recording in server 20. Often I'll be using the old iPhone simulator aka the 3.5 inch or non retina, I found that they can scale it. So this is I'm using iPad on scaling it down to 50%, which is great because on the old droid power or the like the lowest device simulator was really laggy whereas on this, it's not that laggy and comply a little better. So we've been up and down and there we go.
That is right there is the scoring section that we created and it's died. Okay, so the next thing to do is we're going to create a score integer variable in the game scene header and initialize it to zero so games seen what here, but then on sign in because we know it's not going to go below zero, but you may want some sort of different scoring system again, you'll have to customize it to your game and we're gonna it's gonna find it with a society here, though, score equals zero, not part of this tutorial is to add the collision check condition and increment the score. Plus for the purpose of this tutorial, we will just print out the score when the player hits an obstacle and dies, but we will eventually implement the score in the game overseen in the next few tutorials. So the uncontacted begin what he will do else if and what we can do.
To make it easier we can copy and paste This, the only one thing that we're going to change the literally the only thing we're going to change instead of obstacle, Queen. Point to Point and in here, first of all we're going to see see log and point scored. Then we need to increment score. So score plus class. And in here when we actually die alone and do it safely cc log. For this we're going to go through the total score that the player has obtained for the course of the game.
And we'll specify the score variable. So now if we run this the plan is we can go in between the pipes endpoints, and when we do an appoint score or A log appearing here as a school and when you die, your total score will be displayed in here. Click Play. Point scored. Yay. Okay, so I make this one as well and understand our purpose.
Now as you can see it scored four. And so yeah that is it really the reason they did to Khalid try to switch the scene twice it collided affably with the pipe and the grammar. That's not much of an issue. That's it for this tutorial. In the next part of this series, we're gonna be looking at implementing the game overseen. If you have any questions, feel free to message us or support us on our systems coda UK.
The email will be in the description. You can comment on this video or just directing messages via YouTube. The requirements for source code will also be in the description. And as usual, thanks for watching and I hope you have a great day.