COMPLETER LA CLASSE ABSTRAITE
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
#include "Sprite.hpp"
|
||||
|
||||
Sol::Sol() {
|
||||
Sol::Sol(SDL_Renderer* renderer) : Sprite() {
|
||||
// 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;
|
||||
}
|
||||
|
||||
Sol::~Sol() {
|
||||
// Destructor implementation
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = nullptr;
|
||||
surface = nullptr;
|
||||
std::cout << "Sol destroyed." << std::endl;
|
||||
}
|
||||
|
||||
void Sol::draw() {
|
||||
// Drawing implementation
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ class Sol: public Sprite {
|
||||
public:
|
||||
Sol();
|
||||
virtual ~Sol();
|
||||
|
||||
void draw() override;
|
||||
|
||||
}
|
||||
|
||||
@@ -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,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <exception>
|
||||
|
||||
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
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 978 B |
Reference in New Issue
Block a user