commit a58200921075e440b0cc3a0a4a871d5d30640fdb Author: Dan Dembinski Date: Sat Jun 22 21:27:19 2019 -0400 Finished Part 1 diff --git a/arial10x10.png b/arial10x10.png new file mode 100644 index 0000000..64691f1 Binary files /dev/null and b/arial10x10.png differ diff --git a/engine.py b/engine.py new file mode 100644 index 0000000..b9e0bd5 --- /dev/null +++ b/engine.py @@ -0,0 +1,46 @@ +import tcod +from input_handlers import handle_keys + +def main(): + screen_width = 80 + screen_height = 50 + + player_x = int(screen_width/2) + player_y = int(screen_height/2) + + tcod.console_set_custom_font('arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) + + tcod.console_init_root(screen_width, screen_height, 'tutorial revised', False) + con = tcod.console_new(screen_width, screen_height) + + key = tcod.Key() + mouse = tcod.Mouse() + + while not tcod.console_is_window_closed(): + tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse) + tcod.console_set_default_foreground(con, tcod.white) + tcod.console_put_char(con, player_x, player_y, '@', tcod.BKGND_NONE) + tcod.console_blit(con, 0,0, screen_width, screen_height, 0,0,0) + tcod.console_flush() + + tcod.console_put_char(con, player_x, player_y, ' ', tcod.BKGND_NONE) + + action = handle_keys(key) + + move = action.get('move') + exit = action.get('exit') + fullscreen = action.get('fullscreen') + + if move: + dx, dy = move + player_x += dx + player_y += dy + + if exit: + return True + + if fullscreen: + tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/input_handlers.py b/input_handlers.py new file mode 100644 index 0000000..adfc786 --- /dev/null +++ b/input_handlers.py @@ -0,0 +1,18 @@ +import tcod + +def handle_keys(key): + if key.vk == tcod.KEY_UP: + return {'move': (0,-1)} + elif key.vk == tcod.KEY_DOWN: + return {'move': (0,1)} + elif key.vk == tcod.KEY_LEFT: + return {'move':(-1,0)} + elif key.vk == tcod.KEY_RIGHT: + return {'move':(1,0)} + + if key.vk == tcod.KEY_ENTER and key.lalt: + return {'fullscreen':True} + elif key.vk == tcod.KEY_ESCAPE: + return {'exit': True} + + return {} \ No newline at end of file