pygame setup

Getting started with a game.

Example event-driven program using pygame

We’ll have some fun by creating a very simple game using the pygame library. Our example program comes from a very excellent YouTube tutorial called “The Ultimate introduction to Pygame” by Clear Code. I highly recommend his channel as his tutorials are clear and to the point.

We will implement the code as in his tutorial, but we will re-design the code by applying the rules above. His code works just fine, but our re-design will help improve the understandability, maintainability, efficiency, and robustness of the software.

Setup

  1. Open a Terminal and use cd to get into your seng-201 directory.
  2. Run the command git clone https://github.com/UNCW-SENG/pygame-design. This will create a subdirectory named pygame-design.
  3. Open PyCharm. Go through the menus: File -> Open. Find and open the pygame-design/ folder, then hit the Open button. You should see the following structure:
    It is essential that the root folder is pygame-design/
  4. Click in the bottom right of your PyCharm window where it either says Add interpreter... or Python 3.x (something).
  5. Then select Add Interpreter -> Add Local Interpreter. You should see something similar to the following:
  6. Make sure Generate New is selected. The pre-populated location should be fine. Then hit OK.
  7. Open the Integrated Terminal in PyCharm. Type the command pip install pygame to download the pygame library.
  8. Open runner.py and run it. A black screen should pop-up and you should see Hello from the pygame community in the integrated Terminal.

You should now be good to go.

Class recording

Code at the end

You must have cloned the project from the setup section. Here is the code at the end of class:

Last modified October 28, 2025.