Return to repo list

tzed

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

commit 994194902777cd66906a3d05ad4751b3a40035cf
parent d96a4fac1853c46346cdb5d1fbff9b37bd2f189e
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed, 25 Aug 2021 16:55:00 -0500

added message feature and fonts

Diffstat:
MLICENSE | 2++
Mdata/etc/defaults.json | 2++
Adata/fonts/PixelOperatorMono.ttf | 0
Mmain.py | 2++
Msrc/game.py | 15++++++++++++++-
Msrc/gamelib.py | 2++
Asrc/message.py | 47+++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/LICENSE b/LICENSE @@ -2,6 +2,8 @@ Licensing details for Tzed: 1. All code and other non-media (that is, non-image, non-sound, non-font) files are released under the terms of the MIT/Expat License. 2. All media (that is, image and sound) files are released under the terms of the CC0 Public Domain Dedication License, unless otherwise noted. + 3. All font files are released under the terms of the CC0 Public Domain Dedication License. The fonts used were created by third parties and are credited as follows: + I) Pixel Operator Font (data/fonts/PixelOperatorMono.ttf) by Jayvee Enaguas (HarvettFox96) (https://harvettfox96.neocities.org/) MEDIA EXCEPTIONS: The following files are derived from other free sources, and are released under different licenses noted here: diff --git a/data/etc/defaults.json b/data/etc/defaults.json @@ -4,6 +4,8 @@ "screen_margin_x" : 4, "screen_margin_y" : 4, "framerate" : 30, + "message_font" : "PixelOperatorMono.ttf", + "message_font_size" : 14, "controls" : { "up" : [119, 1073741906], "down" : [115, 1073741905], diff --git a/data/fonts/PixelOperatorMono.ttf b/data/fonts/PixelOperatorMono.ttf Binary files differ. diff --git a/main.py b/main.py @@ -11,6 +11,8 @@ from src import game # Pre-init - set pygame mixer settings and init pygame pygame.mixer.pre_init(44100, -16, 4, 1024) pygame.init() +if not pygame.font: + print("FONTS DISABLED") # Start the game if __name__ == "__main__": diff --git a/src/game.py b/src/game.py @@ -1,5 +1,5 @@ import pygame, os, json -from . import interface, images, board, entity, ui +from . import interface, images, board, entity, ui, message from .gamelib import * ########### @@ -39,6 +39,7 @@ class Game(object): # Game components self.interface = interface.Interface(self) + self.message_board = message.MessageBoard(self, (20, 20), (99, 99)) # Pygame sprite objects self.player = None @@ -51,6 +52,7 @@ class Game(object): self.sheets = {} self.loaded_boards = {} self.current_board = None + self.gamedata = {} # Loading self.load_sheets("sheets.json") @@ -187,6 +189,14 @@ class Game(object): self.current_board.position_to_tile(self.player.tilepos) self.current_board.check_events_at_tilepos(self.player.tilepos) + def collect_game_data(self): + """ + Collect a bunch of info about the current + state of the game and game objects. + """ + # TODO: This will see regular expansion + self.gamedata["player_name"] = "Joe" + def shift_frames(self, framerate = FRAMERATE): """ Shift to the next frame of the game at the specified @@ -213,6 +223,9 @@ class Game(object): self.player.update(self.screen, self.viewport_rect) self.ui_group.update(self.screen) + # Next, get info about the game + self.collect_game_data() + # Last, update the screen pygame.display.update() diff --git a/src/gamelib.py b/src/gamelib.py @@ -38,6 +38,8 @@ SCREEN_HEIGHT = SETTINGS_RAW["screen_height"] SCREEN_MARGINS = (SETTINGS_RAW["screen_margin_x"], SETTINGS_RAW["screen_margin_y"]) FRAMERATE = SETTINGS_RAW["framerate"] CONTROLS = SETTINGS_RAW["controls"] +MESSAGE_FONT = SETTINGS_RAW["message_font"] +MESSAGE_FONT_SIZE = SETTINGS_RAW["message_font_size"] COLOR_PALETTE = tuple(tuple(color) for color in SETTINGS_RAW["color_palette"]) OVERLAY_SHEET = SETTINGS_RAW["overlay_sheet"] diff --git a/src/message.py b/src/message.py @@ -0,0 +1,47 @@ +import pygame +from .gamelib import * + +############## +# message.py # +############## + +# This file contains: +# 1. The 'MessageBoard' class, which is an object that parses text and creates surfaces with that text drawn on it. + +################################## +# Section 2 - MessageBoard class # +################################## + +class MessageBoard(object): + """ + MessageBoard is a manager class that posts + and organizes messages and displays them on + the right-hand side of the game screen. + """ + + def __init__(self, game, board_dim, board_pos): + + # Saved vals + self.game = game + self.board_rect = pygame.Rect(board_pos, board_dim) + + # Font vals + self.font = pygame.font.Font(os.path.join(FONT_PATH, MESSAGE_FONT), MESSAGE_FONT_SIZE) + + # Other vals + self.messages = [] + + def post(self, text, data): + """ + Post a message to the board. + """ + # TODO: Make this better + self.messages.add + + def update_board(self, surface = None): + """ + Draw messages to the screen in post order. + """ + if surface != None: + pass +