Hi, welcome back.
In this video, we will learn how to add school to our game.
Flappy Bird clone.
So we will add a score variable to be called score equals zero as the volume and also add another variable
called high score and assign it to an ensure value equal zero.
So the score and the high school of the Flappy Bird game will start at zero value.
Now we will add techies in our game using pygame, python module and the next three major steps, the
first step to create the font style and size.
So we will determine the style and the size of the game text font.
Then the second step to render font using text and color method of the bi game module.
Finally, we will use the resulting text as a text service.
So font equal pygame.
The font dot font with capital F.
Between two parentheses style and size, font style is a reality free, downloaded font style called
Evil Empire Days for the week between two.
Singer called Coma the size is 50, then we will create a function to display score called display underscore
function as the following.
So yes, this delay underscore this call to empty parentheses of the function, then column.
Then inside the function we will assign a new variable called score underscore sull.
Which.
A shortcut for score underscore.
Service.
Ekwall game and the score from the trender between two parentheses string of score.
And the true and the color of.
The phone, so we will choose the right color.
Which is a table of three values, two hundred fifty five comma, two hundred fifty five comma, two
hundred fifty five, then close to parentheses of the render method.
So we use three parameters in the render method, the first parameter, which is for which we use to
be accepted by the end of the VI game by some module.
And the two refers to actualizing of the phone and the table of three values refers to the white color
of our text or phone text so you can use different values to get different colors for the phone text.
But we will use the white color in this game for the school and to add the surface to the screen.
We will use a rectangle around this as we use and get around there and pi.
And we do that to make it easy to add this font exactly in the middle of our game display.
So score underscore rectangle equal score underscore service dot get underscore recht between two parentheses
center equal a table of two values, one hundred forty three comma and one handwrite.
OK then we can use this font rectangle to end the font tickets to our game, display our game screen
as the following.
So.
Game underscored is the belt between two parentheses score and the score, sir, or service comma is
called Underscore Rectangle.
Finally, we can call that this delay underscore its core function.
Inside our game loop the following, so display underscore.
Two empty parentheses added to the game loop, then buried our project and we get an error.
This error will be solved with the following, we forget to add to F.
Font file extension, so we will add it to correctly load our.
Font file So we get another error and build our product again and we will get another error, this error
day there too, we use game underscore font instead of font.
So we will change that to fund the Trenta, OK, and build our project again and see if it done correctly.
It will run correctly with the score appears on the top of our game display or our game screen.
Now we want to update this zero score to be increased by the player achievement.
Now we will adjust the size of our.
Font as a photo to be 35 instead of 50, then build our project again to see the new size of our phone
ticket and it's OK for the size of our screen, not too big or too small.
Now we will adjust.
The position of this school is the following by using the value of y axis to be to be thirty instead
of one hundred and build our project again to see the evolution of our school.
And it's perfect for our game display and the game screen, as you see.
So we will update the display, underscore its core function as the following users rank four main method
inside the font that render method as the following.
So f single core strength three into parentheses score close the single quote, then comma then true,
then y values inside the table of three items and inside the four main function.
We will add score with capital s column, then string score between two parentheses, then add to curly
brackets and instead of string score as the following.
Then after the second single could not score, this will update always the score inside the string function
or use the second shape of the string for me function to avoid errors when we want to run or build our
Brossette, as you see between single code score with capital s column, then two empty curly brackets.
Not for me, OK, and between two parentheses of the formate function, we add score variable.
Then we build our project, see if we have other errors, and after we build our project, we get another
day or two.
We forget to close the second parentheses of the random, so we will add the second parentheses as the
following and add string score to avoid any errors and run our project again.
And our game runs perfect without any errors.
But we need to increase the score by the achievements of the players.
So let's do that for now.
I will close the game window and we can update the zero score to be increased by the player achievement
in the game loop all the while loop of our code inside the F game underscore on statement we will add
after show by its score plus equal zero point zero one and we will build our project again to run our
game and see if the score updating from zero eight updating partnership of offload value.
So we will change the score.
The last equal entry into parentheses 0.01 and build our project again to see if this problem has been
solved.
And after building the project, we observed that the school is not updating, so we will return the
score value as it was then.
Then change it from the score.
Plus equal 0.01 to score plus equals one and build our project and we see that the score is updating
very quickly.
The question now is how we can updating our score appropriately and adjust this very quick updating
of the score.
We will add and to the four main function inside the font that render method the following, so not
for me between two parentheses string.
Then inside the two branches of the screening function, we will add in between two parents, as is
the school, then returned to the school inside game on the school, on statement to be scored plus
equal or boy or one world out project again to observe our school, which will updating correctly and
effectively for our game.
So everybody the player cross without collusion with the school is updating.
And we observe also that our school needed to be revisited after every collision of the bird with the
game object.
So we can do that and we can do that by adding an a statement inside our display underscore function
as the following.
So inside the function we will end a game on.
To underscore on Columbo, these three lines of code inside the function, to be inside the statement
and add and Elif statement as follows.
So L.F. game on game underscore on the Blackwall Foles column, then Cobbe the three lines inside the
first if statement inside this function, then add these three lines of code inside the ELIF statement
double times the first three lines of code for the score and the second three lines of code or the second
time for the high school.
So we will change all the school and the second time from school to high school as you see it, change
the F game on the on column kento f game equal between two parentheses game underscore on and also ayliffe
game equal game over between two parentheses also and we will head over to the while loop or the game
loop to change something.
Add the following change.
The parameters of the display underscore is called function from empty parameter to between two parentheses.
And between two things, the Colts game on, then Ed and L's statement after this F game on a statement
as the volume so else this play underscore its core function between two parentheses and two single
quotes game underscore over.
So if the game is on, the display is called function will display the school and else game is over.
The display on the school function well.
Display the score and the high school.
Now we need to adjust the possession of our high school as a follow and we will change it from 30 to
one hundred and build our project again.
And we get an air of.
Due to missing column of the F statement F game with equal between two parentheses game on, we add
the missing column, then build our project again and we get another error, which is due to missing
parameters, and that is delay, underscore function.
We have a type error, which is this.
Bedier underscore function takes zero positional arguments, but we add.
One argument or one parameter inside the method of the function, so we will return to the function
and add this parameter as the volume, so the function parameter or argument will be the gain and build
our project again.
It run correctly without any errors.
And also we get that set of the scope, as you see.
But the high score is not found at the game over screen.
As you see, we can solve this problem by adding a new function called high score update function.
So Def High, underscore the score, underscore the between two parentheses the score comma high score
then column.
Then inside this function we will add in every statement as the following.
So if it's more than high, underscore the score goal, then high on those core score equals score.
Then return high, underscore school, then inside the game loop all the while loop, we will call this
function high school update or else column before the display underscore the school method.
We will add high underscore equal high school update function between two parentheses school and the
high school.
We will head to the high school service and the change the school to high school and the for me and
re-enter function so high on the school school.
Underscore of a call from the trender between two parentheses and two single quotes.
High school inside the four main function instead of school and inside the game underscore display the
belet method.
We will add high, underscore the school and the school service and.
High school rectangle instead of a school rectangle, then we will build our project again and our game
runs perfectly, but the score is the same as the high school.
So we want to reset the score every time we play the game and the game over the screen or background.
So we will head over the statement in the while loop or the game loop then and the score equal zeal
to reset the score at the game over screen or background.
So and we will our goes back again to see if this error have been solved or not.
And we observe that there have been solved and everything is OK and the school and high school are perfectly
showing on the game over screen at this point, we reached the end of this lecture.
I hope you enjoyed this lecture and get all of that.
Thanks for watching and thanks for being here.
See you next with you.