#
# 2D platform scrolling game that teaches binary logic
-import sys, os, time, random, pygame
+import sys, os, time, random, math, pygame
import engine
# Use conditionals in the code to print useful information to the console using the form:
screen = None # the pygame Screen for the game window
def __init__(self, width, height, title, resources={}, debug=False):
+ os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()
self.debug = debug
self.myGame = engine.Game(width, height, title, resources, debug=self.debug)
+ if self.myGame.config['sound'] == 1:
+ self.myGame.soundtrack.playlist(self.myGame.resources['soundtrack'])
+
self.background_colour = (20, 20, 64)
if 'icon' in self.myGame.resources:
if self.debug: engine.debug_pr("pygame.image.get_extended()=%r" % pygame.image.get_extended())
# starting position
y = resolution[1] / 2
- if self.myGame.config['sound'] == 1:
- self.myGame.soundtrack.playlist(self.myGame.resources['soundtrack'])
-
self.myGame.config['auto_scroll'] = False
movement = 0 # represents number of pixels, and direction, of next scroll
x_pos = 0 # coordinate of left side of viewport
self.myGame.soundtrack.pause()
elif k == pygame.K_l:
self.myGame.config['auto_scroll'] = True if self.myGame.config['auto_scroll'] == False else False
+ elif k >= pygame.K_F1 and k <= pygame.K_F12:
+ self.stepping = k - (pygame.K_F1 - 1)
+ if self.myGame.config['auto_scroll']:
+ movement = int(math.copysign(self.stepping, movement))
+ if self.debug: engine.debug_pr("Keypress=%d, movement=%d" % (k, movement))
if event.type == pygame.USEREVENT:
if self.debug: engine.debug_pr("pygame.USEREVENT received; calling playlist_next()")
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)
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)