pocket-friends/pocket_friends/game_files/surfaces/selection_info.py

72 lines
2.4 KiB
Python
Raw Normal View History

2023-05-11 15:24:17 -04:00
import pygame
from ..elements import sprites
from ..io.input_handler import InputHandler
2023-05-11 15:24:17 -04:00
class Surface(pygame.Surface):
"""
"""
2023-05-11 15:24:17 -04:00
def __init__(self, window_size, resources_dir, game_fps, **kwargs):
"""
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-13 10:46:34 -04:00
if event.key == pygame.K_DOWN:
2023-05-11 15:24:17 -04:00
# Scroll down on the info screen.
self.info_text.scroll_down()
2023-05-13 10:46:34 -04:00
if event.key == pygame.K_UP:
2023-05-11 15:24:17 -04:00
# Scroll up on the info screen.
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}
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}
self.next_surface = 'egg_select'