2 #include <whycpp/log.h> 3 #include <whycpp/types.h> 6 Sprite::Sprite(i32 width, i32 height)
9 texture(std::vector<std::vector<
RGBA>>(static_cast<u64>(width),
10 std::vector<
RGBA>(static_cast<u64>(height), {0, 0, 0, 0}))) {
11 LOG_DEBUG(
"Sprite [%d, %d] created", width, height);
14 LOG_DEBUG(
"Sprite [%d, %d] destroyed", width_, height_);
16 void Sprite::Set(i32 x, i32 y,
const RGBA &color) {
17 texture.at(CheckX(x)).at(CheckY(y)) = color;
19 const RGBA &Sprite::Get(i32 x, i32 y)
const {
20 return texture.at(static_cast<u64>(CheckX(x))).at(static_cast<u64>(CheckY(y)));
22 i32 Sprite::GetHeight()
const {
25 i32 Sprite::GetWidth()
const {
28 size_t Sprite::CheckX(i32 x)
const {
29 if (x >= width_ || x < 0) {
30 LOG_VERBOSE(
"Sprite: X is out of bound, should be [0, %d) but %d", width_, x);
31 return static_cast<size_t>(clamp(x, 0, width_ - 1));
33 return static_cast<size_t>(x);
35 size_t Sprite::CheckY(i32 y)
const {
36 if (y >= height_ || y < 0) {
37 LOG_VERBOSE(
"Sprite: Y is out of bound, should be [0, %d) but %d", height_, y);
38 return static_cast<size_t>(clamp(y, 0, height_ - 1));
40 return static_cast<size_t>(y);