pocket-friends/pocket_friends/surfaces/selection_info.py

64 lines
2.4 KiB
Python
Raw Normal View History

2023-05-15 00:24:57 -04:00
"""Module for selection info. Shows egg stats after an egg has been selected from the starting
screen. Contains the surface object to be rendered."""
2023-05-11 15:24:17 -04:00
import pygame
from pocket_friends.elements import sprites
from pocket_friends.elements import surface
2023-05-11 15:24:17 -04:00
class Surface(surface.GameSurface):
2023-05-15 01:04:45 -04:00
"""
Surface object for the selection info screen. Contains the selected egg, egg properties, and description in a
scrollable text box. Child class of surface.GameSurface.
"""
def __init__(self, game_res: tuple, resources_dir: str, game_fps: int, **kwargs: str):
"""
Create a selection info surface object.
Args:
game_res: The internal resolution of the surface.
resources_dir: The path of the game's main resource directory.
game_fps: How many frames per second the game will run at.
Keyword Args:
selected_egg: The egg that was selected by the previous screen.
"""
super().__init__(game_res, resources_dir, game_fps)
self._selected_egg = None
2023-05-11 15:24:17 -04:00
for key in kwargs.keys():
if key == 'selected_egg':
self._selected_egg = kwargs.get(key)
2023-05-11 15:24:17 -04:00
egg = sprites.SelectionEgg(self._selected_egg, resources_dir)
2023-05-11 15:24:17 -04:00
egg.rect.x = 8
egg.rect.y = 3
self._sprites.add(egg)
2023-05-11 15:24:17 -04:00
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))
2023-05-11 15:24:17 -04:00
def update(self):
2023-05-15 00:24:57 -04:00
"""
2023-05-15 01:04:45 -04:00
Draw objects on the screen and advance the surface logic by one frame; Handle user input.
2023-05-15 00:24:57 -04:00
"""
self.preprocess()
2023-05-11 15:24:17 -04:00
self._info_text.draw(self)
self._info_icons.draw(self)
2023-05-11 15:24:17 -04:00
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
2023-05-13 10:46:34 -04:00
if event.key == pygame.K_DOWN:
self._info_text.scroll_down()
2023-05-13 10:46:34 -04:00
if event.key == pygame.K_UP:
self._info_text.scroll_up()
2023-05-13 10:46:34 -04:00
if event.key == pygame.K_a:
2023-05-12 17:34:13 -04:00
self.running = False
self.additional_args = {'selected_color': self._selected_egg}
2023-05-12 17:34:13 -04:00
self.next_surface = 'playground'
2023-05-13 10:46:34 -04:00
if event.key == pygame.K_b:
2023-05-11 15:24:17 -04:00
self.running = False
self.additional_args = {'selected_color': self._selected_egg}
2023-05-11 15:24:17 -04:00
self.next_surface = 'egg_select'