I made it work! a bit.. when it was real time, it just jumped alot of tiles whatever direction you pressed, leaving a long trail of shitty @'s, if it moved outside, the piece of junk crashes, now my attempt to fix it, broke it. And i have no means of debugging due to my enviroment being IDLE on Python 2.5 and libtcod. This is shit.
import string
import random
import libtcodpy as libtcod
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
LIMIT_FPS = 20
debug = 1
null = 0
#Read material list
mat_list = []
f = open('./mat_list.txt')
for line in f:
mat_list.append(line.strip())
#Sort list alphabetically, thanks god for this function, otherwise it'd be painful.
mat_list.sort()
#initialise libtcod stuff
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
#SPAGETTHI! Nah its just the key handling function, just as the tut sez..
def handle_keys():
key = libtcod.console.check_for_keypress(True) #<- This will make it wait for a keypress :)
if key.vk == libtcod.KEY_ENTER and libtcod.KEY_ALT:
#Alt+Enter: toggle fullscreen
libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
elif key.vk == libtcod.KEY_ESCAPE:
return True #poo
global playerx, playery
#movement keys lol
if libtcod.console_is_key_pressed(libtcod.KEY_UP):
playery -= 1
elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
playery += 1
elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
playerx -= 1
elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
playerx += 1
#center player on map
playerx = SCREEN_WIDTH/2
playery = SCREEN_HEIGHT/2
#Main loop
while not libtcod.console_is_window_closed():
libtcod.console_set_foreground_color(0, libtcod.white)
libtcod.console_print_left(0, playerx, playery, libtcod.BKGND_NONE, '@')
#update screen
libtcod.console_flush()
#handle keys and exit game if needed
exit = handle_keys()
if exit:
break
i think i coded enough for the day..