diff options
author | cflip <cflip@cflip.net> | 2022-02-27 19:37:36 -0700 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-02-27 19:37:36 -0700 |
commit | 8c8096dab1538592e6bacea6ba4e1f9882ae6e0b (patch) | |
tree | 35a69e588af9ace66a5b8c0211e05167ea40428b /src/util.cpp | |
parent | bba66a0ccb7281cd6c717fe9784a04a4fcf72700 (diff) |
Miscellaneous code cleanup
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 |