marked attributes of a few classes as protected

This commit is contained in:
Nicholas Dyer 2023-05-15 00:26:44 -04:00
parent f765bb3dcb
commit 30e25999c4
4 changed files with 28 additions and 33 deletions

View File

@ -29,17 +29,18 @@ class GameSurface(pygame.Surface):
game_fps: How many frames per second the game will run at.
"""
super().__init__(game_res, pygame.SRCALPHA)
self.running = True
self.running = True # Surfaces should be running by default
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
self.bg = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha()
self.sprites = pygame.sprite.Group()
self.background = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha()
self._clock = pygame.time.Clock()
self._input_handler = InputHandler(self._clock)
self._sprites = pygame.sprite.Group()
def preprocess(self):
"""
@ -47,12 +48,11 @@ class GameSurface(pygame.Surface):
"""
self._clock.tick(self.game_fps)
self.blit(self.bg, (0, 0))
self.sprites.update()
self.sprites.draw(self)
self.blit(self.background, (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

View File

@ -48,7 +48,7 @@ class Surface(surface.GameSurface):
egg.rect.y = y
# Add the egg to the sprite list.
self.sprites.add(egg)
self._sprites.add(egg)
self.selected_egg = 0
self.selected_color = ''

View File

@ -10,23 +10,18 @@ class Surface(surface.GameSurface):
def __init__(self, game_res, resources_dir, game_fps, **kwargs):
super().__init__(game_res, resources_dir, game_fps)
preselected_color = None
for key in kwargs.keys():
if key == 'selected_color':
preselected_color = kwargs.get(key)
self.selected_egg = None
self._selected_egg = None
for key in kwargs.keys():
if key == 'selected_egg':
self.selected_egg = kwargs.get(key)
self._selected_egg = kwargs.get(key)
egg = sprites.SelectionEgg(self.selected_egg, resources_dir)
egg = sprites.SelectionEgg(self._selected_egg, resources_dir)
egg.rect.x = 8
egg.rect.y = 3
self.sprites.add(egg)
self._sprites.add(egg)
self.info_text = sprites.InfoText(resources_dir, game_res[0], egg.description)
self.info_icons = sprites.EggInfo(resources_dir, egg.contentedness, egg.metabolism, (32, 4))
self._info_text = sprites.InfoText(resources_dir, game_res[0], egg.description)
self._info_icons = sprites.EggInfo(resources_dir, egg.contentedness, egg.metabolism, (32, 4))
def update(self):
"""
@ -34,22 +29,22 @@ class Surface(surface.GameSurface):
"""
self.preprocess()
self.info_text.draw(self)
self.info_icons.draw(self)
self._info_text.draw(self)
self._info_icons.draw(self)
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
# Scroll down on the info screen.
self.info_text.scroll_down()
self._info_text.scroll_down()
if event.key == pygame.K_UP:
# Scroll up on the info screen.
self.info_text.scroll_up()
self._info_text.scroll_up()
if event.key == pygame.K_a:
self.running = False
self.additional_args = {'selected_color': self.selected_egg}
self.additional_args = {'selected_color': self._selected_egg}
self.next_surface = 'playground'
if event.key == pygame.K_b:
self.running = False
self.additional_args = {'selected_color': self.selected_egg}
self.additional_args = {'selected_color': self._selected_egg}
self.next_surface = 'egg_select'

View File

@ -18,19 +18,19 @@ class Surface(surface.GameSurface):
super().__init__(game_res, resources_dir, game_fps)
self.frames = 0
self.delay = 1
self._frames = 0
self._delay = 1
self.title = pygame.image.load(resources_dir + '/images/title.png').convert_alpha()
self._title = pygame.image.load(resources_dir + '/images/title.png').convert_alpha()
def update(self):
"""
Advance the surface logic by one frame.
"""
self.preprocess()
self.blit(self.title, (0, 0))
self.blit(self._title, (0, 0))
self.frames += 1
if self.frames > self.game_fps * self.delay:
self._frames += 1
if self._frames > self.game_fps * self._delay:
self.next_surface = 'egg_select'
self.running = False