diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp new file mode 100644 index 0000000..3eaf143 --- /dev/null +++ b/src/util.cpp @@ -0,0 +1,17 @@ +#include "util.h" +#include <cmath> + +Point2D ScreenToTile(Point2D source) +{ + Point2D result {}; + + auto fx = (float)source.x; + auto fy = (float)source.y; + float xx = (fx / TileSize + fy / (TileSize / 2.f)); + float yy = (fy / (TileSize / 2.f) - (fx / TileSize)); + + result.x = (int)floorf(xx - 1.5f); // Magic numbers + result.y = (int)floorf(yy - 0.5f); + + return result; +}
\ No newline at end of file |