summary refs log tree commit diff stats
path: root/src/direction.cpp
blob: cf6409e6013e345ae9bac1b01a2757b7fce05c01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "direction.h"

vec2s posInDir(vec2s orig, Direction dir)
{
  switch (dir)
  {
    case Direction::left: return orig - vec2s { 1, 0 };
    case Direction::right: return orig + vec2s { 1, 0 };
    case Direction::up: return orig - vec2s { 0, 1 };
    case Direction::down: return orig + vec2s { 0, 1 };
    case Direction::none: return orig;
  }
}

Direction oppositeDir(Direction dir)
{
  switch (dir)
  {
    case Direction::left: return Direction::right;
    case Direction::right: return Direction::left;
    case Direction::up: return Direction::down;
    case Direction::down: return Direction::up;
    case Direction::none: return Direction::none;
  }
}