summary refs log tree commit diff stats
path: root/src/direction.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-01-30 16:15:55 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-01-30 16:15:55 -0500
commitd1df87ce04f6d79fed94ab154fa098ccc83ebab8 (patch)
tree191a5a1f1d659207df50dd8a7ebe46da8504a144 /src/direction.h
parentb9fe1b45127085d8a7c664245dd070afd8cbf3b4 (diff)
downloadtanetane-d1df87ce04f6d79fed94ab154fa098ccc83ebab8.tar.gz
tanetane-d1df87ce04f6d79fed94ab154fa098ccc83ebab8.tar.bz2
tanetane-d1df87ce04f6d79fed94ab154fa098ccc83ebab8.zip
Added crouching/running
Diffstat (limited to 'src/direction.h')
-rw-r--r--src/direction.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/direction.h b/src/direction.h index 0679a00..ebc0e46 100644 --- a/src/direction.h +++ b/src/direction.h
@@ -3,6 +3,7 @@
3 3
4#include <string> 4#include <string>
5#include <stdexcept> 5#include <stdexcept>
6#include "vector.h"
6 7
7enum class Direction { 8enum class Direction {
8 up, 9 up,
@@ -27,4 +28,17 @@ inline Direction directionFromString(std::string_view str) {
27 throw std::invalid_argument("Invalid direction: " + std::string(str)); 28 throw std::invalid_argument("Invalid direction: " + std::string(str));
28} 29}
29 30
31inline vec2i unitVecInDirection(Direction dir) {
32 switch (dir) {
33 case Direction::up: return { 0, -1 };
34 case Direction::up_right: return { 1, -1 };
35 case Direction::right: return { 1, 0 };
36 case Direction::down_right: return { 1, 1 };
37 case Direction::down: return { 0, 1 };
38 case Direction::down_left: return { -1, 1 };
39 case Direction::left: return { -1, 0 };
40 case Direction::up_left: return { -1, -1 };
41 }
42}
43
30#endif /* end of include guard: DIRECTION_H_AB66A90E */ 44#endif /* end of include guard: DIRECTION_H_AB66A90E */