pygame_terminal_ii
This is an old revision of the document!
Table of Contents
Pygame Terminal II
- A more advanced version of Pygame Terminal
About
In Pygame Terminal we discussed a very basic kind of game terminal. This can be used to create many kinds of games such as the Robots game.
However, we may like to increase the functionality of this framework by adding a few quality of life features.
Pygame Terminal Major Changes
The first major change is in the Game class draw loop. The first part of the Game class now looks like this:
class Game: def __init__(self, window): self.window = window self.screen = window.screen self.font = window.font self.logo = window.logo # Game Data self.FPS = 60 self.clock = pygame.time.Clock() self.maze = Maze(19, 14, 30, 30) self.maze.set_wall(3,3, "south", False) self.maze.cwidth = 40 self.maze.cheight = 40 def start(self): while True: self.checkEvents() self.update() self.draw() self.clock.tick(self.FPS) def update(self): pass def draw(self): self.screen.fill((0, 0, 0)) # Clear the screen. self.maze.draw(self.screen) pygame.display.flip() # update the display. def quit(self): quit() exit()
As you can see we have moved to using self.clock.tick(self.FPS), and have split the check events and update loops. We will also add a quit function. The quit function will have more importance later, such as if we need to save game state when exiting.
pygame_terminal_ii.1699230723.txt.gz · Last modified: 2023/11/06 00:32 by appledog