resources['icon'] = 'base2runner-icon.png'
resources['background'] = 'binary-1024x1024.jpg'
resources['splash'] = 'base2runner.jpg'
- resources['soundtrack'] = 'Music'
resources['copyright'] = '© Copyright 2013 TJ <hacker@iam.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)
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
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})
# 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']:
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):