2023-05-11 11:51:51 -04:00
|
|
|
import pygame
|
|
|
|
import os
|
|
|
|
from pathlib import Path
|
|
|
|
import pocket_friends
|
2023-05-12 23:17:33 -04:00
|
|
|
|
2023-05-11 13:09:55 -04:00
|
|
|
import importlib
|
|
|
|
|
2023-05-12 23:17:33 -04:00
|
|
|
from pocket_friends.game_files.io import gpio_handler
|
|
|
|
|
2023-05-11 13:09:55 -04:00
|
|
|
valid_surfaces = [
|
|
|
|
'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
|
|
|
]
|
|
|
|
surface_modules = {}
|
|
|
|
|
|
|
|
for module in valid_surfaces:
|
|
|
|
surface_modules[module] = importlib.import_module('pocket_friends.game_files.surfaces.{0}'.format(module))
|
2023-05-11 11:51:51 -04:00
|
|
|
|
|
|
|
# FPS for the entire game to run at.
|
|
|
|
game_fps = 16
|
|
|
|
# The resolution the game is rendered at.
|
|
|
|
game_res = 80
|
|
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
save_dir = os.path.join(Path.home(), '.pocket_friends')
|
2023-05-11 18:00:25 -04:00
|
|
|
resources_dir = script_dir + '/resources'
|
2023-05-11 12:20:07 -04:00
|
|
|
starting_surface = 'title'
|
|
|
|
|
2023-05-13 10:16:43 -04:00
|
|
|
# Makes Pygame draw on the display of the RPi.
|
|
|
|
os.environ["SDL_FBDEV"] = "/dev/fb1"
|
2023-05-11 11:51:51 -04:00
|
|
|
|
|
|
|
|
2023-05-12 23:42:21 -04:00
|
|
|
def game(windowed=False):
|
2023-05-11 11:51:51 -04:00
|
|
|
"""
|
|
|
|
Starts the game.
|
|
|
|
"""
|
|
|
|
|
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 09:56:55 -04:00
|
|
|
# The game is normally rendered at 80 pixels and upscaled from there. If changing displays, change the
|
|
|
|
# screen_size to reflect what the resolution of the new display is.
|
2023-05-13 09:49:51 -04:00
|
|
|
screen_size = 240
|
2023-05-13 09:56:55 -04:00
|
|
|
|
2023-05-12 23:55:06 -04:00
|
|
|
window = pygame.display.set_mode((screen_size, screen_size))
|
2023-05-13 00:04:34 -04:00
|
|
|
surface = pygame.Surface((game_res, game_res))
|
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
|
|
|
clock = pygame.time.Clock()
|
|
|
|
|
|
|
|
running = True
|
|
|
|
|
|
|
|
#surface = surface_modules.get(starting_surface).Surface((game_res, game_res), resources_dir, game_fps)
|
|
|
|
surface.fill((255, 0, 0))
|
|
|
|
|
2023-05-11 11:51:51 -04:00
|
|
|
# Default game state when the game first starts.
|
|
|
|
running = True
|
|
|
|
|
2023-05-11 12:20:07 -04:00
|
|
|
while running:
|
2023-05-13 00:04:34 -04:00
|
|
|
#surface.update()
|
2023-05-13 09:56:55 -04:00
|
|
|
surface.fill((255, 0, 0))
|
2023-05-11 12:20:07 -04:00
|
|
|
frame = pygame.transform.scale(surface, (screen_size, screen_size))
|
|
|
|
window.blit(frame, frame.get_rect())
|
|
|
|
|
2023-05-13 00:04:34 -04:00
|
|
|
#if not surface.running:
|
|
|
|
# next_surface = surface.next_surface
|
|
|
|
# additional_args = surface.additional_args
|
|
|
|
# if next_surface not in valid_surfaces:
|
|
|
|
# next_surface = 'error_screen'
|
|
|
|
# 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
|
|
|
|
2023-05-12 23:42:21 -04:00
|
|
|
def main(windowed=False):
|
2023-05-11 11:51:51 -04:00
|
|
|
"""
|
|
|
|
Calls the game() function to start the game.
|
|
|
|
"""
|
2023-05-12 23:42:21 -04:00
|
|
|
game(windowed)
|
2023-05-11 11:51:51 -04:00
|
|
|
|
|
|
|
pygame.quit()
|