1
0
python-roguelike/main.py

55 lines
1.5 KiB
Python
Raw Normal View History

2022-01-06 11:09:43 -05:00
#!/usr/bin/env python3
import tcod
from actions import EscapeAction, MovementAction
2022-01-06 11:19:56 -05:00
from entity import Entity
2022-01-06 11:09:43 -05:00
from input_handlers import EventHandler
def main() -> None:
screen_width = 80
screen_height = 50
tileset = tcod.tileset.load_tilesheet(
"dejavu10x10_gs_tc.png",
32,
8,
tcod.tileset.CHARMAP_TCOD
)
event_handler = EventHandler()
2022-01-06 11:19:56 -05:00
player = Entity(int(screen_width / 2), int(screen_height/ 2), "@", (255, 255, 255))
npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@", (255, 255, 0))
entities = {npc, player}
2022-01-06 11:09:43 -05:00
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")
while True:
2022-01-06 11:19:56 -05:00
root_console.print(x=player.x, y=player.y, string=player.char, fg=player.color)
2022-01-06 11:09:43 -05:00
# Actually display on the screen
context.present(root_console)
root_console.clear()
for event in tcod.event.wait():
action = event_handler.dispatch(event)
if action is None:
continue
if isinstance(action, MovementAction):
2022-01-06 11:19:56 -05:00
player.move(dx=action.dx, dy=action.dy)
2022-01-06 11:09:43 -05:00
elif isinstance(action, EscapeAction):
raise SystemExit()
if __name__ == "__main__":
main()