Return to repo list

tzed

Simple story-driven open world 2D CRPG.
Return to HMagellan.com

commit 6c2acc116a4d7186e8d56bca3c3a24e227aaa6f5
parent 6c4c63e29da3b219b77ebefbb515d23eb2113c58
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 27 Aug 2021 17:29:46 -0500

basic date and location display

Diffstat:
Mdata/images/ui_tray.png | 0
Msrc/game.py | 95++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/data/images/ui_tray.png b/data/images/ui_tray.png Binary files differ. diff --git a/src/game.py b/src/game.py @@ -45,8 +45,17 @@ class Game(object): self.player = None # UI elements - self.UI_tray = None + self.ui_font = pygame.font.Font(os.path.join(FONT_PATH, MESSAGE_FONT), MESSAGE_FONT_SIZE) # TODO: Should there be a UI font option??? + self.small_ui_font = pygame.font.Font(os.path.join(FONT_PATH, MESSAGE_FONT), MESSAGE_FONT_SIZE - 3) + self.date_string = "" + self.ui_tray = None self.ui_group = pygame.sprite.Group() + self.location_element = None + self.location_element_pos = (0, 0) + self.date_element = None + self.date_element_pos = (0, 0) + self.clock_element = None + self.clock_element_pos = (0, 0) # Other values self.sheets = {} @@ -54,6 +63,18 @@ class Game(object): self.current_board = None self.gamedata = {} self.gametime = 0 + self.old_gametime = -1 + self.seconds = 0 + self.minutes = 0 + self.hours = 0 + self.days = 0 + self.months = 0 + self.years = 0 + self.day_descriptors = ["Advent", "Apex", "Verge"] + self.month_names = ["Turrich's Reign", "The Rebirth", "Thrive", "Arbala's Reign", "The Long Days", "The Turning", "Mensor's Reign", "Cold Winds", "The Nights"] + self.datestring = "" + self.clockstring = "" + self.old_location = "" # Loading self.load_sheets("sheets.json") @@ -114,6 +135,8 @@ class Game(object): populate its adjacents and entities. """ if boardname in self.loaded_boards.keys(): + if self.current_board != None: + self.old_location = self.current_board.display_name self.current_board = self.loaded_boards[boardname] self.current_board.change_cell(cellpos) self.current_board.create_dynamic_entities() @@ -210,12 +233,52 @@ class Game(object): # First, add time and calculate into date string. # TODO: Add date string and its display + self.old_gametime = self.gametime self.gametime += time_mod + + # Factor this time into the appropriate categories + # TODO: Time should be defined externally to allow for custom time systems + self.seconds = (10 * self.gametime) + 12999993970 + self.minutes = self.seconds // 60 + self.hours = self.seconds // (60 * 60) + self.days = self.seconds // (60 * 60 * 25) + self.years = self.seconds // (60 * 60 * 25 * 351) + self.days -= self.years * 351 + self.hours -= self.years * (25 * 351) + self.hours -= self.days * 25 + self.minutes -= self.years * (60 * 25 * 351) + self.minutes -= self.days * (60 * 25) + self.minutes -= self.hours * 60 + self.seconds -= self.years * (60 * 60 * 25 * 351) + self.seconds -= self.days * (60 * 60 * 25) + self.seconds -= self.hours * (60 * 60) + self.seconds -= self.minutes * 60 + self.months = self.days // 39 + self.days -= self.months * 39 # Then, if take_turn is true, take a turn for the other entities. if take_turn: pass + def derive_datestring(self): + """ + Derive a datestring and a clockstring from + the current game time. + """ + mnth = self.month_names[self.months] + day_index = self.days // 13 + day_rem = self.days % 13 + if day_rem == 0: + day_meas = "" + else: + day_meas = str(13 - day_rem) + " day" + str("s" if 13 - day_rem != 1 else "") + " ere the " + if day_index < 2: + day_index += 1 + else: + day_index = 0 + self.datestring = day_meas + self.day_descriptors[day_index] + " of " + mnth + self.clockstring = "Year " + str(self.years) + " | " + str("0" if self.hours <= 9 else "") + str(self.hours) + ":" + str("0" if self.minutes <= 9 else "") + str(self.minutes) + ":" + str("0" if self.seconds <= 9 else "") + str(self.seconds) + " o'clock" + def post_message(self, text): """ This method is used by external objects to @@ -223,6 +286,35 @@ class Game(object): """ self.message_board.post(text, self.gamedata) + def update_dynamic_ui(self, surface = None): + """ + Update the dynamic portions of the UI. + """ + + # TODO: Lotsa hardcoding + if surface != None: + + # To begin with, check if any elements in the dynamic UI need to be updated + if self.old_gametime != self.gametime: + self.derive_datestring() + self.old_gametime = self.gametime + self.date_element = self.small_ui_font.render(self.datestring, False, (255, 255, 255)) + self.date_element_pos = (696, 34) + self.clock_element = self.small_ui_font.render(self.clockstring, False, (255, 255, 255)) + self.clock_element_pos = (696, 48) + if self.old_location != self.current_board.display_name: + self.old_location = self.current_board.display_name + self.location_element = self.ui_font.render(self.current_board.display_name, False, (255, 255, 255)) + self.location_element_pos = (696, 16) + + # After updating, blit the whole dynamic UI + if self.date_element != None: + surface.blit(self.date_element, self.date_element_pos) + if self.clock_element != None: + surface.blit(self.clock_element, self.clock_element_pos) + if self.location_element != None: + surface.blit(self.location_element, self.location_element_pos) + def collect_game_data(self): """ Collect a bunch of info about the current @@ -259,6 +351,7 @@ class Game(object): self.player.update(self.screen, self.viewport_rect) self.ui_group.update(self.screen) self.message_board.update_message_board(self.screen) + self.update_dynamic_ui(self.screen) # Next, get info about the game self.collect_game_data()