diff --git a/pocket_friends/__main__.py b/pocket_friends/__main__.py index 7fadff4..4c55047 100644 --- a/pocket_friends/__main__.py +++ b/pocket_friends/__main__.py @@ -9,7 +9,7 @@ import pocket_friends.game_files.game as game if __name__ == '__main__': enable_dev = False - windowed = False + resolution = 240 # enable dev mode if --dev argument is passed if len(sys.argv) > 0: @@ -17,10 +17,10 @@ if __name__ == '__main__': if arg == '--delete-save': save_dir = os.path.join(Path.home(), '.pocket_friends') os.remove(save_dir + '/save.json') - if arg == '--windowed': - windowed = True + if '--res=' in arg: + resolution = int(arg.split('=')[1]) - game.main(windowed) + game.main(resolution) pygame.quit() sys.exit() diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 50bafac..63ec1ce 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -2,10 +2,8 @@ import pygame import os from pathlib import Path import pocket_friends - import importlib -from pocket_friends.game_files.io import gpio_handler valid_surfaces = [ 'title', @@ -13,27 +11,32 @@ valid_surfaces = [ 'selection_info', 'error_screen' ] -surface_modules = {} +# Add all the surface modules to a dictionary for easy switching +surface_modules = {} for module in valid_surfaces: surface_modules[module] = importlib.import_module('pocket_friends.game_files.surfaces.{0}'.format(module)) - -# 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') -resources_dir = script_dir + '/resources' starting_surface = 'title' +# FPS for the game to run at. +game_fps = 16 +# The internal resolution of the game +game_res = 80 + +# Get the path for where all game resources are (images, fonts, sounds, etc.) +script_dir = os.path.dirname(os.path.abspath(__file__)) +resources_dir = script_dir + '/resources' + # Makes Pygame draw on the display of the RPi. os.environ["SDL_FBDEV"] = "/dev/fb1" -def game(windowed=False): +def game(resolution=240): """ Starts the game. + + Args: + resolution (int, optional): Resolution to display the game at. Defaults to 240. """ pygame.init() @@ -41,11 +44,7 @@ def game(windowed=False): # Hide the cursor for the Pi display. pygame.mouse.set_visible(False) - # 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. - screen_size = 240 - - window = pygame.display.set_mode((screen_size, screen_size)) + window = pygame.display.set_mode((resolution, resolution)) surface = surface_modules.get(starting_surface).Surface((game_res, game_res), resources_dir, game_fps) # Only really useful for PCs. Does nothing on the Raspberry Pi. @@ -55,13 +54,13 @@ def game(windowed=False): icon = pygame.image.load(resources_dir + '/icon/icon.png').convert_alpha() pygame.display.set_icon(icon) - clock = pygame.time.Clock() - running = True while running: surface.update() - frame = pygame.transform.scale(surface, (screen_size, screen_size)) + + # The game is only 80x80px, however it is upscaled to whatever the running resolution is. + frame = pygame.transform.scale(surface, (resolution, resolution)) window.blit(frame, frame.get_rect()) if not surface.running: @@ -74,10 +73,13 @@ def game(windowed=False): pygame.display.flip() -def main(windowed=False): +def main(resolution=240): """ Calls the game() function to start the game. + + Args: + resolution (int, optional): Resolution to display the game at. Defaults to 240. """ - game(windowed) + game(resolution) pygame.quit()