diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-22 17:25:59 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-22 17:25:59 -0500 |
commit | 26fbd8c1edaf94513d9750681edbe449b699efe4 (patch) | |
tree | 3356e61d3eca5eda067169a2c584616a49d8e5a5 /src/direction.cpp | |
parent | d9c201cbf2fbfe315137e141d886a9bbfa6794ba (diff) | |
download | dispatcher-26fbd8c1edaf94513d9750681edbe449b699efe4.tar.gz dispatcher-26fbd8c1edaf94513d9750681edbe449b699efe4.tar.bz2 dispatcher-26fbd8c1edaf94513d9750681edbe449b699efe4.zip |
Trains move on tracks to the beat
Small implementation changes in various places, biggest thing is now we're using ranges, which is experimental and will be included for real in C++20.
Diffstat (limited to 'src/direction.cpp')
-rw-r--r-- | src/direction.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/direction.cpp b/src/direction.cpp new file mode 100644 index 0000000..cf6409e --- /dev/null +++ b/src/direction.cpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "direction.h" | ||
2 | |||
3 | vec2s posInDir(vec2s orig, Direction dir) | ||
4 | { | ||
5 | switch (dir) | ||
6 | { | ||
7 | case Direction::left: return orig - vec2s { 1, 0 }; | ||
8 | case Direction::right: return orig + vec2s { 1, 0 }; | ||
9 | case Direction::up: return orig - vec2s { 0, 1 }; | ||
10 | case Direction::down: return orig + vec2s { 0, 1 }; | ||
11 | case Direction::none: return orig; | ||
12 | } | ||
13 | } | ||
14 | |||
15 | Direction oppositeDir(Direction dir) | ||
16 | { | ||
17 | switch (dir) | ||
18 | { | ||
19 | case Direction::left: return Direction::right; | ||
20 | case Direction::right: return Direction::left; | ||
21 | case Direction::up: return Direction::down; | ||
22 | case Direction::down: return Direction::up; | ||
23 | case Direction::none: return Direction::none; | ||
24 | } | ||
25 | } | ||