Add actions and events modules
This commit is contained in:
parent
367b284d31
commit
9ddeef2561
3 changed files with 57 additions and 1 deletions
|
@ -1,8 +1,11 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
from . import object
|
from . import actions
|
||||||
|
from . import events
|
||||||
|
from . import geometry
|
||||||
from . import main
|
from . import main
|
||||||
|
from . import object
|
||||||
from . import tile
|
from . import tile
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
25
roguebasin/actions.py
Normal file
25
roguebasin/actions.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
|
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
|
28
roguebasin/events.py
Normal file
28
roguebasin/events.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
|
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
|
Loading…
Add table
Add a link
Reference in a new issue