COMPLETER LA CLASSE ABSTRAITE

This commit is contained in:
YANNIS
2025-06-01 10:34:29 +02:00
parent 90c5485fc5
commit cfee2379ab
6 changed files with 29 additions and 4 deletions
+7
View File
@@ -7,6 +7,12 @@ Game::Game(){
std::string(SDL_GetError())); 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", \ _window = SDL_CreateWindow("Bomberman", \
SDL_WINDOWPOS_CENTERED, \ SDL_WINDOWPOS_CENTERED, \
SDL_WINDOWPOS_CENTERED, \ SDL_WINDOWPOS_CENTERED, \
@@ -34,6 +40,7 @@ Game::~Game() {
if (_window) { if (_window) {
SDL_DestroyWindow(_window); SDL_DestroyWindow(_window);
} }
IMG_Quit();
SDL_Quit(); SDL_Quit();
} }
+14 -2
View File
@@ -1,12 +1,24 @@
#include "Sprite.hpp" #include "Sprite.hpp"
Sol::Sol() { Sol::Sol(SDL_Renderer* renderer) : Sprite() {
// Constructor implementation // Constructor implementation
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; std::cout << "Sol created." << std::endl;
} }
Sol::~Sol() { Sol::~Sol() {
// Destructor implementation // Destructor implementation
SDL_DestroyTexture(texture);
texture = nullptr;
surface = nullptr;
std::cout << "Sol destroyed." << std::endl; std::cout << "Sol destroyed." << std::endl;
} }
void Sol::draw() {
// Drawing implementation
}
+1 -1
View File
@@ -6,6 +6,6 @@ class Sol: public Sprite {
public: public:
Sol(); Sol();
virtual ~Sol(); virtual ~Sol();
void draw() override;
} }
+4
View File
@@ -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)
+2
View File
@@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <exception>
class Sprite { class Sprite {
private: private:
@@ -11,6 +12,7 @@ private:
float posY = 0.0f; float posY = 0.0f;
public: public:
Sprite() = default; Sprite() = default;
Sprite(SDL_Renderer* renderer, std::string filePath);
virtual ~Sprite() = default; virtual ~Sprite() = default;
// Pure virtual function to be implemented by derived classes // Pure virtual function to be implemented by derived classes
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 978 B