added eggs on selection screen with animations
This commit is contained in:
parent
bbe97f0de7
commit
fd7e1b7492
@ -1,4 +1,5 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
from . import sprites
|
||||||
|
|
||||||
|
|
||||||
class Surface(pygame.Surface):
|
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.bg = pygame.image.load(resources_dir + '/images/bg.png').convert_alpha()
|
||||||
self.sprites = pygame.sprite.Group()
|
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):
|
def update(self):
|
||||||
self.blit(self.bg, (0, 0))
|
self.blit(self.bg, (0, 0))
|
||||||
self.sprites.update()
|
self.sprites.update()
|
||||||
|
@ -67,7 +67,7 @@ class SelectionEgg(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
# Load the egg from the given color and get the bounding rectangle for the image.
|
# 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),
|
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
|
self.images = sprite_sheet.images
|
||||||
|
|
||||||
# Get the rectangle from the first image in the list
|
# Get the rectangle from the first image in the list
|
Loading…
Reference in New Issue
Block a user