diff --git a/roguebasin/__main__.py b/roguebasin/__main__.py index 53aff78..e4615c7 100644 --- a/roguebasin/__main__.py +++ b/roguebasin/__main__.py @@ -1,8 +1,11 @@ #!/usr/bin/env python3 # Eryn Wells -from . import object +from . import actions +from . import events +from . import geometry from . import main +from . import object from . import tile if __name__ == '__main__': diff --git a/roguebasin/actions.py b/roguebasin/actions.py new file mode 100644 index 0000000..1caf3a2 --- /dev/null +++ b/roguebasin/actions.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +# Eryn Wells + +class Action: + pass + +class ExitAction(Action): + pass + +class RegenerateRoomsAction(Action): + pass + +class MovePlayerAction(Action): + class Direction: + North = (0, -1) + NorthEast = (1, -1) + East = (1, 0) + SouthEast = (1, 1) + South = (0, 1) + SouthWest = (-1, 1) + West = (-1, 0) + NorthWest = (-1, -1) + + def __init__(self, direction: Direction): + self.direction = direction \ No newline at end of file diff --git a/roguebasin/events.py b/roguebasin/events.py new file mode 100644 index 0000000..588e1f8 --- /dev/null +++ b/roguebasin/events.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +# Eryn Wells + +import tcod +from .actions import Action, ExitAction, MovePlayerAction, RegenerateRoomsAction +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 + + if sym == tcod.event.KeySym.h: + action = MovePlayerAction(MovePlayerAction.Direction.West) + elif sym == tcod.event.KeySym.j: + action = MovePlayerAction(MovePlayerAction.Direction.South) + elif sym == tcod.event.KeySym.k: + action = MovePlayerAction(MovePlayerAction.Direction.North) + elif sym == tcod.event.KeySym.l: + action = MovePlayerAction(MovePlayerAction.Direction.East) + elif sym == tcod.event.KeySym.SPACE: + action = RegenerateRoomsAction() + + return action