diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..2fb7807 --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,25 @@ +#include +#include "utils.hpp" +#include "SDL_image.h" +#include "data/hills.hpp" + + +std::vector get_hills() { + std::vector surfaces; + + for (int i = 0; i < hills_length; i++) { + HillData png = hills[i]; + SDL_RWops *rw = SDL_RWFromMem(const_cast(png.data), png.length); + if (!rw) + throw std::runtime_error("Failed to create RWops from memory"); + + SDL_Surface *surface = IMG_Load_RW(rw, 1); + if (!surface) { + SDL_RWclose(rw); + throw std::runtime_error("Failed to load image from memory: " + std::string(IMG_GetError())); + } + surfaces.push_back(surface); + } + + return surfaces; +} diff --git a/src/utils.hpp b/src/utils.hpp index f7501cc..828c1c4 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -1,7 +1,7 @@ #pragma once - -#include +#include +#include "SDL_surface.h" template constexpr size_t array_len(T *array[]) { @@ -10,3 +10,5 @@ constexpr size_t array_len(T *array[]) { i++; return i; } + +std::vector get_hills();