marked attributes of a few classes as protected
This commit is contained in:
parent
f765bb3dcb
commit
30e25999c4
@ -29,17 +29,18 @@ class GameSurface(pygame.Surface):
|
|||||||
game_fps: How many frames per second the game will run at.
|
game_fps: How many frames per second the game will run at.
|
||||||
"""
|
"""
|
||||||
super().__init__(game_res, pygame.SRCALPHA)
|
super().__init__(game_res, pygame.SRCALPHA)
|
||||||
self.running = True
|
self.running = True # Surfaces should be running by default
|
||||||
self.next_surface = None
|
self.next_surface = None
|
||||||
self.resource_dir = resources_dir
|
self.resource_dir = resources_dir
|
||||||
self._clock = pygame.time.Clock()
|
|
||||||
self.game_fps = game_fps
|
self.game_fps = game_fps
|
||||||
self._input_handler = InputHandler(self._clock)
|
|
||||||
self.additional_args = {}
|
self.additional_args = {}
|
||||||
self.dev_override = False
|
self.dev_override = False
|
||||||
|
|
||||||
self.bg = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha()
|
self.background = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha()
|
||||||
self.sprites = pygame.sprite.Group()
|
|
||||||
|
self._clock = pygame.time.Clock()
|
||||||
|
self._input_handler = InputHandler(self._clock)
|
||||||
|
self._sprites = pygame.sprite.Group()
|
||||||
|
|
||||||
def preprocess(self):
|
def preprocess(self):
|
||||||
"""
|
"""
|
||||||
@ -47,12 +48,11 @@ class GameSurface(pygame.Surface):
|
|||||||
"""
|
"""
|
||||||
self._clock.tick(self.game_fps)
|
self._clock.tick(self.game_fps)
|
||||||
|
|
||||||
self.blit(self.bg, (0, 0))
|
self.blit(self.background, (0, 0))
|
||||||
self.sprites.update()
|
self._sprites.update()
|
||||||
self.sprites.draw(self)
|
self._sprites.draw(self)
|
||||||
|
|
||||||
self._input_handler.update()
|
self._input_handler.update()
|
||||||
if self._input_handler.dev_found:
|
if self._input_handler.dev_found:
|
||||||
self.next_surface = 'dev_menu'
|
|
||||||
self.dev_override = True
|
self.dev_override = True
|
||||||
self.running = False
|
self.running = False
|
||||||
|
@ -48,7 +48,7 @@ class Surface(surface.GameSurface):
|
|||||||
egg.rect.y = y
|
egg.rect.y = y
|
||||||
|
|
||||||
# Add the egg to the sprite list.
|
# Add the egg to the sprite list.
|
||||||
self.sprites.add(egg)
|
self._sprites.add(egg)
|
||||||
|
|
||||||
self.selected_egg = 0
|
self.selected_egg = 0
|
||||||
self.selected_color = ''
|
self.selected_color = ''
|
||||||
|
@ -10,23 +10,18 @@ class Surface(surface.GameSurface):
|
|||||||
def __init__(self, game_res, resources_dir, game_fps, **kwargs):
|
def __init__(self, game_res, resources_dir, game_fps, **kwargs):
|
||||||
super().__init__(game_res, resources_dir, game_fps)
|
super().__init__(game_res, resources_dir, game_fps)
|
||||||
|
|
||||||
preselected_color = None
|
self._selected_egg = None
|
||||||
for key in kwargs.keys():
|
|
||||||
if key == 'selected_color':
|
|
||||||
preselected_color = kwargs.get(key)
|
|
||||||
|
|
||||||
self.selected_egg = None
|
|
||||||
for key in kwargs.keys():
|
for key in kwargs.keys():
|
||||||
if key == 'selected_egg':
|
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.x = 8
|
||||||
egg.rect.y = 3
|
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_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_icons = sprites.EggInfo(resources_dir, egg.contentedness, egg.metabolism, (32, 4))
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""
|
"""
|
||||||
@ -34,22 +29,22 @@ class Surface(surface.GameSurface):
|
|||||||
"""
|
"""
|
||||||
self.preprocess()
|
self.preprocess()
|
||||||
|
|
||||||
self.info_text.draw(self)
|
self._info_text.draw(self)
|
||||||
self.info_icons.draw(self)
|
self._info_icons.draw(self)
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_DOWN:
|
if event.key == pygame.K_DOWN:
|
||||||
# Scroll down on the info screen.
|
# Scroll down on the info screen.
|
||||||
self.info_text.scroll_down()
|
self._info_text.scroll_down()
|
||||||
if event.key == pygame.K_UP:
|
if event.key == pygame.K_UP:
|
||||||
# Scroll up on the info screen.
|
# Scroll up on the info screen.
|
||||||
self.info_text.scroll_up()
|
self._info_text.scroll_up()
|
||||||
if event.key == pygame.K_a:
|
if event.key == pygame.K_a:
|
||||||
self.running = False
|
self.running = False
|
||||||
self.additional_args = {'selected_color': self.selected_egg}
|
self.additional_args = {'selected_color': self._selected_egg}
|
||||||
self.next_surface = 'playground'
|
self.next_surface = 'playground'
|
||||||
if event.key == pygame.K_b:
|
if event.key == pygame.K_b:
|
||||||
self.running = False
|
self.running = False
|
||||||
self.additional_args = {'selected_color': self.selected_egg}
|
self.additional_args = {'selected_color': self._selected_egg}
|
||||||
self.next_surface = 'egg_select'
|
self.next_surface = 'egg_select'
|
||||||
|
@ -18,19 +18,19 @@ class Surface(surface.GameSurface):
|
|||||||
|
|
||||||
super().__init__(game_res, resources_dir, game_fps)
|
super().__init__(game_res, resources_dir, game_fps)
|
||||||
|
|
||||||
self.frames = 0
|
self._frames = 0
|
||||||
self.delay = 1
|
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):
|
def update(self):
|
||||||
"""
|
"""
|
||||||
Advance the surface logic by one frame.
|
Advance the surface logic by one frame.
|
||||||
"""
|
"""
|
||||||
self.preprocess()
|
self.preprocess()
|
||||||
self.blit(self.title, (0, 0))
|
self.blit(self._title, (0, 0))
|
||||||
|
|
||||||
self.frames += 1
|
self._frames += 1
|
||||||
if self.frames > self.game_fps * self.delay:
|
if self._frames > self.game_fps * self._delay:
|
||||||
self.next_surface = 'egg_select'
|
self.next_surface = 'egg_select'
|
||||||
self.running = False
|
self.running = False
|
||||||
|
Loading…
Reference in New Issue
Block a user