made changes to launch script, added customizable resolution

This commit is contained in:
Nick Dyer 2021-06-20 20:52:23 -04:00
parent 88bcd76533
commit 85557ebb1c
3 changed files with 48 additions and 32 deletions

View File

@ -1,29 +1,7 @@
"""
Launch script for Pocket Friends.
Wrapper that launches the launch script.
"""
import os
from pathlib import Path
import pygame
import sys
from pocket_friends.game_files.game import main as game_main
from pocket_friends.development.dev_menu import main as dev_menu_main
import pocket_friends.launch as launch
if __name__ == '__main__':
enable_dev = False
# enable dev mode if --dev argument is passed
if len(sys.argv) > 0:
for args in sys.argv:
if args == '--dev':
enable_dev = True
if args == '--delete-save':
save_dir = os.path.join(Path.home(), '.pocket_friends')
os.remove(save_dir + '/save.json')
if not enable_dev:
game_main()
else:
dev_menu_main()
pygame.quit()
sys.exit()
launch.main()

View File

@ -534,7 +534,7 @@ except ImportError:
on_hardware = False
def game():
def game(screen_size):
"""
Starts the game.
"""
@ -543,10 +543,6 @@ def game():
# 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 = 320
window = pygame.display.set_mode((screen_size, screen_size))
surface = pygame.Surface((game_res, game_res))
@ -974,11 +970,11 @@ def game():
draw()
def main():
def main(screen_size=320):
"""
Calls the game() function to start the game.
"""
game()
game(screen_size)
GPIOHandler.teardown()
pygame.quit()

42
pocket_friends/launch.py Normal file
View File

@ -0,0 +1,42 @@
import os
from pathlib import Path
import argparse
import pygame
import sys
from pocket_friends.game_files.game import main as game_main
def main():
"""
Launch script for Pocket Friends.
"""
# Creates the parser object.
parser = argparse.ArgumentParser()
# Adds parser arguments.
parser.add_argument('-D', '--delete-save', action='store_true', help='Deletes the save file if it exists.')
parser.add_argument('-s', '--size', type=int, default=320, help='Sets the size of the window.')
# Parse the arguments given
args = parser.parse_args()
# If given the delete-save argument, delete the safe file
if args.delete_save:
save_dir = os.path.join(Path.home(), '.pocket_friends')
# Remove the file if it exists
try:
os.remove(save_dir + '/save.json')
print('Save file deleted.')
except FileNotFoundError:
print('Save file does not exist, cannot delete.')
# Set the screen size
screen_size = int(args.size)
# Start the game
game_main(screen_size)
# Cleanup
pygame.quit()
sys.exit()