rearragned project, removed unneeded game_files folder

This commit is contained in:
2023-05-13 13:11:47 -04:00
parent 83a7e98a7f
commit 06755ee937
61 changed files with 10 additions and 9 deletions

View File

View File

@@ -0,0 +1,129 @@
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)
egg_list = [
'dev_egg',
'blue',
'rainbow'
]
self.eggs = []
for egg in egg_list:
self.eggs.append(sprites.SelectionEgg(egg, self.resource_dir))
self.eggs_per_row = 3
distance_between_eggs = 36 / self.eggs_per_row
# Count the total rows.
self.total_rows = -(-len(self.eggs) // self.eggs_per_row)
distance_between_rows = 32 / self.eggs_per_row
# Determine the location of each egg.
for egg in self.eggs:
current_row = self.eggs.index(egg) // self.eggs_per_row
rows_after = self.total_rows - (current_row + 1)
egg_in_row = self.eggs.index(egg) % self.eggs_per_row
eggs_after = min(len(self.eggs) - (current_row * self.eggs_per_row), self.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)
self.selected_egg = 0
self.selected_color = ''
if preselected_color is not None:
self.selected_color = self.eggs[self.selected_egg].egg_color
for i in range(len(self.eggs)):
if self.eggs[i].egg_color == preselected_color:
self.selected_egg = i
def get_cursor_coords(self):
"""
Gets the coordinates of an egg on the selection screen by index and returns it as a tuple
:return: tuple of the coordinates of the selected egg
"""
cursor_x_offset = -2
cursor_y_offset = -2
return (self.eggs[self.selected_egg].rect.x + cursor_x_offset,
self.eggs[self.selected_egg].rect.y + cursor_y_offset)
def sel_left(self):
"""
Select the egg to the left with constraints.
"""
if self.selected_egg % self.eggs_per_row != 0:
self.selected_egg -= 1
def sel_right(self):
"""
Select the egg to the right with constraints.
"""
row = self.selected_egg // self.eggs_per_row
eggs_in_row = min(len(self.eggs) - (row * self.eggs_per_row), self.eggs_per_row)
if self.selected_egg % self.eggs_per_row != eggs_in_row - 1:
self.selected_egg += 1
def sel_up(self):
"""
Select the egg above with constraints.
"""
if self.selected_egg // self.eggs_per_row != 0:
self.selected_egg -= self.eggs_per_row
def sel_down(self):
"""
Select the egg below with constraints.
"""
if self.selected_egg // self.eggs_per_row != self.total_rows - 1:
self.selected_egg += self.eggs_per_row
def update(self):
self.preprocess()
cursor = pygame.image.load(
self.resource_dir + '/images/gui/egg_selector.png').convert_alpha()
self.blit(cursor, self.get_cursor_coords())
self.selected_color = self.eggs[self.selected_egg].egg_color
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
self.sel_right()
if event.key == pygame.K_LEFT:
self.sel_left()
if event.key == pygame.K_DOWN:
self.sel_down()
if event.key == pygame.K_UP:
self.sel_up()
if event.key == pygame.K_a:
self.additional_args = {'selected_egg': self.selected_color}
self.next_surface = 'selection_info'
self.running = False

View File

@@ -0,0 +1,28 @@
import pygame
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)
self.frames = 1
self.game_fps = game_fps
self.delay = 1
self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10)
self.title = pygame.image.load(resources_dir + '/images/debug/invalid.png').convert_alpha()
self.next_surface = 'title'
def update(self):
self.preprocess()
self.blit(self.title, (0, -4))
text = self.font.render('Frames: {0}'.format(self.frames), False, (64, 64, 64))
self.blit(text, (3, 68))
self.frames += 1
self.frames %= self.game_fps
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_b:
self.running = False

View File

@@ -0,0 +1,49 @@
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'

View File

@@ -0,0 +1,25 @@
import pygame
from pocket_friends.elements import surface
class Surface(surface.GameSurface):
def __init__(self, game_res, resources_dir, game_fps):
super().__init__(game_res, resources_dir, game_fps)
self.frames = 0
self.delay = 1
self.title = pygame.image.load(resources_dir + '/images/title.png').convert_alpha()
def update(self):
"""
Advance the surface logic by one frame.
"""
self.preprocess()
self.blit(self.title, (0, 0))
print(self.frames)
self.frames += 1
if self.frames > self.game_fps * self.delay:
self.next_surface = 'egg_select'
self.running = False