59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
import tcod as tc
|
|
from entity import Entity
|
|
from render_functions import *
|
|
from game_map import *
|
|
from input_handlers import handle_keys
|
|
|
|
|
|
def main():
|
|
screen_width = 80
|
|
screen_height = 50
|
|
map_width = 80
|
|
map_height = 50
|
|
|
|
colors = {
|
|
'dark_wall': tc.Color(0, 0, 100),
|
|
'dark_ground': tc.Color(50, 50, 150)
|
|
}
|
|
|
|
player = Entity(int(screen_width/2), int(screen_height/2), '@', tc.white)
|
|
npc = Entity(int(screen_width/2), int(screen_height/2), '@', tc.yellow)
|
|
entities = [npc, player]
|
|
|
|
tc.console_set_custom_font('arial10x10.png', tc.FONT_TYPE_GREYSCALE | tc.FONT_LAYOUT_TCOD)
|
|
|
|
tc.console_init_root(screen_width, screen_height, 'tutorial revised', False)
|
|
con = tc.console_new(screen_width, screen_height)
|
|
|
|
game_map = GameMap(map_width, map_height)
|
|
|
|
key = tc.Key()
|
|
mouse = tc.Mouse()
|
|
|
|
while not tc.console_is_window_closed():
|
|
tc.sys_check_for_event(tc.EVENT_KEY_PRESS, key, mouse)
|
|
render_all(con, entities, game_map, screen_width, screen_height, colors)
|
|
tc.console_flush()
|
|
|
|
clear_all(con, entities)
|
|
|
|
action = handle_keys(key)
|
|
|
|
move = action.get('move')
|
|
exit = action.get('exit')
|
|
fullscreen = action.get('fullscreen')
|
|
|
|
if move:
|
|
dx, dy = move
|
|
if not game_map.is_blocked(player.x + dx, player.y + dy):
|
|
player.move(dx, dy)
|
|
|
|
if exit:
|
|
return True
|
|
|
|
if fullscreen:
|
|
tc.console_set_fullscreen(not tc.console_is_fullscreen())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |