2023-05-11 15:24:17 -04:00
|
|
|
import pygame
|
2023-05-12 11:44:58 -04:00
|
|
|
from ..elements import sprites
|
2023-05-11 17:59:06 -04:00
|
|
|
import pocket_friends.game_files.io.gpio_handler as gpio_handler
|
|
|
|
from ..io.input_handler import InputHandler
|
2023-05-11 15:24:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Surface(pygame.Surface):
|
2023-05-12 11:20:00 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
"""
|
2023-05-11 15:24:17 -04:00
|
|
|
def __init__(self, window_size, resources_dir, game_fps, **kwargs):
|
2023-05-12 11:20:00 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
|
|
|
window_size:
|
|
|
|
resources_dir:
|
|
|
|
game_fps:
|
|
|
|
**kwargs:
|
|
|
|
"""
|
2023-05-11 15:24:17 -04:00
|
|
|
super().__init__(window_size, pygame.SRCALPHA)
|
|
|
|
self.name = 'selection_info'
|
|
|
|
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.bg = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha()
|
|
|
|
self.sprites = pygame.sprite.Group()
|
|
|
|
|
|
|
|
self.selected_egg = None
|
|
|
|
for key in kwargs.keys():
|
|
|
|
if key == 'selected_egg':
|
|
|
|
self.selected_egg = kwargs.get(key)
|
|
|
|
|
|
|
|
egg = sprites.SelectionEgg(self.selected_egg, resources_dir)
|
|
|
|
egg.rect.x = 8
|
|
|
|
egg.rect.y = 3
|
|
|
|
self.sprites.add(egg)
|
|
|
|
|
|
|
|
self.info_text = sprites.InfoText(resources_dir, window_size[0], egg.description)
|
|
|
|
self.info_icons = sprites.EggInfo(resources_dir, egg.contentedness, egg.metabolism, (32, 4))
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.clock.tick(self.game_fps)
|
|
|
|
|
|
|
|
self.blit(self.bg, (0, 0))
|
|
|
|
self.sprites.update()
|
|
|
|
self.sprites.draw(self)
|
|
|
|
self.info_text.draw(self)
|
|
|
|
self.info_icons.draw(self)
|
|
|
|
|
|
|
|
self.input_handler.update()
|
|
|
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.KEYDOWN:
|
2023-05-11 17:59:06 -04:00
|
|
|
if event.key == gpio_handler.BUTTONS.get('j_d'):
|
2023-05-11 15:24:17 -04:00
|
|
|
# Scroll down on the info screen.
|
|
|
|
self.info_text.scroll_down()
|
2023-05-11 17:59:06 -04:00
|
|
|
if event.key == gpio_handler.BUTTONS.get('j_u'):
|
2023-05-11 15:24:17 -04:00
|
|
|
# Scroll up on the info screen.
|
|
|
|
self.info_text.scroll_up()
|
2023-05-11 17:59:06 -04:00
|
|
|
if event.key == gpio_handler.BUTTONS.get('a'):
|
2023-05-12 17:34:13 -04:00
|
|
|
self.running = False
|
|
|
|
self.additional_args = {'selected_color': self.selected_egg}
|
|
|
|
self.next_surface = 'playground'
|
2023-05-11 17:59:06 -04:00
|
|
|
if event.key == gpio_handler.BUTTONS.get('b'):
|
2023-05-11 15:24:17 -04:00
|
|
|
self.running = False
|
|
|
|
self.additional_args = {'selected_color': self.selected_egg}
|
|
|
|
self.next_surface = 'egg_select'
|