From fd7e1b7492c87b0d6a48b14b0b38b5acd4baa1d4 Mon Sep 17 00:00:00 2001 From: Nicholas Dyer Date: Thu, 11 May 2023 13:23:55 -0400 Subject: [PATCH] added eggs on selection screen with animations --- .../game_files/surfaces/egg_select.py | 39 +++++++++++++++++++ .../surfaces/{objects => }/sprites.py | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) rename pocket_friends/game_files/surfaces/{objects => }/sprites.py (96%) diff --git a/pocket_friends/game_files/surfaces/egg_select.py b/pocket_friends/game_files/surfaces/egg_select.py index 691276f..a7f2ff2 100644 --- a/pocket_friends/game_files/surfaces/egg_select.py +++ b/pocket_friends/game_files/surfaces/egg_select.py @@ -1,4 +1,5 @@ import pygame +from . import sprites class Surface(pygame.Surface): @@ -11,6 +12,44 @@ class Surface(pygame.Surface): self.bg = pygame.image.load(resources_dir + '/images/bg.png').convert_alpha() self.sprites = pygame.sprite.Group() + egg_list = [ + 'dev_egg', + 'blue', + 'rainbow' + ] + eggs = [] + for egg in egg_list: + eggs.append(sprites.SelectionEgg(egg, resources_dir)) + + eggs_per_row = 3 + distance_between_eggs = 36 / eggs_per_row + + # Count the total rows. + total_rows = -(-len(eggs) // eggs_per_row) + distance_between_rows = 32 / eggs_per_row + + # Determine the location of each egg. + for egg in eggs: + current_row = eggs.index(egg) // eggs_per_row + rows_after = total_rows - (current_row + 1) + egg_in_row = eggs.index(egg) % eggs_per_row + eggs_after = min(len(eggs) - (current_row * eggs_per_row), eggs_per_row) - (egg_in_row + 1) + + x_offset = 32 + y_offset = 30 + + # The x coordinate of an egg is determined by which egg in the row it is, and how many eggs + # are in that row. If there is only 1 egg in a row, it is in the middle of the screen. If + # there are two, they're on equal halves and so on. + x = x_offset - (eggs_after * distance_between_eggs) + (egg_in_row * distance_between_eggs) + y = y_offset - (rows_after * distance_between_rows) + (current_row * distance_between_rows) + + egg.rect.x = x + egg.rect.y = y + + # Add the egg to the sprite list. + self.sprites.add(egg) + def update(self): self.blit(self.bg, (0, 0)) self.sprites.update() diff --git a/pocket_friends/game_files/surfaces/objects/sprites.py b/pocket_friends/game_files/surfaces/sprites.py similarity index 96% rename from pocket_friends/game_files/surfaces/objects/sprites.py rename to pocket_friends/game_files/surfaces/sprites.py index 7ae91f2..d4f0f8d 100644 --- a/pocket_friends/game_files/surfaces/objects/sprites.py +++ b/pocket_friends/game_files/surfaces/sprites.py @@ -67,7 +67,7 @@ class SelectionEgg(pygame.sprite.Sprite): # Load the egg from the given color and get the bounding rectangle for the image. sprite_sheet = SpriteSheet(resources_dir + '/images/bloops/{0}/egg.png'.format(self.egg_color), - resources_dir + '/resources/images/bloops/{0}/egg.json'.format(self.egg_color)) + resources_dir + '/images/bloops/{0}/egg.json'.format(self.egg_color)) self.images = sprite_sheet.images # Get the rectangle from the first image in the list