Game Programming Basics
I had purchased a book that had two parts: (1) Python programming and (2) Python projects. By now I had learned enough Python basics. So I only needed ideas for interesting programs to write. I jumped right into the projects section of the book with enthusiasm.
The projects were split into three sections. The first section was Python game programming with the pygame module. I was annoyed that the example game code resulted in a game window that stuck around, even when the program had ended. WTF?
Again, I had previously done some Python learning. This included pygame. The missing part was the call to shut down the pygame game engine. Here is the code required to do so, in context:
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
I highlighted the key function call in red. That will allow an orderly shutdown of your game. Not sure why the book I was reading did not cover that. Still, I ended up motivated to create a small space invaders clone. It was not polished. But at least the game play looked good and worked. Here is a peek: