Advertisement
carlosmfp

Debugging Class for pygame

Sep 15th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | Source Code | 0 0
  1. import pygame as pg
  2.  
  3. class Debug:
  4.     def __init__(self, info: str='None', x: int=15, y: int=15,  **kwargs):
  5.         self.font_color: str | tuple[int, int, int] = kwargs.get('font_color', 'black')
  6.         self.bg_color: str | tuple[int, int, int] = kwargs.get('bg_color', 'white')
  7.         self.info: str = info
  8.         self.display_surface: pg.Surface = pg.display.get_surface()
  9.  
  10.         self.font: pg.Font = pg.font.Font(None, 30)
  11.         self.image: pg.Surface = self._render_image()
  12.         self.rect: pg.Rect = self.image.get_rect(topleft=(x, y))
  13.         pg.draw.rect(self.display_surface, self.bg_color, self.rect, width=0)
  14.    
  15.     def draw(self, *args, **kwargs):
  16.         self.update(*args, **kwargs)
  17.         self.display_surface.blit(self.image, self.rect)
  18.  
  19.     def update(self, *args, **kwargs):
  20.         if 'info' in kwargs:
  21.             self.info = kwargs['info']
  22.             self.image = self._render_image()
  23.  
  24.     def _render_image(self):
  25.         return self.font.render(str(self.info), True, self.font_color)
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement