diff options
Diffstat (limited to 'src/model/Position.hpp')
-rw-r--r-- | src/model/Position.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/model/Position.hpp b/src/model/Position.hpp index b68476f..84044e6 100644 --- a/src/model/Position.hpp +++ b/src/model/Position.hpp @@ -26,6 +26,8 @@ #pragma once +#include "Direction.hpp" + namespace RPGEdit { @@ -33,6 +35,33 @@ namespace Model { struct Position { float x, y; + + Position translate(Direction dir, float amount) const { + Position p = *this; + + switch (dir) { + case NORTH: + p.y -= amount; + break; + + case EAST: + p.x += amount; + break; + + case SOUTH: + p.y += amount; + break; + + case WEST: + p.x -= amount; + } + + return p; + } + + Position operator+(Direction dir) const { + return translate(dir, 1); + } }; } |