diff --git a/CMakeLists.txt b/CMakeLists.txt index 08b4bf1..95a2982 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ find_package(SDL3_image CONFIG REQUIRED) find_package(flecs CONFIG REQUIRED) find_package(spdlog CONFIG REQUIRED) -add_executable(HansTheGatherer main.cpp) +add_executable(HansTheGatherer main.cpp assets.cpp) target_link_libraries(HansTheGatherer SDL3::SDL3 SDL3_image::SDL3_image flecs::flecs spdlog::spdlog) diff --git a/assets.cpp b/assets.cpp new file mode 100644 index 0000000..7989858 --- /dev/null +++ b/assets.cpp @@ -0,0 +1,28 @@ +#include "assets.hpp" +#include "sdl_types.hpp" + +#include +#include +#include + +static constexpr uint8_t BACKGROUND_DATA[] = { +#embed "jungle.jpg" +}; + +static constexpr uint8_t FRUITS_DATA[] = { +#embed "fruits.jpg" +}; + +void init_assets(flecs::world &world) { + auto *renderer = world.get()->renderer; + + auto *background_iostream = + SDL_IOFromConstMem(BACKGROUND_DATA, sizeof(BACKGROUND_DATA)); + SDL_Texture *background = + IMG_LoadTexture_IO(renderer, background_iostream, false); + if (background == nullptr) { + spdlog::error("Failed to load SDL texture!\nCause: {}", SDL_GetError()); + } + + world.set(SpriteAssets{.background = background}); +} diff --git a/assets.hpp b/assets.hpp new file mode 100644 index 0000000..89086be --- /dev/null +++ b/assets.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +struct SpriteAssets { + SDL_Texture *background; + SDL_Texture *fruits; +}; + +void init_assets(flecs::world &world); diff --git a/fruits.jpg b/fruits.jpg new file mode 100644 index 0000000..05af9d6 Binary files /dev/null and b/fruits.jpg differ diff --git a/Fruit+.png b/fruits.png similarity index 100% rename from Fruit+.png rename to fruits.png diff --git a/input.hpp b/input.hpp new file mode 100644 index 0000000..bdb2e2b --- /dev/null +++ b/input.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +struct ButtonInput { + std::set pressed; + std::set just_pressed; + std::set just_released; +}; + diff --git a/main.cpp b/main.cpp index 1f3bacd..192cf6d 100644 --- a/main.cpp +++ b/main.cpp @@ -1,51 +1,25 @@ +#include "assets.hpp" +#include "sdl_types.hpp" +#include "input.hpp" + #include #include #include #include #include #include -#include #include -#include #include -const uint8_t background_data[] = { -#embed "jungle.jpg" -}; - static constexpr int WINDOW_WIDTH = 400; static constexpr int WINDOW_HEIGHT = 280; -struct SpriteAssets { - SDL_Texture *background; +struct Position { + int x; + int y; }; -struct SdlHandles { - SDL_Window *window; - SDL_Renderer *renderer; -}; - -struct ButtonInput { - std::set pressed; - std::set just_pressed; - std::set just_released; -}; - -auto init_assets(flecs::world &world) -> void { - auto *renderer = world.get()->renderer; - - auto *background_iostream = - SDL_IOFromConstMem(background_data, sizeof(background_data)); - SDL_Texture *background = - IMG_LoadTexture_IO(renderer, background_iostream, false); - if (background == nullptr) { - spdlog::error("Failed to load SDL texture!\nCause: {}", SDL_GetError()); - } - - world.set(SpriteAssets{.background = background}); -} - -auto main() -> int { +int main() { spdlog::info("Initialize SDL..."); if (!SDL_Init(SDL_INIT_VIDEO)) { diff --git a/sdl_types.hpp b/sdl_types.hpp new file mode 100644 index 0000000..873b07b --- /dev/null +++ b/sdl_types.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +struct SdlHandles { + SDL_Window *window; + SDL_Renderer *renderer; +}; +