Finished Part 1

This commit is contained in:
2019-06-22 21:27:19 -04:00
commit a582009210
3 changed files with 64 additions and 0 deletions

BIN
arial10x10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

46
engine.py Normal file
View File

@@ -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()

18
input_handlers.py Normal file
View File

@@ -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 {}