Return to repo list

tzed

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

commit e54a7bc1c9e3f2ba7976ee57b1b806d5af0e9240
parent f93da1294ee29c74282f276fabeca9dfa8fc340e
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Thu, 26 Aug 2021 16:52:46 -0500

cleanup and expand messages

Diffstat:
Msrc/game.py | 18+++++++++---------
Msrc/message.py | 10+++++-----
2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/game.py b/src/game.py @@ -116,6 +116,8 @@ class Game(object): self.current_board = self.loaded_boards[boardname] self.current_board.change_cell(cellpos) self.current_board.create_dynamic_entities() + self.collect_game_data() + self.message_board.post("$PLAYERNAME enters $CURRENTBOARDNAME.", self.gamedata) else: return 1 @@ -168,13 +170,10 @@ class Game(object): if self.player != None: np = (self.player.tilepos[0] + offset[0], self.player.tilepos[1] + offset[1]) - # Next, if the new tilepos is within the bounds of the current cell and is passable, simply change the players tilepos - # to that value and reposition the board to the tile. + # Next, if the new tilepos is within the bounds of the current cell and is passable, simply change the players tilepos to that value. if np[1] >= 0 and np[1] < len(self.current_board.current_cell) and np[0] >= 0 and np[0] < len(self.current_board.current_cell[np[1]]): if self.current_board.cellmap[self.player.cellpos][np[1]][np[0]][1]: self.player.tilepos = np - self.current_board.position_to_tile(self.player.tilepos) - self.current_board.check_events_at_tilepos(self.player.tilepos) canmove = True # Otherwise, in case we are trying to move out of the current cell, calculate the relative offset of the new cellpos @@ -183,21 +182,21 @@ class Game(object): celloff = (-1 if offset[0] < 0 else 0 if offset[0] == 0 else 1, -1 if offset[1] < 0 else 0 if offset[1] == 0 else 1) ncc = (self.player.cellpos[0] + celloff[0], self.player.cellpos[1] + celloff[1]) - # Check if we would land on in this new cell. + # Check if we would land in this new cell. if self.current_board.adjacent_cells[celloff] != None and ncc in self.current_board.cellmap.keys(): ntp = (0 if celloff[0] > 0 else self.player.tilepos[0] if celloff[0] == 0 else self.current_board.cell_dimensions[0] - 1, 0 if celloff[1] > 0 else self.player.tilepos[1] if celloff[1] == 0 else self.current_board.cell_dimensions[1] - 1) - # If that tilepos is passable, move the player's cellpos and tilepos, then change the board cell and reposition. + # If that tilepos is passable, move the player's cellpos and tilepos, then change the board cell. if self.current_board.cellmap[ncc][ntp[1]][ntp[0]][1]: self.player.cellpos = ncc self.player.tilepos = ntp self.current_board.change_cell(self.player.cellpos) - self.current_board.position_to_tile(self.player.tilepos) - self.current_board.check_events_at_tilepos(self.player.tilepos) canmove = True - # Finally, post the message + # Finally, post the message, reposition, and check events self.message_board.post("$PLAYERNAME moves " + d[offset] if offset in d.keys() and canmove else "$PLAYERNAME cannot move there!" if not canmove else "", self.gamedata) + self.current_board.position_to_tile(self.player.tilepos) + self.current_board.check_events_at_tilepos(self.player.tilepos) def post_message(self, text): """ @@ -213,6 +212,7 @@ class Game(object): """ # TODO: This will see regular expansion self.gamedata["$PLAYERNAME"] = "Joe" + self.gamedata["$CURRENTBOARDNAME"] = self.current_board.display_name def shift_frames(self, framerate = FRAMERATE): """ diff --git a/src/message.py b/src/message.py @@ -6,7 +6,8 @@ from .gamelib import * ############## # This file contains: -# 1. The 'MessageBoard' class, which is an object that parses text and creates surfaces with that text drawn on it. +# 1. The 'Message' class, which is a simple sprite that is used to represent displayed messages. +# 2. The 'MessageBoard' class, which is an object that parses text and creates surfaces with that text drawn on it. ############################# # Section 1 - Message class # @@ -36,7 +37,7 @@ class Message(pygame.sprite.Sprite): surface.blit(self.image, self.rect) ################################## -# Section 1 - MessageBoard class # +# Section 2 - MessageBoard class # ################################## class MessageBoard(object): @@ -64,13 +65,12 @@ class MessageBoard(object): """ Post a message to the board. """ - # TODO: Make this better + # Only work if text is not an empty string if text != "": # First, parse for data variable names - punc = ",.!?'" - pr = re.split(r"([ " + punc + "])", text) + pr = re.split(r"([ ,.!?':;])", text) for w in range(0, len(pr)): if pr[w] in data.keys(): pr[w] = data[pr[w]]