Hi, welcome back.
In this lecture, we will learn how to create game loop with by game imported and initialised that display
set and the game surface being updated.
We can start working on our main game loop.
We will create a wide loop that runs the game.
The loop will call the volume value of true meaning that the loop will loop forever unless it is disrupted.
Within this main game loop of our program or our game, we will contract for Loop to iterate through
the player events within the event queen, which will be called by the following action by game.
Don't even get this.
Well, get the events that take place in the back end of our game or the program, as you see.
Event and the event and the event and even for events that doesn't be shown to the players or the users
of our program or game, now we will add our game loop as the following after removing by game that
event that get while through column enter for event and by game and event doget method.
At this point, we have nothing within the for loop, but we can add Brent statement to show that the
code is running correctly.
We will pass the events iteration and to the statement as Trent.
Even so, while true for column to run the code correctly, we must restart our current and run all
of the tests again to avoid errors.
As you see, the could run correctly and the event, so in the back end, when we run the file and it
handed by 600 went to pop up to test the events, you can mouse over the window and the click within
the window and press the keys on the keyboard.
These events will be sent out to our council.
You can stop this.
Endless loop by clicking on control policy, see, now you can delete the print function.
We don't need that as we pretty to ensure that our program is running correctly.
At this moment, we need to quit the game or the big game program.
So we will use by game the quiet method or function which will exit the program since the players are
in control of game functionality and events.
We should also note that by game, not get a sent to the event queen when the players or players have
requested the program to shut down by clicking on the X in the game.
When those other corners lets us start controlling the program's flow with a condition after statement
within the event handling for loop.
So if even the time doesn't equal quite in our case.
Gholam.
By game, not quite.
And this quote, we saying that if the player has requested the program to shut down the program, should
initializing the pygame module with zappy game don't quit and exist the big game with get this error
because we didn't import by game that local.
So we will import it now as we can to use by a game that quitte method, which is a part of my game,
not local.
So from my game that locales import Asterix and run all the cells again and complete the statement inside
the follow as the following f even the type assigned to quote in our case, or even the type that will
equal K down in our case and into parentheses.
Even the K Dobbyn equals K underscore escape or event dot k equal k underscore Q and close the first
parentheses and second parentheses column by game to quit, then quit.
Notice that avoids identies and error and cites the F statement inside the fold and we run the code
and we get a blank screen can be closed by X or by Q or by Skip Gates so the user can close the game
by using X in the upper corner of the game window or using using Q or escape K and the keyboard to close
the game.
After we exit the game using the X or Q or escape games, we get a message that our candidate is started
and the video not initialized or video system is not initialized and we can improve our code by using
a function and name it, for example, event underscore handler and edit the for loop inside it and
get it outside of the Y loop, then call it inside the loop, add the following year, even underscore
handler and inside the function we will add Zabar.
The whole of Falu call this function inside the loop and move another part inside the loop.
Pygame the display update and move the game.
Underscore display variable.
And declare it and assign it to the whites and the height of our screen display before the event handler
and run our code again, it will run correctly and successfully and add another line of code by a game
to display that set caption not mood under score caption and between two parentheses and two saying
the codes.
My game as a title will appear in the window in the upper part of the window.
My game.
OK, now we have a clean code of our game or our first game as a black screen, and in the next section
we will learn how to add game assets, game sounds and form using pygame module.
The next section we will learn how to use by game to create full games like love or ping pong and more.
At this point we reach the end of this lecture.
Hope we enjoyed this lecture and get all of that.
Thanks for being here and thanks for watching.
See you next section.