1 00:00:00,930 --> 00:00:02,720 Hi, welcome back. 2 00:00:03,210 --> 00:00:12,550 In this lecture, we will learn how to create game loop with by game imported and initialised that display 3 00:00:12,570 --> 00:00:17,060 set and the game surface being updated. 4 00:00:17,400 --> 00:00:21,440 We can start working on our main game loop. 5 00:00:22,080 --> 00:00:26,550 We will create a wide loop that runs the game. 6 00:00:27,330 --> 00:00:38,070 The loop will call the volume value of true meaning that the loop will loop forever unless it is disrupted. 7 00:00:38,430 --> 00:00:48,960 Within this main game loop of our program or our game, we will contract for Loop to iterate through 8 00:00:49,200 --> 00:00:59,430 the player events within the event queen, which will be called by the following action by game. 9 00:00:59,440 --> 00:01:01,320 Don't even get this. 10 00:01:01,320 --> 00:01:11,880 Well, get the events that take place in the back end of our game or the program, as you see. 11 00:01:15,290 --> 00:01:23,960 Event and the event and the event and even for events that doesn't be shown to the players or the users 12 00:01:24,260 --> 00:01:32,800 of our program or game, now we will add our game loop as the following after removing by game that 13 00:01:32,810 --> 00:01:41,020 event that get while through column enter for event and by game and event doget method. 14 00:01:41,360 --> 00:01:50,450 At this point, we have nothing within the for loop, but we can add Brent statement to show that the 15 00:01:50,450 --> 00:01:52,220 code is running correctly. 16 00:01:52,520 --> 00:01:58,400 We will pass the events iteration and to the statement as Trent. 17 00:01:58,400 --> 00:02:07,400 Even so, while true for column to run the code correctly, we must restart our current and run all 18 00:02:07,400 --> 00:02:11,450 of the tests again to avoid errors. 19 00:02:12,460 --> 00:02:22,480 As you see, the could run correctly and the event, so in the back end, when we run the file and it 20 00:02:22,480 --> 00:02:30,970 handed by 600 went to pop up to test the events, you can mouse over the window and the click within 21 00:02:30,970 --> 00:02:35,250 the window and press the keys on the keyboard. 22 00:02:35,320 --> 00:02:39,130 These events will be sent out to our council. 23 00:02:39,730 --> 00:02:41,530 You can stop this. 24 00:02:42,380 --> 00:02:50,220 Endless loop by clicking on control policy, see, now you can delete the print function. 25 00:02:50,360 --> 00:02:58,140 We don't need that as we pretty to ensure that our program is running correctly. 26 00:02:58,250 --> 00:03:03,890 At this moment, we need to quit the game or the big game program. 27 00:03:04,280 --> 00:03:15,110 So we will use by game the quiet method or function which will exit the program since the players are 28 00:03:15,110 --> 00:03:18,810 in control of game functionality and events. 29 00:03:18,830 --> 00:03:30,020 We should also note that by game, not get a sent to the event queen when the players or players have 30 00:03:30,020 --> 00:03:35,750 requested the program to shut down by clicking on the X in the game. 31 00:03:35,780 --> 00:03:43,130 When those other corners lets us start controlling the program's flow with a condition after statement 32 00:03:43,160 --> 00:03:46,020 within the event handling for loop. 33 00:03:46,250 --> 00:03:52,040 So if even the time doesn't equal quite in our case. 34 00:03:52,760 --> 00:03:53,330 Gholam. 35 00:03:54,760 --> 00:03:56,160 By game, not quite. 36 00:03:56,860 --> 00:04:06,310 And this quote, we saying that if the player has requested the program to shut down the program, should 37 00:04:06,310 --> 00:04:18,310 initializing the pygame module with zappy game don't quit and exist the big game with get this error 38 00:04:18,430 --> 00:04:22,760 because we didn't import by game that local. 39 00:04:22,840 --> 00:04:31,480 So we will import it now as we can to use by a game that quitte method, which is a part of my game, 40 00:04:31,480 --> 00:04:32,330 not local. 41 00:04:32,440 --> 00:04:40,990 So from my game that locales import Asterix and run all the cells again and complete the statement inside 42 00:04:40,990 --> 00:04:49,570 the follow as the following f even the type assigned to quote in our case, or even the type that will 43 00:04:49,570 --> 00:04:54,460 equal K down in our case and into parentheses. 44 00:04:54,790 --> 00:05:06,070 Even the K Dobbyn equals K underscore escape or event dot k equal k underscore Q and close the first 45 00:05:06,070 --> 00:05:12,680 parentheses and second parentheses column by game to quit, then quit. 46 00:05:12,700 --> 00:05:20,650 Notice that avoids identies and error and cites the F statement inside the fold and we run the code 47 00:05:20,950 --> 00:05:34,630 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 48 00:05:34,630 --> 00:05:43,900 by using X in the upper corner of the game window or using using Q or escape K and the keyboard to close 49 00:05:43,900 --> 00:05:44,440 the game. 50 00:05:44,740 --> 00:05:54,910 After we exit the game using the X or Q or escape games, we get a message that our candidate is started 51 00:05:54,910 --> 00:06:02,770 and the video not initialized or video system is not initialized and we can improve our code by using 52 00:06:02,770 --> 00:06:12,910 a function and name it, for example, event underscore handler and edit the for loop inside it and 53 00:06:13,120 --> 00:06:23,470 get it outside of the Y loop, then call it inside the loop, add the following year, even underscore 54 00:06:23,470 --> 00:06:28,780 handler and inside the function we will add Zabar. 55 00:06:29,050 --> 00:06:38,860 The whole of Falu call this function inside the loop and move another part inside the loop. 56 00:06:38,860 --> 00:06:42,460 Pygame the display update and move the game. 57 00:06:42,850 --> 00:06:45,070 Underscore display variable. 58 00:06:46,150 --> 00:06:55,930 And declare it and assign it to the whites and the height of our screen display before the event handler 59 00:06:55,930 --> 00:07:05,630 and run our code again, it will run correctly and successfully and add another line of code by a game 60 00:07:05,630 --> 00:07:15,160 to display that set caption not mood under score caption and between two parentheses and two saying 61 00:07:15,160 --> 00:07:15,730 the codes. 62 00:07:16,060 --> 00:07:22,890 My game as a title will appear in the window in the upper part of the window. 63 00:07:23,110 --> 00:07:23,800 My game. 64 00:07:24,400 --> 00:07:34,180 OK, now we have a clean code of our game or our first game as a black screen, and in the next section 65 00:07:34,180 --> 00:07:40,830 we will learn how to add game assets, game sounds and form using pygame module. 66 00:07:40,870 --> 00:07:48,440 The next section we will learn how to use by game to create full games like love or ping pong and more. 67 00:07:48,790 --> 00:07:51,930 At this point we reach the end of this lecture. 68 00:07:52,480 --> 00:07:55,200 Hope we enjoyed this lecture and get all of that. 69 00:07:55,490 --> 00:07:58,150 Thanks for being here and thanks for watching. 70 00:07:58,390 --> 00:08:00,340 See you next section.