pocket-friends/pocket_friends/surfaces/selection_info.py

50 lines
1.8 KiB
Python

import pygame
from pocket_friends.elements import sprites
from pocket_friends.elements import surface
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
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, game_res[0], egg.description)
self.info_icons = sprites.EggInfo(resources_dir, egg.contentedness, egg.metabolism, (32, 4))
def update(self):
self.preprocess()
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()
if event.key == pygame.K_UP:
# Scroll up on the info screen.
self.info_text.scroll_up()
if event.key == pygame.K_a:
self.running = False
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.next_surface = 'egg_select'