changed project file structure to better fit python standards

This commit is contained in:
Nick Dyer 2021-05-29 20:08:15 -04:00
parent 329c4a022c
commit 4e7e37177b
28 changed files with 65 additions and 59 deletions

View File

@ -1,25 +0,0 @@
"""
Launch script for Pocket Friends.
"""
import pygame
import sys
from pocket_friends.game import main as game_main
from pocket_friends.development.dev_menu import main as dev_menu_main
enable_dev = False
if __name__ == '__main__':
# 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 not enable_dev:
game_main()
else:
dev_menu_main()
pygame.quit()
sys.exit()

View File

@ -1 +1 @@
"""Imports classes for running the game."""
"""Imports classes for running the hardware."""

View File

@ -0,0 +1,31 @@
"""
Launch script for Pocket Friends.
"""
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
def main():
enable_dev = False
if __name__ == '__main__':
# 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 not enable_dev:
game_main()
else:
dev_menu_main()
pygame.quit()
sys.exit()
if __name__ == "__main__":
main()

View File

@ -1,6 +1,6 @@
"""
Module used to fake the RPi.GPIO module so that
the game can be run without the actual hardware.
the hardware can be run without the actual hardware.
"""
# Constants used by RPi.GPIO

View File

@ -2,7 +2,7 @@
Module to test the GPIO input on the Raspberry Pi.
"""
from collections import deque
from ..gpio_handler import Constants, GPIOHandler
from pocket_friends.hardware.gpio_handler import Constants, GPIOHandler
def button_test():

View File

@ -1,14 +1,14 @@
"""
Development menu for the game on Raspberry Pi. NOTE: THIS DOES NOTHING ON A COMPUTER!
Development menu for the hardware on Raspberry Pi. NOTE: THIS DOES NOTHING ON A COMPUTER!
"""
import pocket_friends.game
import pocket_friends.game_files.game
import importlib.util
import os
import pygame
import time
from .button_test import button_test
from .menus import Menu
from ..gpio_handler import GPIOHandler, Constants
from pocket_friends.hardware.gpio_handler import GPIOHandler, Constants
dev_version = '0.0.1'
@ -40,10 +40,10 @@ def clear_screen():
def start_game():
"""
Cleans the GPIO and starts the game.
Cleans the GPIO and starts the hardware.
"""
GPIOHandler.teardown()
pocket_friends.game.main()
pocket_friends.game_files.game.main()
pygame.quit()
GPIOHandler.setup()
@ -95,7 +95,7 @@ def main():
# The following defines all of the options in the various different menus.
main_menu = Menu('Pocket Friends Dev Menu {0}\nGame Version {1}'.format(dev_version, pocket_friends.game.version))
main_menu = Menu('Pocket Friends Dev Menu {0}\nGame Version {1}'.format(dev_version, pocket_friends.game_files.game.version))
main_menu.add_option(Menu.Option('Start Game', start_game))
main_menu.add_option(Menu.Option('Button Test', run_button_test))
main_menu.add_option(Menu.Option('Restart Dev Menu', quit_with_error))

View File

View File

@ -1,5 +1,5 @@
"""
Main file for the entire game. Controls everything except for GPIO input.
Main file for the entire hardware. Controls everything except for GPIO input.
"""
from collections import deque
import importlib.util
@ -7,7 +7,7 @@ import json
import os
import pygame
from pygame.locals import *
from .gpio_handler import Constants, GPIOHandler
from pocket_friends.hardware.gpio_handler import Constants, GPIOHandler
version = '0.0.1'
game_fps = 16
@ -15,7 +15,7 @@ game_fps = 16
class FileHandler:
"""
Class that handles the game attributes and save files.
Class that handles the hardware attributes and save files.
"""
def __init__(self):
@ -69,7 +69,7 @@ class SelectionEgg(pygame.sprite.Sprite):
def __init__(self, egg_color):
pygame.sprite.Sprite.__init__(self)
image_directory = 'resources/images/egg_images/{0}'.format(egg_color)
image_directory = 'pocket_friends/resources/images/egg_images/{0}'.format(egg_color)
# Load the egg from the given color and get the bounding rectangle for the image.
self.images = []
@ -113,14 +113,14 @@ except ImportError:
def game():
"""
Starts the game.
Starts the hardware.
"""
pygame.init()
# 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
# The hardware 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.
rendered_size = 80
screen_size = 800
@ -133,10 +133,10 @@ def game():
clock = pygame.time.Clock()
# Font used for small text in the game. Bigger text is usually image files.
small_font = pygame.font.Font('resources/fonts/5Pts5.ttf', 10)
# Font used for small text in the hardware. Bigger text is usually image files.
small_font = pygame.font.Font('pocket_friends/resources/fonts/5Pts5.ttf', 10)
# Default game state when the game first starts.
# Default hardware state when the hardware first starts.
game_state = 'title'
running = True
file_handler = FileHandler()
@ -147,7 +147,7 @@ def game():
# Start the GPIO handler to take in buttons from the RPi HAT.
GPIOHandler.setup()
# Dev code used to exit the game. Default Down, Down, Up, Up, Down, Down, Up, Up, A, A, B
# Dev code used to exit the hardware. Default Down, Down, Up, Up, Down, Down, Up, Up, A, A, B
dev_code = deque()
for button in [Constants.buttons.get('j_d'), Constants.buttons.get('j_d'), Constants.buttons.get('j_u'),
Constants.buttons.get('j_u'), Constants.buttons.get('j_d'), Constants.buttons.get('j_d'),
@ -177,9 +177,9 @@ def game():
def draw_bg():
"""
Draws the main game background image onto a given surface.
Draws the main hardware background image onto a given surface.
"""
bg_image = pygame.image.load('resources/images/bg.png').convert()
bg_image = pygame.image.load('pocket_friends/resources/images/bg.png').convert()
surface.blit(bg_image, (0, 0))
def log_button(pressed_button):
@ -226,7 +226,7 @@ def game():
def keyboard_handler():
"""
Simulates key presses to GPIO button presses. Also handles quitting the game.
Simulates key presses to GPIO button presses. Also handles quitting the hardware.
"""
nonlocal running
@ -254,10 +254,10 @@ def game():
def pre_handler():
"""
Runs at the beginning of each loop, handles drawing the background, controlling game speed, and
Runs at the beginning of each loop, handles drawing the background, controlling hardware speed, and
controlling the GPIO button inputs and keyboard handler
"""
# Regulate the speed of the game.
# Regulate the speed of the hardware.
clock.tick(game_fps)
# Handle all inputs for both debugging and real GPIO button presses.
@ -274,11 +274,11 @@ def game():
pre_handler()
# Draw the title image in the middle of the screen.
title_image = pygame.image.load('resources/images/title.png').convert_alpha()
title_image = pygame.image.load('pocket_friends/resources/images/title.png').convert_alpha()
surface.blit(title_image, (0, 0))
draw()
# Show the title for 1 second then move on to the initialization phase of the game.
# Show the title for 1 second then move on to the initialization phase of the hardware.
pygame.time.wait(1000)
game_state = 'init'
@ -294,8 +294,8 @@ def game():
# Read the save file.
file_handler.read_save()
# Determines if it is a new game or not by looking at the evolution stage. If it is -1, the egg has
# not been created yet, and the game sends you to the egg selection screen. If not, the game sends
# Determines if it is a new hardware or not by looking at the evolution stage. If it is -1, the egg has
# not been created yet, and the hardware sends you to the egg selection screen. If not, the hardware sends
# you to the playground.
if file_handler.attributes['evolution_stage'] == -1:
game_state = 'egg_select'
@ -419,7 +419,7 @@ def game():
submenu = 'egg_info'
# Draws the cursor on screen.
cursor = pygame.image.load('resources/images/clock_selector.png').convert_alpha()
cursor = pygame.image.load('pocket_friends/resources/images/clock_selector.png').convert_alpha()
surface.blit(cursor, get_cursor_coords(selected))
draw()
@ -430,7 +430,7 @@ def game():
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == Constants.buttons.get('a'):
# Go to an invalid game state if continuing.
# Go to an invalid hardware state if continuing.
game_state = None
if event.key == Constants.buttons.get('b'):
# Go back to the egg selection screen.
@ -446,17 +446,17 @@ def game():
game_state = None
else:
# Error screen. This appears when an invalid game state has been selected.
# Error screen. This appears when an invalid hardware state has been selected.
all_sprites.empty()
frames_passed = 0 # Counter for frames, helps ensure the game isnt frozen.
frames_passed = 0 # Counter for frames, helps ensure the hardware isnt frozen.
while running and game_state != 'title':
pre_handler()
# Draw the error screen
error_screen = pygame.image.load('resources/images/debug/invalid.png').convert_alpha()
error_screen = pygame.image.load('pocket_friends/resources/images/debug/invalid.png').convert_alpha()
surface.blit(error_screen, (0, -8))
# Counts the frames passed. Resets every second.
@ -479,7 +479,7 @@ def game():
def main():
"""
Calls the game() function to start the game.
Calls the hardware() function to start the hardware.
"""
game()

View File

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 631 B

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 807 B

After

Width:  |  Height:  |  Size: 807 B

View File

Before

Width:  |  Height:  |  Size: 610 B

After

Width:  |  Height:  |  Size: 610 B

View File

Before

Width:  |  Height:  |  Size: 820 B

After

Width:  |  Height:  |  Size: 820 B

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 864 B

After

Width:  |  Height:  |  Size: 864 B

View File

Before

Width:  |  Height:  |  Size: 740 B

After

Width:  |  Height:  |  Size: 740 B

View File

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

View File

Before

Width:  |  Height:  |  Size: 736 B

After

Width:  |  Height:  |  Size: 736 B

View File

Before

Width:  |  Height:  |  Size: 312 B

After

Width:  |  Height:  |  Size: 312 B

View File

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB