def main(): tg.initialize() try: layer0 = tg.character_map.load("examples/data/parallax_scroll/layer0.txt") layer1 = tg.character_map.load("examples/data/parallax_scroll/layer1.txt") layer2 = tg.character_map.load("examples/data/parallax_scroll/layer2.txt") screen = tg.character_display.CharacterDisplay(80, layer0.height) timer = tg.Metronome(1.0/25) # continue at 10 frames per second frame = 0 while True: k = tg.keyboard.getch() # this will return a character from the keyboard if one is pressed otherwise None if k != None: break # go until a user presses a key screen.draw_image(0, 0, layer0,'#') screen.draw_image(0, 0, layer1,'#') screen.draw_image(0, 0, layer2,'#') timer.wait_for_tick() # wait until the 1.0/10 second tick happens screen.show() # show the next frame frame += 1 if frame % 20 == 0: layer0.scroll_left() if frame % 3 == 0: layer1.scroll_left() if frame % 1 == 0: layer2.scroll_left() finally: tg.quit()
def main(): """ The main entrypoint to the Flappy Bird game. It initializes librarys including tinygame and creates the Game UI """ tg.initialize() try: while True: gameui = FlappyUI(80, 23, len(sys.argv) == 2 and sys.argv[1] == '--cheat') gameui.intro() # Show the title gameui.play() # simply start playing if gameui.exit: break # Keep playing till the user wants to exit finally: tg.quit()
def main(): """ The main entrypoint to the Tetris game. It initializes librarys including tinygame and creates the Game UI """ tg.initialize() try: while True: gameui = TetrisGameUI() gameui.intro() gameui.play() # simply start playing if gameui.exit: break finally: tg.quit()
def main(args): """ The main entrypoint to the Dringle game. It initializes librarys including tinygame and creates the Game UI """ tg.initialize() try: gameui = DringleUI() if len(args) > 0: gameui.level = int(args[0]) while True: gameui.play_round() if gameui.exit: break finally: tg.quit()
def main(): tg.initialize() try: screen = tg.character_display.CharacterDisplay(40, 30) # create a small 40x30 screen to display stuff screen.write_text(5, 10, "Hello, World!") # write Hello World! around the middle of the display. This is hello world afterall timer = tg.Metronome(1.0/10) # continue at 10 frames per second while True: k = tg.keyboard.getch() # this will return a character from the keyboard if one is pressed otherwise None if k != None: break # go until a user presses a key screen.scroll_left() # keep scrolling the display left (it loops around) timer.wait_for_tick() # wait until the 1.0/10 second tick happens screen.show() # show the next frame finally: tg.quit()
def main(args): """ The entrypoint to this game of life simulation. It is a non-interactive cellular automaton so the user simply sits back and watches. One optional command line argument supplies a file containing a character map of ' ' and '#' as an initial cell state. A default start is provided inside this module. args: command line argument list. Should be empty or exactly one string representing the path to a character map """ if len(args) not in [0,1]: # validate command line arguments print "Usage: python life.py [startmap.txt]" return tg.initialize() try: timer = tg.Metronome(1.0/7) # continue at 5 frames per second start = tg.character_map.parse(DEFAULT_START) # load the default map if len(args) == 1: start = tg.character_map.load(args[0]) # optionally load specified start maps screen = tg.character_display.CharacterDisplay(start.width, start.height) # create a screen of the board size to display stuff prev = tg.character_map.CharacterMap(screen.width, screen.height) # we store the previous next = prev.clone() # and next state in two successive maps prev.draw_image(0, 0, start) while True: k = tg.keyboard.getch() # this will return a character from the keyboard if one is pressed otherwise None if k == tg.keyboard.ESCAPE: break # go until a user presses escape key for y in xrange(0, prev.height): for x in xrange(0, prev.width): n = [(xo,yo) for (xo,yo) in [(-1, -1), (0, -1), (1,-1), (-1, 0), (1, 0), (-1,1), (0, 1), (1,1)] if prev[(x+xo)%prev.width,(y+yo)%prev.height] == '#'] if prev[x,y] == '#': if len(n) < 2: next[x,y] = ' ' # cell dies from under-population elif len(n) in [2,3]: next[x, y] = '#' # it lives on with just the right density else: next[x,y] = ' ' # dies of overcrowding else: if len(n) == 3: next[x,y] = '#' # is born from reproduction else: next[x,y] = ' ' # no new generation screen.draw_image(0, 0, next) prev, next = next, prev # switch the next to the new previous timer.wait_for_tick() # wait until the 1.0/10 second tick happens screen.show() finally: tg.quit()
def main(): """ The main entrypoint to the Breakout game. It initializes librarys including tinygame and creates the Game UI """ tg.initialize() try: gameui = BreakoutGameUI() gameui.intro() while not gameui.done: gameui.show_stats() gameui.play_round() if gameui.lives < 1: gameui.show_gameover() gameui.done = True gameui.finalize() finally: tg.quit()
def main(): """ The main entrypoint to the snake game. It initializes librarys including tinygame and creates the Game UI """ tg.initialize() # initialize tinygame for use in the Snake game try: gameui = SnakeGameUI() # create a UI gameui.intro() while not gameui.done: # loop forever until the UI says it is done gameui.show_stats() # first show the player stats gameui.play_round() # then play a round of Snake game if gameui.lives < 1: # check that the user has lives left gameui.show_gameover() # if not show the game over screen gameui.done = True # then we are done if gameui.level > 5: # check if the user has passed level 5 gameui.show_win() # if so show the user the winners screen gameui.level = 1 # go back to the beginning gameui.finalize() finally: tg.quit()
import sys sys.path.extend(['.', '..']) import tinygame as tg tg.initialize() try: screen = tg.character_display.CharacterDisplay(40, 20) cmap = tg.character_map.load(sys.argv[1]) x, y = 0, 0 while True: k = tg.keyboard.getch(1/10.0) if k == tg.keyboard.KEY_LEFT: x -= 1 if k == tg.keyboard.KEY_RIGHT: x += 1 if k == tg.keyboard.KEY_UP: y -= 1 if k == tg.keyboard.KEY_DOWN: y += 1 if k == tg.keyboard.KEY_ESCAPE: break screen.fill(' ') screen.draw_image(-x, -y, cmap) screen.show() finally: tg.quit()