diff --git a/Game.cpp b/Game.cpp index c901e6d..f0bb358 100644 --- a/Game.cpp +++ b/Game.cpp @@ -7,6 +7,12 @@ Game::Game(){ std::string(SDL_GetError())); } + if (IMG_Init(IMG_INIT_PNG) == 0) { + SDL_Quit(); + throw std::runtime_error("SDL_image could not initialize! IMG_Error: " + \ + std::string(IMG_GetError())); + } + _window = SDL_CreateWindow("Bomberman", \ SDL_WINDOWPOS_CENTERED, \ SDL_WINDOWPOS_CENTERED, \ @@ -34,6 +40,7 @@ Game::~Game() { if (_window) { SDL_DestroyWindow(_window); } + IMG_Quit(); SDL_Quit(); } diff --git a/Sol.cpp b/Sol.cpp index a9861f2..c07c1b9 100644 --- a/Sol.cpp +++ b/Sol.cpp @@ -1,12 +1,24 @@ #include "Sprite.hpp" -Sol::Sol() { +Sol::Sol(SDL_Renderer* renderer) : Sprite() { // Constructor implementation - - std::cout << "Sol created." << std::endl; + if (renderer == nullptr) + throw std::runtime_error("Renderer is null"); + surface = IMG_Load("map/SOL.png"); + texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_FreeSurface(surface); + std::cout << "Sol created." << std::endl; } Sol::~Sol() { // Destructor implementation + SDL_DestroyTexture(texture); + texture = nullptr; + surface = nullptr; std::cout << "Sol destroyed." << std::endl; } + +void Sol::draw() { + // Drawing implementation + +} diff --git a/Sol.hpp b/Sol.hpp index e12c8e7..3b1ccd7 100644 --- a/Sol.hpp +++ b/Sol.hpp @@ -6,6 +6,6 @@ class Sol: public Sprite { public: Sol(); virtual ~Sol(); - + void draw() override; } diff --git a/Sprite.cpp b/Sprite.cpp new file mode 100644 index 0000000..ad8d752 --- /dev/null +++ b/Sprite.cpp @@ -0,0 +1,4 @@ +#include "Sprite.hpp" + +//Implementation du constructeur avec SDL_Renderer comme paramètre +//(en gros je vais mettre le constructeur de Sol dans la classe abstraite Sprite pour automatiser la création de texture selon le iflePath) diff --git a/Sprite.hpp b/Sprite.hpp index c0062b4..12182f1 100644 --- a/Sprite.hpp +++ b/Sprite.hpp @@ -2,6 +2,7 @@ #include #include #include +#include class Sprite { private: @@ -11,6 +12,7 @@ private: float posY = 0.0f; public: Sprite() = default; + Sprite(SDL_Renderer* renderer, std::string filePath); virtual ~Sprite() = default; // Pure virtual function to be implemented by derived classes diff --git a/TILES/map/SOL.png b/TILES/map/SOL.png new file mode 100644 index 0000000..8ab1780 Binary files /dev/null and b/TILES/map/SOL.png differ