Last Updated: September 29, 2021
·
420
· shakepen

Notes During the Study of Pygame

Hi this is my very first post and, more, importantly, I consider myself an advanced beginner which means if there is any mistake or dead end that I have walked in, please be an adviser. As you might also notice, I am not a native speaker, so bear with me.

I am using Pygame to make a complete version of Tetris. I think Pygame is a good library to study 2D object-oriented programming -- I don't know why (maybe because I study it?). However, I personally don't think it is going to be used in reality for developing real games

Okay, at least I think the event detection is fairly impressive. Yet, one thing that I am not familiar with it is that I don't know how to update a whole class, but whatever, please help.

From the two relatively official eBooks about Pygame and some so called online courses, I have learned that there are things to be done to make a event-driven software.

  1. set up global variables
  2. make helper functions
  3. make classes
  4. initialize the frame
  5. put everything into the frame
  6. run
  7. check events and play

Okay, it may looks frustrating because of my poor logic, but that's almost how a OO programming is done.

In my version of Tetris, I have three classes: Text, Block, Game.

The Text class is used to draw text or buttons on the surface. A Text object is sometimes pretending to be a button for selections in menu and the program checks events to redraw the text with the switch between text color which is white and background color which is black when not selected.

(To be continued if I can edit it. New to CoderWall)