# Use conditionals in the code to print useful information to the console using the form:
# if self.debug: engine.debug_pr("some_var=%d, another_var=%s" % (some_var, another_var), somevalue, another_value)
-class Base2Runner:
+class Base2Runner(object):
background_image = None
stepping = 8 # pixels scrolled each flip
delay = 0.01 # main loop sleep (100 milliseconds)
pygame.display.set_icon(self.icon_image)
def play(self):
+ error_code = 0
self.screen = pygame.display.set_mode(self.myGame.resolution, self.flags, self.depth)
self.screen.fill(self.background_colour)
pygame.display.set_caption(self.myGame.config['title'])
self.myGame.soundtrack.fadeout(5000)
time.sleep(5)
pygame.display.quit()
+ return error_code
-def main(width, height, title, resources={}, debug=False):
- game = Base2Runner(width, height, title, resources, debug)
- time.sleep(10) # keep splash screen up for a little longer
- game.play()
- exit(0)
+ def main(self, args, env)
+ """ entry point for starting the game """
+ time.sleep(10) # keep splash screen up for a little longer
+ return self.play()
+
if __name__ == '__main__':
+ # define some basic resources
resources = {}
resources['path'] = 'resources'
resources['icon'] = 'base2runner-icon.png'
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)
+
+ # instantiate the program, which will also initialise the display and show a splash screen
+ app = Base2Runner(iwidth=900, height=600, title="BaseĀ² Runner", resources=resources, debug=True)
+ # start the program with any command-line arguments and environment and exit using any error code it returns
+ exit( app.main(sys.argv[1:], os.environ) )