Skip to content

Instantly share code, notes, and snippets.

@schas002
Created June 17, 2016 12:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save schas002/b39195317aa848137891dc208860fc4d to your computer and use it in GitHub Desktop.
A roguelike in Python, using libtcod.
# The name libtcodpy is very funky (sorry Jice!)
import libtcodpy as libtcod
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
LIMIT_FPS = 20
def handle_keys():
key = libtcod.console_wait_for_keypress(True)
if key.vk == libtcod.KEY_ESCAPE:
# Exit game
return True
libtcod.console_set_custom_font(
'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD
)
libtcod.console_init_root(
SCREEN_WIDTH, SCREEN_HEIGHT, 'firstrl', False
)
while not libtcod.console_is_window_closed():
libtcod.console_set_default_foreground(0, libtcod.white)
libtcod.console_put_char(0, 0, 1, 'H', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 1, 1, 'e', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 2, 1, 'l', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 3, 1, 'l', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 4, 1, 'o', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 5, 1, ',', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 7, 1, 'W', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 8, 1, 'o', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 9, 1, 'r', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 10, 1, 'l', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 11, 1, 'd', libtcod.BKGND_NONE)
libtcod.console_put_char(0, 12, 1, '!', libtcod.BKGND_NONE)
libtcod.console_flush()
# Handle keys and break out of the loop
finished = handle_keys()
if finished:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment