From e2d202d07646c2de03982e094b8b3015c980316b Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Thu, 3 Jun 2021 23:57:17 -0400 Subject: [PATCH 01/11] removed all eggs but red, blue, and rainbow --- pocket_friends/game_files/game.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 5dc0f48..546678c 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -330,10 +330,7 @@ def game(): if submenu == 'main': # Creates and holds the egg objects in a list. - eggs = [SelectionEgg('red'), SelectionEgg('orange'), SelectionEgg('yellow'), - SelectionEgg('green'), - SelectionEgg('blue'), SelectionEgg('indigo'), SelectionEgg('violet'), SelectionEgg('white'), - SelectionEgg('rainbow')] + eggs = [SelectionEgg('red'), SelectionEgg('blue'), SelectionEgg('rainbow')] # How many eggs per row should be displayed. eggs_per_row = 3 From 6d199b2e36ab782708010729394aa507c6b7702b Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Fri, 4 Jun 2021 00:05:57 -0400 Subject: [PATCH 02/11] renamed FileHandler to SaveHandler --- pocket_friends/game_files/game.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 546678c..f9efb56 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -25,7 +25,7 @@ except FileExistsError: pass -class FileHandler: +class SaveHandler: """ Class that handles the hardware attributes and save files. """ @@ -155,7 +155,7 @@ def game(): # Default hardware state when the hardware first starts. game_state = 'title' running = True - file_handler = FileHandler() + save_handler = SaveHandler() # A group of all the sprites on screen. Used to update all sprites at onc all_sprites = pygame.sprite.Group() @@ -308,12 +308,12 @@ def game(): draw() # Read the save file. - file_handler.read_save() + save_handler.read_save() # 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: + if save_handler.attributes['evolution_stage'] == -1: game_state = 'egg_select' else: game_state = 'playground' From 4e0efbabd98e28202f8f7b4b258546bbb608906b Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Fri, 4 Jun 2021 00:15:01 -0400 Subject: [PATCH 03/11] added description for the SelectionEgg, added .json files for each currently added egg --- pocket_friends/game_files/game.py | 7 +++++++ .../game_files/resources/data/egg_info/blue.json | 1 + .../game_files/resources/data/egg_info/rainbow.json | 1 + pocket_friends/game_files/resources/data/egg_info/red.json | 1 + 4 files changed, 10 insertions(+) create mode 100644 pocket_friends/game_files/resources/data/egg_info/blue.json create mode 100644 pocket_friends/game_files/resources/data/egg_info/rainbow.json create mode 100644 pocket_friends/game_files/resources/data/egg_info/red.json diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index f9efb56..9fa430d 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -81,8 +81,15 @@ class SelectionEgg(pygame.sprite.Sprite): def __init__(self, egg_color): pygame.sprite.Sprite.__init__(self) + # Loads the JSON file of the egg to read in data. + with open(script_dir + '/resources/data/egg_info/{0}.json'.format(egg_color), 'r') as save_file: + json_file = json.load(save_file) + save_file.close() image_directory = script_dir + '/resources/images/egg_images/{0}'.format(egg_color) + # Gets the description off the egg from the JSON file. + self.description = json_file.get('description') + # Load the egg from the given color and get the bounding rectangle for the image. self.images = [] for filename in os.listdir(image_directory): diff --git a/pocket_friends/game_files/resources/data/egg_info/blue.json b/pocket_friends/game_files/resources/data/egg_info/blue.json new file mode 100644 index 0000000..780dd86 --- /dev/null +++ b/pocket_friends/game_files/resources/data/egg_info/blue.json @@ -0,0 +1 @@ +{"description": "Blue egg description"} \ No newline at end of file diff --git a/pocket_friends/game_files/resources/data/egg_info/rainbow.json b/pocket_friends/game_files/resources/data/egg_info/rainbow.json new file mode 100644 index 0000000..e4f43a2 --- /dev/null +++ b/pocket_friends/game_files/resources/data/egg_info/rainbow.json @@ -0,0 +1 @@ +{"description": "Rainbow egg description"} \ No newline at end of file diff --git a/pocket_friends/game_files/resources/data/egg_info/red.json b/pocket_friends/game_files/resources/data/egg_info/red.json new file mode 100644 index 0000000..bbf92c9 --- /dev/null +++ b/pocket_friends/game_files/resources/data/egg_info/red.json @@ -0,0 +1 @@ +{"description": "Red egg description"} \ No newline at end of file From ba4df78d353faeda23d039cede8abc0245beba7d Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Fri, 4 Jun 2021 00:33:02 -0400 Subject: [PATCH 04/11] egg now drawn on the description screen --- pocket_friends/game_files/game.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 9fa430d..090d4e9 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -81,6 +81,8 @@ class SelectionEgg(pygame.sprite.Sprite): def __init__(self, egg_color): pygame.sprite.Sprite.__init__(self) + self.egg_color = egg_color + # Loads the JSON file of the egg to read in data. with open(script_dir + '/resources/data/egg_info/{0}.json'.format(egg_color), 'r') as save_file: json_file = json.load(save_file) @@ -331,9 +333,12 @@ def game(): submenu = 'main' selected = 0 + selected_color = "" while running and game_state == 'egg_select': + all_sprites.empty() + if submenu == 'main': # Creates and holds the egg objects in a list. @@ -442,11 +447,22 @@ def game(): cursor = pygame.image.load(script_dir + '/resources/images/clock_selector.png').convert_alpha() surface.blit(cursor, get_cursor_coords(selected)) + selected_color = eggs[selected].egg_color + draw() elif submenu == 'egg_info': + + # Draw the selected egg on screen + egg = SelectionEgg(selected_color) + egg.rect.x = 32 + egg.rect.y = 3 + all_sprites.add(egg) + while running and game_state == 'egg_select' and submenu == 'egg_info': + pre_handler() + for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == Constants.buttons.get('a'): @@ -457,7 +473,7 @@ def game(): submenu = 'main' # Quick debugging for which egg is selected. - selection_debug = small_font.render('Egg {0}'.format(selected), False, (64, 64, 64)) + selection_debug = small_font.render(egg.description, False, (64, 64, 64)) surface.blit(selection_debug, (5, 35)) draw() From 92781747bc6b71c5b47e2fc8a320f8cb52e1cecd Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Fri, 4 Jun 2021 16:56:33 -0400 Subject: [PATCH 05/11] removed a statement that reset the selected egg to 0 once backing out of the info screen --- pocket_friends/game_files/game.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 090d4e9..9e6a12d 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -373,7 +373,6 @@ def game(): # Add the egg to the sprite list. all_sprites.add(egg) - selected = 0 def get_cursor_coords(selection): """ @@ -485,7 +484,7 @@ def game(): # Error screen. This appears when an invalid hardware state has been selected. all_sprites.empty() - frames_passed = 0 # Counter for frames, helps ensure the hardware isnt frozen. + frames_passed = 0 # Counter for frames, helps ensure the hardware isn't frozen. while running and game_state != 'title': From a401c58d22be93c355180f7cbadb972b8a698929 Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Fri, 4 Jun 2021 23:21:54 -0400 Subject: [PATCH 06/11] added the InfoText class to help with drawing large amounts of text on screen at a time. --- pocket_friends/game_files/game.py | 81 +++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 9e6a12d..602b104 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -120,6 +120,87 @@ class SelectionEgg(pygame.sprite.Sprite): self.update_frame_dependent() +class InfoText: + """ + Class for drawing large amounts of text on the screen at a time + """ + + def __init__(self, font, text='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam commodo tempor ' + 'aliquet. Suspendisse placerat accumsan neque, nec volutpat nunc porta ut.'): + + self.font = font + self.text = [] # Text broken up into a list according to how it will fit on screen. + self.max_lines = 6 # Max number of lines to be shown on screen at a time. + self.offset = 0 + raw_text = text # Copy the text to a different variable to be cut up. + + max_line_width = 71 # The maximum pixel width that drawn text can be. + cut_chars = '.,! ' # Characters that will be considered "cuts" aka when a line break can occur. + + # Prevents freezing if the end of the string does not end in a cut character + # Will fix eventually more elegantly + if raw_text[-1:] not in cut_chars: + raw_text += ' ' + + # Calculating line breaks. + while len(raw_text) > 0: + index = 0 + test_text = '' # Chunk of text to pseudo-render and test the width of. + + # Loops until the testing text has reached the size limit. + while True: + + # Break if the current index is larger than the remaining text. + if index + 1 > len(raw_text): + index -= 1 + break + + # Add one character to the testing text from the raw text. + test_text += raw_text[index] + # Get the width of the pseudo-rendered text. + text_width = font.size(test_text)[0] + + # Break if the text is larger than the defined max width. + if text_width > max_line_width: + break + index += 1 + pass + + # Gets the chunk of text to be added to the list. + text_chunk = raw_text[0:index + 1] + # Determines if the chunk of text has any break characters. + has_breaks = any(cut_chars in text_chunk for cut_chars in cut_chars) + + # If the text has break characters, start with the last character and go backwards until + # one has been found, decreasing the index each time. + if has_breaks: + while raw_text[index] not in cut_chars: + index -= 1 + text_chunk = raw_text[0:index + 1] + # If there are no break characters in the chunk, simply decrease the index by one and insert + # a dash at the end of the line to indicate the word continues. + else: + index -= 1 + text_chunk = raw_text[0:index + 1] + text_chunk += '-' + + # Append the text chunk to the list of text to draw. + self.text.append(text_chunk) + + # Cut the text to repeat the process with the new cut string. + raw_text = raw_text[index + 1:] + + def draw(self, surface): + """ + Draws the text on a given surface. + :param surface: The surface for the text to be drawn on. + """ + + for i in range(min(len(self.text), self.max_lines)): + text = self.font.render(self.text[i + self.offset], False, (64, 64, 64)) + surface.blit(text, (3, 22 + (i * 7))) + + # Makes Pygame draw on the display of the RPi. os.environ["SDL_FBDEV"] = "/dev/fb1" From a4aa20e306e7d6c76516c827137beed6121d6d55 Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Fri, 4 Jun 2021 23:26:56 -0400 Subject: [PATCH 07/11] added scrolling to the InfoText class --- pocket_friends/game_files/game.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 602b104..4668ece 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -200,6 +200,21 @@ class InfoText: text = self.font.render(self.text[i + self.offset], False, (64, 64, 64)) surface.blit(text, (3, 22 + (i * 7))) + def scroll_down(self): + """ + Scrolls the text on the screen down. + """ + # Ensures that the offset cannot be too big as to try to render non-existent lines. + if len(self.text) - (self.offset + 1) >= self.max_lines: + self.offset += 1 + + def scroll_up(self): + """ + Scrolls the text on the screen up. + """ + if self.offset > 0: # Ensures a non-zero offset is not possible. + self.offset -= 1 + # Makes Pygame draw on the display of the RPi. os.environ["SDL_FBDEV"] = "/dev/fb1" From 9e4dfdc16ddb9e010eea90a59e8dd8202656abbf Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Fri, 4 Jun 2021 23:59:10 -0400 Subject: [PATCH 08/11] added arrows to scrolling, added arrow images --- pocket_friends/game_files/game.py | 13 ++++++++++++- .../resources/images/gui/down_arrow.png | Bin 0 -> 217 bytes .../game_files/resources/images/gui/up_arrow.png | Bin 0 -> 213 bytes 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 pocket_friends/game_files/resources/images/gui/down_arrow.png create mode 100644 pocket_friends/game_files/resources/images/gui/up_arrow.png diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 4668ece..9fcb6b6 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -132,6 +132,11 @@ class InfoText: self.text = [] # Text broken up into a list according to how it will fit on screen. self.max_lines = 6 # Max number of lines to be shown on screen at a time. self.offset = 0 + + # Arrow icons to indicate scrolling + self.up_arrow = pygame.image.load(script_dir + '/resources/images/gui/up_arrow.png').convert_alpha() + self.down_arrow = pygame.image.load(script_dir + '/resources/images/gui/down_arrow.png').convert_alpha() + raw_text = text # Copy the text to a different variable to be cut up. max_line_width = 71 # The maximum pixel width that drawn text can be. @@ -198,7 +203,13 @@ class InfoText: for i in range(min(len(self.text), self.max_lines)): text = self.font.render(self.text[i + self.offset], False, (64, 64, 64)) - surface.blit(text, (3, 22 + (i * 7))) + surface.blit(text, (3, 25 + (i * 7))) + + # Draw the arrows if there is more text than is on screen. + if self.offset != 0: + surface.blit(self.up_arrow, (36, 22)) + if len(self.text) - (self.offset + 1) >= self.max_lines: + surface.blit(self.down_arrow, (36, 70)) def scroll_down(self): """ diff --git a/pocket_friends/game_files/resources/images/gui/down_arrow.png b/pocket_friends/game_files/resources/images/gui/down_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..adf337ebb9513a795f81e585d3cc4b69ad96a947 GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^96-#*!3HG%vEKg;;v{*yy8vk*`02d69!PN(ctjR6 zFz6|RFk{71`!b*)dx@v7EBjM6R%SiJte8nYKq1Kz*N775{M_8syb=cIqSVBa)D(sC z%#sWRcTeAd@J2pypdv?47sn8e>$QC+c^M3OnABf(3EiD$KV@o7QQi{S&VEOU9huJE zMRF>P3BUP#9(U(z1>^_|_FHm&`+p{9(mdJy%GN9jlE$6J``LkpF?hQAxvXJjtt8pA^n$5>p2hfx_4Dh yOJkcY-zPwqQPl@Yce+ Date: Sat, 5 Jun 2021 00:00:52 -0400 Subject: [PATCH 09/11] implemented new selection screen --- pocket_friends/game_files/game.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index 9fcb6b6..bf94538 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -251,7 +251,7 @@ def game(): # 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 + screen_size = 320 window = pygame.display.set_mode((screen_size, screen_size)) surface = pygame.Surface((rendered_size, rendered_size)) @@ -565,12 +565,21 @@ def game(): egg.rect.y = 3 all_sprites.add(egg) + # Info screen for the eggs. + info = InfoText(small_font) + while running and game_state == 'egg_select' and submenu == 'egg_info': pre_handler() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: + if event.key == Constants.buttons.get('j_d'): + # Scroll down on the info screen. + info.scroll_down() + if event.key == Constants.buttons.get('j_u'): + # Scroll up on the info screen. + info.scroll_up() if event.key == Constants.buttons.get('a'): # Go to an invalid hardware state if continuing. game_state = None @@ -578,9 +587,8 @@ def game(): # Go back to the egg selection screen. submenu = 'main' - # Quick debugging for which egg is selected. - selection_debug = small_font.render(egg.description, False, (64, 64, 64)) - surface.blit(selection_debug, (5, 35)) + # Draw the info screen. + info.draw(surface) draw() From 08014d8244712c90ebf210e509720feb2388c2d0 Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Sat, 5 Jun 2021 00:04:28 -0400 Subject: [PATCH 10/11] made info text show description of egg from its json file --- pocket_friends/game_files/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index bf94538..a0e41ca 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -566,7 +566,7 @@ def game(): all_sprites.add(egg) # Info screen for the eggs. - info = InfoText(small_font) + info = InfoText(small_font, egg.description) while running and game_state == 'egg_select' and submenu == 'egg_info': From ff57cf918f2924629b73a15e80666fa211729ad9 Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Sat, 5 Jun 2021 00:08:56 -0400 Subject: [PATCH 11/11] changed version number to 0.0.2, removed unused version tag in __main__.py --- pocket_friends/__init__.py | 2 +- pocket_friends/__main__.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pocket_friends/__init__.py b/pocket_friends/__init__.py index f0ccdbb..463e1b1 100644 --- a/pocket_friends/__init__.py +++ b/pocket_friends/__init__.py @@ -1 +1 @@ -__version__ = 'dev_0.0.1' +__version__ = 'dev_0.0.2' diff --git a/pocket_friends/__main__.py b/pocket_friends/__main__.py index 60a496c..45820fa 100644 --- a/pocket_friends/__main__.py +++ b/pocket_friends/__main__.py @@ -6,8 +6,6 @@ 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 -__version__ = '0.0.1' - if __name__ == '__main__': enable_dev = False