From cfee2379abfa121e3a43012ff6bdbe3d472b86f1 Mon Sep 17 00:00:00 2001 From: YANNIS Date: Sun, 1 Jun 2025 10:34:29 +0200 Subject: [PATCH] COMPLETER LA CLASSE ABSTRAITE --- Game.cpp | 7 +++++++ Sol.cpp | 18 +++++++++++++++--- Sol.hpp | 2 +- Sprite.cpp | 4 ++++ Sprite.hpp | 2 ++ TILES/map/SOL.png | Bin 0 -> 978 bytes 6 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 Sprite.cpp create mode 100644 TILES/map/SOL.png 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 0000000000000000000000000000000000000000..8ab1780d41da0ef15f79e82a240d64d0b7c7ad1a GIT binary patch literal 978 zcma)2F=!M)6n#gGSrbDREIb5ZLC_Tywj9J_6E0>BO;}^V(KM?TZY2v*SZrLxVyxV9 zk$?j>TglliR$HEp9N0vwD^IJGU$O9ytA~x6&(6;OZ{ECl|38a1))wba%mY~L%ibpM zu3gRy|NRR~*Lgd1Z+U$gc=LSW`|Vk-J3E_eE1i$;&OheDyDK->fk&r-{3-B_p?m^7 z41g~&aIplAr@L>jT>@qhUENw`Lg9jl_H#}-DYKRTzeo$t2HnR|OnNl4z}^l#cS;EU4LoFI8RU(99Pe zt4$K=7rE4lh|M_g+-??n%F1<3?ABR#uMlPA$HIDqo2F?LMSd8GI5Vb7DnedS1?Cf> z9I`vY7=dY+O`xparxZ=Vh}tutA;`zxph(%Rj+Nwb*_kktlTay^Ek+X-R7Imr!6*Ed zCq(O?Y5cjqPjHx@b368WNCPxJNLi`GfpqXEKj{8c=L-N2$CSptNEFBMU@)M%Aki2d zDZ?IA4L!2GT0d zJ&={R!O7H*1Pmi}fd=e{Bos3;R3&Q5ZG)zKfK}3||G)M7`{Mt1JH!LW{b1;^WarM6 zwI1~BNp_DTsl2%ZEF80|gBQD92In61*H`C0AMVVZIeTM!;}t_o{oe9c_ru-M<(Z?W Ywt-K#&UM~@Eno5x`l}ng*DLXp9~4$+kN^Mx literal 0 HcmV?d00001