restructured directories to make more sense of modules and sub-modules
@ -1 +1,4 @@
|
|||||||
|
"""Pocket Friends is a game where you raise your own little pocket friend! These pocket friends, called bloops,
|
||||||
|
are great little companions to have! You can feed them, play with them, and watch them grow up!"""
|
||||||
|
|
||||||
__version__ = 'dev_0.0.3'
|
__version__ = 'dev_0.0.3'
|
||||||
|
@ -5,8 +5,7 @@ import os
|
|||||||
import pygame
|
import pygame
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pocket_friends.game_files.game import main as game_main
|
import pocket_friends.game_files.game as game
|
||||||
#from pocket_friends.development.dev_menu import main as dev_menu_main
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
enable_dev = False
|
enable_dev = False
|
||||||
@ -14,19 +13,11 @@ if __name__ == '__main__':
|
|||||||
# enable dev mode if --dev argument is passed
|
# enable dev mode if --dev argument is passed
|
||||||
if len(sys.argv) > 0:
|
if len(sys.argv) > 0:
|
||||||
for args in sys.argv:
|
for args in sys.argv:
|
||||||
#if args == '--dev': [reimplement later]
|
|
||||||
# enable_dev = True
|
|
||||||
if args == '--delete-save':
|
if args == '--delete-save':
|
||||||
save_dir = os.path.join(Path.home(), '.pocket_friends')
|
save_dir = os.path.join(Path.home(), '.pocket_friends')
|
||||||
os.remove(save_dir + '/save.json')
|
os.remove(save_dir + '/save.json')
|
||||||
|
|
||||||
# Dev menu disabled for now, will reimplement later
|
game.main()
|
||||||
#if not enable_dev:
|
|
||||||
# game_main()
|
|
||||||
#else:
|
|
||||||
# dev_menu_main()
|
|
||||||
|
|
||||||
game_main()
|
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Module to test the GPIO input on the Raspberry Pi.
|
Module to test the GPIO input on the Raspberry Pi.
|
||||||
"""
|
"""
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from pocket_friends.game_files.io_helpers.gpio_handler import Constants, GPIOHandler
|
from pocket_friends.game_files.io.gpio_handler import Constants, GPIOHandler
|
||||||
|
|
||||||
|
|
||||||
def button_test():
|
def button_test():
|
||||||
|
@ -8,13 +8,13 @@ import pygame
|
|||||||
import time
|
import time
|
||||||
from .button_test import button_test
|
from .button_test import button_test
|
||||||
from .menus import Menu
|
from .menus import Menu
|
||||||
from pocket_friends.game_files.io_helpers.gpio_handler import GPIOHandler, Constants
|
from pocket_friends.game_files.io.gpio_handler import GPIOHandler, Constants
|
||||||
|
|
||||||
try:
|
try:
|
||||||
importlib.util.find_spec('RPi.GPIO')
|
importlib.util.find_spec('RPi.GPIO')
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import pocket_friends.game_files.io_helpers.fake_gpio as GPIO
|
import pocket_friends.game_files.io.fake_gpio as GPIO
|
||||||
|
|
||||||
# Global variable to keep track of the current menu.
|
# Global variable to keep track of the current menu.
|
||||||
menu = 'main'
|
menu = 'main'
|
||||||
|
2
pocket_friends/game_files/io/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
"""Sub-package for handling all I/O operations including keyboard input (GPIO input when connected to a Raspberry Pi)
|
||||||
|
and save data reading and writing."""
|
62
pocket_friends/game_files/io/gpio_handler.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
"""
|
||||||
|
Handle inputs from the GPIO pins on the Raspberry Pi and converting them to events to be used in other places (pygame, etc.)
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
|
||||||
|
# If the RPi.GPIO module is not found (aka the program is not running on a Pi), import the fake
|
||||||
|
# GPIO module instead to prevent a crash.
|
||||||
|
try:
|
||||||
|
importlib.util.find_spec('RPi.GPIO')
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
except ImportError:
|
||||||
|
import pocket_friends.game_files.io.fake_gpio as GPIO
|
||||||
|
|
||||||
|
# Dictionary of all the buttons used and what their corresponding GPIO codes are
|
||||||
|
BUTTONS = {
|
||||||
|
'a': 31, # A button
|
||||||
|
'b': 29, # B button
|
||||||
|
'j_i': 7, # Joystick in
|
||||||
|
'j_u': 11, # Joystick up
|
||||||
|
'j_d': 15, # Joystick down
|
||||||
|
'j_l': 13, # Joystick left
|
||||||
|
'j_r': 16 # Joystick right
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
"""
|
||||||
|
Primes the GPIO pins for reading the inputs of the buttons.
|
||||||
|
"""
|
||||||
|
GPIO.setmode(GPIO.BOARD)
|
||||||
|
|
||||||
|
GPIO.setup(BUTTONS.get('a'), GPIO.IN)
|
||||||
|
GPIO.setup(BUTTONS.get('b'), GPIO.IN)
|
||||||
|
GPIO.setup(BUTTONS.get('j_i'), GPIO.IN)
|
||||||
|
GPIO.setup(BUTTONS.get('j_u'), GPIO.IN)
|
||||||
|
GPIO.setup(BUTTONS.get('j_d'), GPIO.IN)
|
||||||
|
GPIO.setup(BUTTONS.get('j_l'), GPIO.IN)
|
||||||
|
GPIO.setup(BUTTONS.get('j_r'), GPIO.IN)
|
||||||
|
|
||||||
|
GPIO.add_event_detect(BUTTONS.get('a'), GPIO.FALLING)
|
||||||
|
GPIO.add_event_detect(BUTTONS.get('b'), GPIO.FALLING)
|
||||||
|
GPIO.add_event_detect(BUTTONS.get('j_i'), GPIO.FALLING)
|
||||||
|
GPIO.add_event_detect(BUTTONS.get('j_u'), GPIO.FALLING)
|
||||||
|
GPIO.add_event_detect(BUTTONS.get('j_d'), GPIO.FALLING)
|
||||||
|
GPIO.add_event_detect(BUTTONS.get('j_l'), GPIO.FALLING)
|
||||||
|
GPIO.add_event_detect(BUTTONS.get('j_r'), GPIO.FALLING)
|
||||||
|
|
||||||
|
|
||||||
|
def teardown():
|
||||||
|
"""
|
||||||
|
Cleans up the GPIO handler.
|
||||||
|
"""
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
|
|
||||||
|
def get_press(button):
|
||||||
|
"""
|
||||||
|
Returns true if a button has changed from not pressed to pressed.
|
||||||
|
:param button: button to be detected
|
||||||
|
:return: True if the button is has been pressed, False otherwise
|
||||||
|
"""
|
||||||
|
return GPIO.event_detected(button)
|
@ -1,6 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import importlib.util
|
import importlib.util
|
||||||
from pocket_friends.game_files.io_helpers.gpio_handler import Constants, GPIOHandler
|
import pocket_friends.game_files.io.gpio_handler as gpio_handler
|
||||||
|
|
||||||
|
|
||||||
class InputHandler:
|
class InputHandler:
|
||||||
@ -18,7 +18,7 @@ class InputHandler:
|
|||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
self.on_hardware = True
|
self.on_hardware = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import pocket_friends.game_files.io_helpers.fake_gpio as GPIO
|
import pocket_friends.game_files.io.fake_gpio as GPIO
|
||||||
self.on_hardware = False
|
self.on_hardware = False
|
||||||
|
|
||||||
self.last_input_tick = 0
|
self.last_input_tick = 0
|
||||||
@ -38,11 +38,11 @@ class InputHandler:
|
|||||||
"""
|
"""
|
||||||
Handles getting GPIO button presses and making a pygame event when a press is detected.
|
Handles getting GPIO button presses and making a pygame event when a press is detected.
|
||||||
"""
|
"""
|
||||||
for pressed_button in Constants.buttons:
|
for pressed_button in gpio_handler.BUTTONS:
|
||||||
code = Constants.buttons.get(pressed_button)
|
code = gpio_handler.BUTTONS.get(pressed_button)
|
||||||
|
|
||||||
# Check if a button has been pressed. If it has, create a pygame event for it.
|
# Check if a button has been pressed. If it has, create a pygame event for it.
|
||||||
if GPIOHandler.get_press(code):
|
if gpio_handler.get_press(code):
|
||||||
self.create_event(code)
|
self.create_event(code)
|
||||||
|
|
||||||
def keyboard_handler(self):
|
def keyboard_handler(self):
|
||||||
@ -56,19 +56,19 @@ class InputHandler:
|
|||||||
running = False
|
running = False
|
||||||
if keyboard_event.type == pygame.KEYDOWN:
|
if keyboard_event.type == pygame.KEYDOWN:
|
||||||
if keyboard_event.key == pygame.K_a:
|
if keyboard_event.key == pygame.K_a:
|
||||||
self.create_event(Constants.buttons.get('a'))
|
self.create_event(gpio_handler.BUTTONS.get('a'))
|
||||||
if keyboard_event.key == pygame.K_b:
|
if keyboard_event.key == pygame.K_b:
|
||||||
self.create_event(Constants.buttons.get('b'))
|
self.create_event(gpio_handler.BUTTONS.get('b'))
|
||||||
if keyboard_event.key == pygame.K_PERIOD:
|
if keyboard_event.key == pygame.K_PERIOD:
|
||||||
self.create_event(Constants.buttons.get('j_i'))
|
self.create_event(gpio_handler.BUTTONS.get('j_i'))
|
||||||
if keyboard_event.key == pygame.K_RIGHT:
|
if keyboard_event.key == pygame.K_RIGHT:
|
||||||
self.create_event(Constants.buttons.get('j_r'))
|
self.create_event(gpio_handler.BUTTONS.get('j_r'))
|
||||||
if keyboard_event.key == pygame.K_LEFT:
|
if keyboard_event.key == pygame.K_LEFT:
|
||||||
self.create_event(Constants.buttons.get('j_l'))
|
self.create_event(gpio_handler.BUTTONS.get('j_l'))
|
||||||
if keyboard_event.key == pygame.K_DOWN:
|
if keyboard_event.key == pygame.K_DOWN:
|
||||||
self.create_event(Constants.buttons.get('j_d'))
|
self.create_event(gpio_handler.BUTTONS.get('j_d'))
|
||||||
if keyboard_event.key == pygame.K_UP:
|
if keyboard_event.key == pygame.K_UP:
|
||||||
self.create_event(Constants.buttons.get('j_u'))
|
self.create_event(gpio_handler.BUTTONS.get('j_u'))
|
||||||
if keyboard_event.key == pygame.K_ESCAPE:
|
if keyboard_event.key == pygame.K_ESCAPE:
|
||||||
running = False
|
running = False
|
||||||
|
|
@ -1,71 +0,0 @@
|
|||||||
"""
|
|
||||||
Module that helps with the handling of taking inputs from the GPIO pins on the Raspberry
|
|
||||||
Pi and converting them to events to be used in other places (pygame, etc.)
|
|
||||||
"""
|
|
||||||
import importlib.util
|
|
||||||
|
|
||||||
try:
|
|
||||||
importlib.util.find_spec('RPi.GPIO')
|
|
||||||
import RPi.GPIO as GPIO
|
|
||||||
except ImportError:
|
|
||||||
import pocket_friends.game_files.io_helpers.fake_gpio as GPIO
|
|
||||||
|
|
||||||
|
|
||||||
class Constants:
|
|
||||||
"""
|
|
||||||
Contains the constants used by the HAT to read in buttons
|
|
||||||
"""
|
|
||||||
buttons = {
|
|
||||||
'a': 31, # A button
|
|
||||||
'b': 29, # B button
|
|
||||||
'j_i': 7, # Joystick in
|
|
||||||
'j_u': 11, # Joystick up
|
|
||||||
'j_d': 15, # Joystick down
|
|
||||||
'j_l': 13, # Joystick left
|
|
||||||
'j_r': 16 # Joystick right
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class GPIOHandler:
|
|
||||||
"""
|
|
||||||
Class to handle the GPIO inputs from the buttons.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def setup():
|
|
||||||
"""
|
|
||||||
Primes the GPIO pins for reading the inputs of the buttons.
|
|
||||||
"""
|
|
||||||
GPIO.setmode(GPIO.BOARD)
|
|
||||||
|
|
||||||
GPIO.setup(Constants.buttons.get('a'), GPIO.IN)
|
|
||||||
GPIO.setup(Constants.buttons.get('b'), GPIO.IN)
|
|
||||||
GPIO.setup(Constants.buttons.get('j_i'), GPIO.IN)
|
|
||||||
GPIO.setup(Constants.buttons.get('j_u'), GPIO.IN)
|
|
||||||
GPIO.setup(Constants.buttons.get('j_d'), GPIO.IN)
|
|
||||||
GPIO.setup(Constants.buttons.get('j_l'), GPIO.IN)
|
|
||||||
GPIO.setup(Constants.buttons.get('j_r'), GPIO.IN)
|
|
||||||
|
|
||||||
GPIO.add_event_detect(Constants.buttons.get('a'), GPIO.FALLING)
|
|
||||||
GPIO.add_event_detect(Constants.buttons.get('b'), GPIO.FALLING)
|
|
||||||
GPIO.add_event_detect(Constants.buttons.get('j_i'), GPIO.FALLING)
|
|
||||||
GPIO.add_event_detect(Constants.buttons.get('j_u'), GPIO.FALLING)
|
|
||||||
GPIO.add_event_detect(Constants.buttons.get('j_d'), GPIO.FALLING)
|
|
||||||
GPIO.add_event_detect(Constants.buttons.get('j_l'), GPIO.FALLING)
|
|
||||||
GPIO.add_event_detect(Constants.buttons.get('j_r'), GPIO.FALLING)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def teardown():
|
|
||||||
"""
|
|
||||||
Cleans up the GPIO handler.
|
|
||||||
"""
|
|
||||||
GPIO.cleanup()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_press(button):
|
|
||||||
"""
|
|
||||||
Returns true if a button has moved from not pressed to pressed.
|
|
||||||
:param button: button to be detected
|
|
||||||
:return: True if the button is has been pressed, False otherwise
|
|
||||||
"""
|
|
||||||
return GPIO.event_detected(button)
|
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 807 B After Width: | Height: | Size: 807 B |
Before Width: | Height: | Size: 610 B After Width: | Height: | Size: 610 B |
Before Width: | Height: | Size: 820 B After Width: | Height: | Size: 820 B |
Before Width: | Height: | Size: 740 B After Width: | Height: | Size: 740 B |
Before Width: | Height: | Size: 490 B After Width: | Height: | Size: 490 B |
Before Width: | Height: | Size: 736 B After Width: | Height: | Size: 736 B |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 422 B After Width: | Height: | Size: 422 B |
Before Width: | Height: | Size: 565 B After Width: | Height: | Size: 565 B |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 864 B After Width: | Height: | Size: 864 B |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 218 B After Width: | Height: | Size: 218 B |
Before Width: | Height: | Size: 188 B After Width: | Height: | Size: 188 B |
Before Width: | Height: | Size: 178 B After Width: | Height: | Size: 178 B |
Before Width: | Height: | Size: 217 B After Width: | Height: | Size: 217 B |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 419 B After Width: | Height: | Size: 419 B |
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 268 B |
Before Width: | Height: | Size: 350 B After Width: | Height: | Size: 350 B |
Before Width: | Height: | Size: 344 B After Width: | Height: | Size: 344 B |
Before Width: | Height: | Size: 235 B After Width: | Height: | Size: 235 B |
Before Width: | Height: | Size: 302 B After Width: | Height: | Size: 302 B |
Before Width: | Height: | Size: 258 B After Width: | Height: | Size: 258 B |
Before Width: | Height: | Size: 213 B After Width: | Height: | Size: 213 B |
Before Width: | Height: | Size: 213 B After Width: | Height: | Size: 213 B |
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
@ -1,7 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from . import sprites
|
from . import sprites
|
||||||
from pocket_friends.game_files.io_helpers.gpio_handler import Constants
|
import pocket_friends.game_files.io.gpio_handler as gpio_handler
|
||||||
from ..io_helpers.input_handler import InputHandler
|
from ..io.input_handler import InputHandler
|
||||||
|
|
||||||
|
|
||||||
class Surface(pygame.Surface):
|
class Surface(pygame.Surface):
|
||||||
@ -133,15 +133,15 @@ class Surface(pygame.Surface):
|
|||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == Constants.buttons.get('j_r'):
|
if event.key == gpio_handler.BUTTONS.get('j_r'):
|
||||||
self.sel_right()
|
self.sel_right()
|
||||||
if event.key == Constants.buttons.get('j_l'):
|
if event.key == gpio_handler.BUTTONS.get('j_l'):
|
||||||
self.sel_left()
|
self.sel_left()
|
||||||
if event.key == Constants.buttons.get('j_d'):
|
if event.key == gpio_handler.BUTTONS.get('j_d'):
|
||||||
self.sel_down()
|
self.sel_down()
|
||||||
if event.key == Constants.buttons.get('j_u'):
|
if event.key == gpio_handler.BUTTONS.get('j_u'):
|
||||||
self.sel_up()
|
self.sel_up()
|
||||||
if event.key == Constants.buttons.get('a'):
|
if event.key == gpio_handler.BUTTONS.get('a'):
|
||||||
self.additional_args = {'selected_egg': self.selected_color}
|
self.additional_args = {'selected_egg': self.selected_color}
|
||||||
self.next_surface = 'selection_info'
|
self.next_surface = 'selection_info'
|
||||||
self.running = False
|
self.running = False
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from . import sprites
|
from . import sprites
|
||||||
from pocket_friends.game_files.io_helpers.gpio_handler import Constants
|
import pocket_friends.game_files.io.gpio_handler as gpio_handler
|
||||||
from .sprites import SelectionEgg
|
from .sprites import SelectionEgg
|
||||||
from ..io_helpers.input_handler import InputHandler
|
from ..io.input_handler import InputHandler
|
||||||
|
|
||||||
|
|
||||||
class Surface(pygame.Surface):
|
class Surface(pygame.Surface):
|
||||||
@ -46,15 +46,15 @@ class Surface(pygame.Surface):
|
|||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == Constants.buttons.get('j_d'):
|
if event.key == gpio_handler.BUTTONS.get('j_d'):
|
||||||
# Scroll down on the info screen.
|
# Scroll down on the info screen.
|
||||||
self.info_text.scroll_down()
|
self.info_text.scroll_down()
|
||||||
if event.key == Constants.buttons.get('j_u'):
|
if event.key == gpio_handler.BUTTONS.get('j_u'):
|
||||||
# Scroll up on the info screen.
|
# Scroll up on the info screen.
|
||||||
self.info_text.scroll_up()
|
self.info_text.scroll_up()
|
||||||
if event.key == Constants.buttons.get('a'):
|
if event.key == gpio_handler.BUTTONS.get('a'):
|
||||||
pass
|
pass
|
||||||
if event.key == Constants.buttons.get('b'):
|
if event.key == gpio_handler.BUTTONS.get('b'):
|
||||||
self.running = False
|
self.running = False
|
||||||
self.additional_args = {'selected_color': self.selected_egg}
|
self.additional_args = {'selected_color': self.selected_egg}
|
||||||
self.next_surface = 'egg_select'
|
self.next_surface = 'egg_select'
|
||||||
|