pocket-friends/pocket_friends/elements/surface.py

53 lines
2.0 KiB
Python
Raw Normal View History

"""Module to aid in the drawing of surfaces to make switching from one screen to another easier."""
import pygame
from ..io.input_handler import InputHandler
class GameSurface(pygame.Surface):
"""
Class to be used as the backbone of all game surfaces.
Attributes:
running (bool): Boolean to tell whether the surface is running or not.
next_surface (:obj:`str`): What the next surface should be after halting.
resource_dir (:obj:`str`): The path of the game's main resource directory.
game_fps (int): How many frames per second the game will run at.
additional_args (dict): Additional arguments to send to the next surface after halting.
2023-05-14 17:47:56 -04:00
bg (:obj:`pygame.Surface`): The background of the surface.
"""
def __init__(self, game_res, resources_dir, game_fps):
"""
Create a GameSurface object.
Args:
game_res (int): The internal resolution of the surface.
resources_dir (:obj:`str`): The path of the game's main resource directory.
game_fps: (int): How many frames per second the game will run at.
"""
super().__init__(game_res, pygame.SRCALPHA)
self.running = True
self.next_surface = None
self.resource_dir = resources_dir
self._clock = pygame.time.Clock()
self.game_fps = game_fps
self._input_handler = InputHandler(self._clock)
self.additional_args = {}
self.dev_override = False
2023-05-14 17:47:56 -04:00
self.bg = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha()
self.sprites = pygame.sprite.Group()
def preprocess(self):
"""
Advance the surface by one frame and draw the background.
"""
self._clock.tick(self.game_fps)
2023-05-14 17:47:56 -04:00
self.blit(self.bg, (0, 0))
self.sprites.update()
self.sprites.draw(self)
self._input_handler.update()
if self._input_handler.dev_found:
self.next_surface = 'dev_menu'
self.dev_override = True
self.running = False