pokemon/coordinates.hpp
Zack Buhman 3d8110ca1c graphic: add functions to draw stats screen borders
This also draws pokemon sprites on the screen, sequentially.
2023-08-03 22:19:01 +00:00

73 lines
1.2 KiB
C++

#pragma once
#include <stdint.h>
namespace screen_offset
{
// the origin is at this offset in screen space
constexpr int32_t x = 4;
constexpr int32_t y = 4;
}
struct offset_t { // in pixels
int32_t x;
int32_t y;
};
struct world_t;
struct block_t {
int32_t x;
int32_t y;
};
struct screen_cell_t {
int32_t x;
int32_t y;
};
struct screen_t {
int32_t x;
int32_t y;
constexpr inline world_t to_world(const world_t& origin) const;
};
struct world_t {
int32_t x;
int32_t y;
constexpr inline screen_t to_screen(const world_t& origin) const;
constexpr inline block_t to_block() const;
};
// screen_t
constexpr inline world_t screen_t::to_world(const world_t& origin) const
{
return {
(origin.x - screen_offset::x) + x,
(origin.y - screen_offset::y) + y,
};
}
// world_t
constexpr inline screen_t world_t::to_screen(const world_t& origin) const
{
return {
-origin.x + screen_offset::x + x,
-origin.y + screen_offset::y + y,
};
}
constexpr inline block_t world_t::to_block() const
{
// division function must round towards negative infinity
// right shift provides that property
return {
x >> 1,
y >> 1,
};
}