2023-05-13 13:07:33 -04:00
|
|
|
"""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.
|
2023-05-13 13:07:33 -04:00
|
|
|
"""
|
|
|
|
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 = {}
|
2023-05-14 19:26:09 -04:00
|
|
|
self.dev_override = False
|
2023-05-13 13:07:33 -04:00
|
|
|
|
2023-05-14 17:47:56 -04:00
|
|
|
self.bg = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha()
|
2023-05-13 13:07:33 -04:00
|
|
|
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))
|
2023-05-13 13:07:33 -04:00
|
|
|
self.sprites.update()
|
|
|
|
self.sprites.draw(self)
|
|
|
|
|
|
|
|
self._input_handler.update()
|
2023-05-14 19:26:09 -04:00
|
|
|
if self._input_handler.dev_found:
|
|
|
|
self.next_surface = 'dev_menu'
|
|
|
|
self.dev_override = True
|
|
|
|
self.running = False
|