going-rogue/roguebasin/events.py

38 lines
1.3 KiB
Python
Raw Normal View History

2022-04-30 21:59:01 -07:00
#!/usr/bin/env python3
# Eryn Wells <eryn@erynwells.me>
import tcod
from .actions import Action, ExitAction, RegenerateRoomsAction, BumpAction
from .geometry import Direction
2022-04-30 21:59:01 -07:00
from typing import Optional
class EventHandler(tcod.event.EventDispatch[Action]):
def ev_quit(self, event: tcod.event.Quit) -> Optional[Action]:
return ExitAction()
def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
action: Optional[Action] = None
sym = event.sym
2022-05-04 09:25:35 -07:00
if sym == tcod.event.KeySym.b:
action = BumpAction(Direction.SouthWest)
2022-05-04 09:25:35 -07:00
elif sym == tcod.event.KeySym.h:
action = BumpAction(Direction.West)
2022-04-30 21:59:01 -07:00
elif sym == tcod.event.KeySym.j:
action = BumpAction(Direction.South)
2022-04-30 21:59:01 -07:00
elif sym == tcod.event.KeySym.k:
action = BumpAction(Direction.North)
2022-04-30 21:59:01 -07:00
elif sym == tcod.event.KeySym.l:
action = BumpAction(Direction.East)
2022-05-04 09:25:35 -07:00
elif sym == tcod.event.KeySym.n:
action = BumpAction(Direction.SouthEast)
2022-05-04 09:25:35 -07:00
elif sym == tcod.event.KeySym.u:
action = BumpAction(Direction.NorthEast)
2022-05-04 09:25:35 -07:00
elif sym == tcod.event.KeySym.y:
action = BumpAction(Direction.NorthWest)
2022-04-30 21:59:01 -07:00
elif sym == tcod.event.KeySym.SPACE:
action = RegenerateRoomsAction()
return action