# 2D platform scrolling game that teaches binary logic
import sys, os, time, random, math, pygame
-import engine
+import engine, circuits
# 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['background'] = 'binary-1024x1024.jpg'
resources['splash'] = 'base2runner.jpg'
- resources['soundtrack'] = 'Music'
resources['copyright'] = '© Copyright 2013 TJ <hacker@iam.tj>'
- main(900, 600, "Base² Runner", resources, debug=True)
+ 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/'
+
+ # instantiate the program, which will also initialise the display and show a splash screen
+ app = Base2Runner(width=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) )