From 77e6bdcf306165daba4c29625452ed09b64d5547 Mon Sep 17 00:00:00 2001 From: TJ Date: Thu, 14 Nov 2013 22:32:11 +0000 Subject: [PATCH] Add soundtrack credits to splash screen --- base2-runner.py | 5 ++++- engine/Game.py | 52 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/base2-runner.py b/base2-runner.py index e00642e..ff79dc1 100755 --- a/base2-runner.py +++ b/base2-runner.py @@ -154,6 +154,9 @@ if __name__ == '__main__': resources['icon'] = 'base2runner-icon.png' resources['background'] = 'binary-1024x1024.jpg' resources['splash'] = 'base2runner.jpg' - resources['soundtrack'] = 'Music' resources['copyright'] = '© Copyright 2013 TJ ' + resources['soundtrack'] = 'Music' + resources['soundtrack.copyright'] = 'Rolemusic @ The Free Music Archive' + resources['soundtrack.license'] = 'Creative Commons Attribution Non-Commercial Share-Alike' + resources['soundtrack.url'] = 'http://freemusicarchive.org/music/Rolemusic/' main(900, 600, "Base² Runner", resources, debug=True) diff --git a/engine/Game.py b/engine/Game.py index 203be80..d20ab21 100755 --- a/engine/Game.py +++ b/engine/Game.py @@ -6,12 +6,27 @@ import os.path, pygame, engine +class Style: + """ Encapsulate the attributes required for printing styled text """ + font = None + colour = None + height = 0 + + def __init__(self, font, height, colour, debug=False): + self.font = pygame.font.Font(font, height) + self.height = height + self.colour = colour + self.debug = debug + if self.debug: engine.debug_pr("Style %s, height: %d, colour:" % (font, height), self.colour) + class Game: """ Container for all game state and configuration items """ config = dict() - fonts = dict() - colours = dict() + styles = dict() resources = None + # text printing origin + print_x = 0 + print_y = 0 def res_path(self, key): """ Create a complete resource path @@ -31,9 +46,9 @@ class Game: resources: Dictionary containing resources debug: enable debug messages written to console """ - # define the colour styles we need - self.colours['h1'] = (255, 255, 255) - self.colours['body'] = (0, 255, 255) + # define the styles for printed text + self.styles['h1'] = engine.Style(None, 80, (255, 255, 255)) + self.styles['body'] = engine.Style(None, 30, (255, 255, 0)) # store the received values self.config.update({'width':width, 'height':height}) @@ -62,6 +77,16 @@ class Game: # splash screen self.splash() + def print(self, text, style): + """ print a line of text and move the text origin to the next line """ + if not style in self.styles: + style = 'body' + # don't do a blit operation unless there is some text to render + if len(text) > 0: + self.splash_screen.blit(self.styles[style].font.render(text, True, self.styles[style].colour), (self.print_x, self.print_y)) + + self.print_y += self.styles[style].height # update the text origin + def splash(self): # draw the splash screen if self.resources['splash']: @@ -74,12 +99,17 @@ class Game: self.splash_screen = pygame.display.set_mode(resolution, pygame.NOFRAME) self.splash_image = pygame.image.load(self.resources['splash']).convert() self.splash_screen.blit(self.splash_image, (0,0)) - self.fonts['h1'] = pygame.font.Font(None, 80) - self.fonts['body'] = pygame.font.Font(None, 30) - x, y = 40, 10 - self.splash_screen.blit(self.fonts['h1'].render(self.resources['title'], True, self.colours['h1']), (x, y)) - y += 80 - self.splash_screen.blit(self.fonts['body'].render(self.resources['copyright'], True, self.colours['body']), (x, y)) + # print the Game title and copyright + self.print_x, self.print_y = 40, 40 # indent + self.print(self.resources['title'], 'h1') + self.print(self.resources['copyright'], 'body') + # print the Soundtrack copyright information + self.print('Soundtrack:', 'body') + self.print_x += 20 # indent + for key in ('copyright', 'license', 'url'): + text = "%s: %s" % (key, self.resources["soundtrack.%s" % key]) + self.print(text, 'body') + pygame.display.update() def pause(self): -- 2.17.1