1️⃣

1.1 - The Game Loop

The Game Loop

The game loop is the most important part of a game. We will be going over the parts shown below.
notion image
As you can see, the game loop revolves around 3 main parts: handling events, updating the game state, and drawing the screen

Update Game State

Updating the game state means specifying which part of the game the player is currently in. This could be states like “paused”, “menu”, or “playing”.
Example: In the next chapter's basic application (
2️⃣
2.2 - Basic Application
), we set the game state of “run” to true and execute the game loop until “run” becomes false.

Draw Screen

Drawing the screen means updating the window (or printing to the console) to display the current events in the game.
Example: In the next chapter's comprehensive example (
5️⃣
2.5 - Example
), we use pygame.display.update() to update the display to show the movement of the rectangle.

Handle Events

Finally, the third component in the game loop is handling events. This means taking in user input and handling them accordingly.
Example: In the next chapter's basic application (
2️⃣
2.2 - Basic Application
), we check for the pygame.QUIT event. If this event had occurred, we’d exit out of the game loop.

Next Section

2️⃣
1.2 - Example
 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.