Move MovePlayerAction.Direction to geometry.Direction
This commit is contained in:
parent
010c67fd78
commit
e1044f3a73
3 changed files with 21 additions and 15 deletions
|
@ -2,7 +2,12 @@
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from .geometry import Vector
|
from .geometry import Direction
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .engine import Engine
|
||||||
|
from .object import Entity
|
||||||
|
|
||||||
LOG = logging.getLogger('events')
|
LOG = logging.getLogger('events')
|
||||||
|
|
||||||
|
@ -26,16 +31,6 @@ class RegenerateRoomsAction(Action):
|
||||||
...
|
...
|
||||||
|
|
||||||
class MovePlayerAction(Action):
|
class MovePlayerAction(Action):
|
||||||
class Direction:
|
|
||||||
North = Vector(0, -1)
|
|
||||||
NorthEast = Vector(1, -1)
|
|
||||||
East = Vector(1, 0)
|
|
||||||
SouthEast = Vector(1, 1)
|
|
||||||
South = Vector(0, 1)
|
|
||||||
SouthWest = Vector(-1, 1)
|
|
||||||
West = Vector(-1, 0)
|
|
||||||
NorthWest = Vector(-1, -1)
|
|
||||||
|
|
||||||
def __init__(self, direction: Direction):
|
def __init__(self, direction: Direction):
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import tcod
|
import tcod
|
||||||
from .actions import Action, ExitAction, MovePlayerAction, RegenerateRoomsAction
|
from .actions import Action, ExitAction, MovePlayerAction, RegenerateRoomsAction
|
||||||
|
from .geometry import Direction
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
class EventHandler(tcod.event.EventDispatch[Action]):
|
class EventHandler(tcod.event.EventDispatch[Action]):
|
||||||
|
@ -15,13 +16,13 @@ class EventHandler(tcod.event.EventDispatch[Action]):
|
||||||
sym = event.sym
|
sym = event.sym
|
||||||
|
|
||||||
if sym == tcod.event.KeySym.h:
|
if sym == tcod.event.KeySym.h:
|
||||||
action = MovePlayerAction(MovePlayerAction.Direction.West)
|
action = MovePlayerAction(Direction.West)
|
||||||
elif sym == tcod.event.KeySym.j:
|
elif sym == tcod.event.KeySym.j:
|
||||||
action = MovePlayerAction(MovePlayerAction.Direction.South)
|
action = MovePlayerAction(Direction.South)
|
||||||
elif sym == tcod.event.KeySym.k:
|
elif sym == tcod.event.KeySym.k:
|
||||||
action = MovePlayerAction(MovePlayerAction.Direction.North)
|
action = MovePlayerAction(Direction.North)
|
||||||
elif sym == tcod.event.KeySym.l:
|
elif sym == tcod.event.KeySym.l:
|
||||||
action = MovePlayerAction(MovePlayerAction.Direction.East)
|
action = MovePlayerAction(Direction.East)
|
||||||
elif sym == tcod.event.KeySym.SPACE:
|
elif sym == tcod.event.KeySym.SPACE:
|
||||||
action = RegenerateRoomsAction()
|
action = RegenerateRoomsAction()
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,16 @@ class Vector:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'(δx:{self.x}, δy:{self.y})'
|
return f'(δx:{self.x}, δy:{self.y})'
|
||||||
|
|
||||||
|
class Direction:
|
||||||
|
North = Vector(0, -1)
|
||||||
|
NorthEast = Vector(1, -1)
|
||||||
|
East = Vector(1, 0)
|
||||||
|
SouthEast = Vector(1, 1)
|
||||||
|
South = Vector(0, 1)
|
||||||
|
SouthWest = Vector(-1, 1)
|
||||||
|
West = Vector(-1, 0)
|
||||||
|
NorthWest = Vector(-1, -1)
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Size:
|
class Size:
|
||||||
width: int = 0
|
width: int = 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue