1
0
python-roguelike/main.py
2022-01-18 14:04:05 -05:00

94 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
import copy
import traceback
import tcod
import color
from engine import Engine
import entity_factories
import exceptions
import input_handlers
from procgen import generate_dungeon
def main() -> None:
screen_width = 80
screen_height = 50
map_width = 80
map_height = 43
room_max_size = 10
room_min_size = 6
max_rooms = 30
max_monsters_per_room = 2
max_items_per_room = 2
tileset = tcod.tileset.load_tilesheet(
"dejavu10x10_gs_tc.png",
32,
8,
tcod.tileset.CHARMAP_TCOD
)
player = copy.deepcopy(entity_factories.player)
engine = Engine(player)
engine.game_map = generate_dungeon(
max_rooms,
room_min_size,
room_max_size,
map_width,
map_height,
max_monsters_per_room,
max_items_per_room,
engine,
)
engine.update_fov()
engine.message_log.add_message(
"Hello and welcome, adventurer, to yet another dungeon!",
color.welcome_text
)
handler: input_handlers.BaseEventHandler = input_handlers.MainGameEventHandler(engine)
with tcod.context.new_terminal(
screen_width,
screen_height,
tileset=tileset,
title="Yet Another Roguelike Tutorial",
vsync=True,
) as context:
root_console = tcod.Console(screen_width, screen_height, order="F")
try:
while True:
root_console.clear()
engine.event_handler.on_render(console=root_console)
context.present(root_console)
try:
for event in tcod.event.wait():
context.convert_event(event)
engine.event_handler.handle_events(event)
except Exception: # Handle exceptions in game.
traceback.print_exc() # Print error to stderr.
# Then print the error to the message log.
engine.message_log.add_message(traceback.format_exc(), color.error)
except exceptions.QuitWithoutSaving:
raise
except SystemExit: # Save and quit.
# TODO: Add the save function here
raise
except BaseException: # Save on any other unexpected exception.
# TODO: Add the save function here
raise
if __name__ == "__main__":
main()