2023-05-11 11:51:51 -04:00
|
|
|
import pygame
|
|
|
|
import os
|
|
|
|
import pocket_friends
|
2023-05-11 13:09:55 -04:00
|
|
|
import importlib
|
|
|
|
|
|
|
|
valid_surfaces = [
|
2023-05-14 23:04:26 -04:00
|
|
|
'_dev_menu',
|
|
|
|
'_black_screen',
|
2023-05-11 13:09:55 -04:00
|
|
|
'title',
|
2023-05-11 15:24:17 -04:00
|
|
|
'egg_select',
|
2023-05-12 17:34:13 -04:00
|
|
|
'selection_info',
|
|
|
|
'error_screen'
|
2023-05-11 13:09:55 -04:00
|
|
|
]
|
|
|
|
|
2023-05-13 10:30:27 -04:00
|
|
|
# Add all the surface modules to a dictionary for easy switching
|
2023-05-14 23:04:26 -04:00
|
|
|
surface_modules = {}
|
2023-05-11 13:09:55 -04:00
|
|
|
for module in valid_surfaces:
|
2023-05-14 23:04:26 -04:00
|
|
|
print(module[0])
|
|
|
|
if module[0] == '_':
|
|
|
|
surface_modules[module] = importlib.import_module('pocket_friends._development.surfaces.{0}'.format(module))
|
|
|
|
else:
|
2023-05-14 19:26:09 -04:00
|
|
|
surface_modules[module] = importlib.import_module('pocket_friends.surfaces.{0}'.format(module))
|
2023-05-13 10:30:27 -04:00
|
|
|
starting_surface = 'title'
|
2023-05-14 23:04:26 -04:00
|
|
|
print(surface_modules)
|
2023-05-13 10:30:27 -04:00
|
|
|
# FPS for the game to run at.
|
2023-05-11 11:51:51 -04:00
|
|
|
game_fps = 16
|
2023-05-13 10:30:27 -04:00
|
|
|
# The internal resolution of the game
|
2023-05-11 11:51:51 -04:00
|
|
|
game_res = 80
|
2023-05-13 10:30:27 -04:00
|
|
|
|
|
|
|
# Get the path for where all game resources are (images, fonts, sounds, etc.)
|
2023-05-11 11:51:51 -04:00
|
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
2023-05-11 18:00:25 -04:00
|
|
|
resources_dir = script_dir + '/resources'
|
2023-05-11 12:20:07 -04:00
|
|
|
|
2023-05-13 10:16:43 -04:00
|
|
|
# Makes Pygame draw on the display of the RPi.
|
2023-05-13 11:47:48 -04:00
|
|
|
os.environ['SDL_FBDEV'] = '/dev/fb1'
|
2023-05-11 11:51:51 -04:00
|
|
|
|
|
|
|
|
2023-05-14 17:10:34 -04:00
|
|
|
def start_game(resolution=240):
|
2023-05-11 11:51:51 -04:00
|
|
|
"""
|
|
|
|
Starts the game.
|
2023-05-13 10:30:27 -04:00
|
|
|
|
|
|
|
Args:
|
|
|
|
resolution (int, optional): Resolution to display the game at. Defaults to 240.
|
2023-05-11 11:51:51 -04:00
|
|
|
"""
|
|
|
|
|
2023-05-13 09:56:55 -04:00
|
|
|
pygame.init()
|
2023-05-12 23:36:21 -04:00
|
|
|
|
2023-05-13 09:49:51 -04:00
|
|
|
# Hide the cursor for the Pi display.
|
|
|
|
pygame.mouse.set_visible(False)
|
2023-05-12 23:55:06 -04:00
|
|
|
|
2023-05-13 10:30:27 -04:00
|
|
|
window = pygame.display.set_mode((resolution, resolution))
|
2023-05-13 10:17:30 -04:00
|
|
|
surface = surface_modules.get(starting_surface).Surface((game_res, game_res), resources_dir, game_fps)
|
2023-05-13 09:49:51 -04:00
|
|
|
|
2023-05-13 09:56:55 -04:00
|
|
|
# Only really useful for PCs. Does nothing on the Raspberry Pi.
|
2023-05-13 09:49:51 -04:00
|
|
|
pygame.display.set_caption('Pocket Friends {0}'.format(pocket_friends.__version__))
|
2023-05-13 09:56:55 -04:00
|
|
|
|
|
|
|
# Add an icon to the pygame window.
|
2023-05-11 18:00:25 -04:00
|
|
|
icon = pygame.image.load(resources_dir + '/icon/icon.png').convert_alpha()
|
2023-05-11 11:51:51 -04:00
|
|
|
pygame.display.set_icon(icon)
|
|
|
|
|
2023-05-13 09:56:55 -04:00
|
|
|
running = True
|
|
|
|
|
2023-05-11 12:20:07 -04:00
|
|
|
while running:
|
2023-05-13 10:17:30 -04:00
|
|
|
surface.update()
|
2023-05-13 10:30:27 -04:00
|
|
|
|
|
|
|
# The game is only 80x80px, however it is upscaled to whatever the running resolution is.
|
|
|
|
frame = pygame.transform.scale(surface, (resolution, resolution))
|
2023-05-11 12:20:07 -04:00
|
|
|
window.blit(frame, frame.get_rect())
|
|
|
|
|
2023-05-13 10:17:30 -04:00
|
|
|
if not surface.running:
|
2023-05-14 19:26:09 -04:00
|
|
|
if surface.dev_override:
|
2023-05-14 23:04:26 -04:00
|
|
|
next_surface = '_dev_menu'
|
2023-05-14 19:26:09 -04:00
|
|
|
else:
|
|
|
|
next_surface = surface.next_surface
|
2023-05-13 10:17:30 -04:00
|
|
|
additional_args = surface.additional_args
|
|
|
|
if next_surface not in valid_surfaces:
|
2023-05-14 23:04:26 -04:00
|
|
|
print(next_surface)
|
2023-05-14 19:06:50 -04:00
|
|
|
next_surface = 'error_screen'
|
2023-05-13 10:17:30 -04:00
|
|
|
surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir,
|
|
|
|
game_fps, **additional_args)
|
2023-05-11 12:20:07 -04:00
|
|
|
pygame.display.flip()
|
|
|
|
|
2023-05-11 11:51:51 -04:00
|
|
|
pygame.quit()
|