diff --git a/decors.cpp b/decors.cpp index 57aa1bf..ca157cc 100644 --- a/decors.cpp +++ b/decors.cpp @@ -11,17 +11,12 @@ void Rock::draw(SDL_Renderer* renderer) const{ Camera& camera = Camera::getInstance(); int cameraX = camera.getX(); int cameraY = camera.getY(); - - SDL_SetRenderDrawColor(renderer, r, g, b, 255); - for (int w = 0; w < size * 2; w++) { - for (int h = 0; h < size * 2; h++) { - int dx = size - w; - int dy = size - h; - if ((dx * dx + dy * dy) <= (size * size)) { - SDL_Rect rect = { x + dx - cameraX, y + dy - cameraY, 1, 1 }; - SDL_RenderFillRect(renderer, &rect); - } - } + SDL_Rect rockRect = { x - cameraX, y - cameraY, size, size }; + if (texturesVector[1] != nullptr) { + SDL_RenderCopy(renderer, texturesVector[1], nullptr, &rockRect); + } else { + SDL_SetRenderDrawColor(renderer, r, g, b, 255); + SDL_RenderFillRect(renderer, &rockRect); } //std::cout << "Rock drawn at (" << x << ", " << y << ")" << std::endl; } @@ -47,8 +42,8 @@ void generateProceduralDecorations(std::vector&kelps, std::vector&ro int numKelps = 10 + std::rand() % 20; for (int i = 0; i < numKelps; i++) { int x = std::rand() % envWidth; - int y = envHeight - (std::rand() % (envHeight / 10)); - int size = 50 + std::rand() % 100; + int y = envHeight - (std::rand() % static_cast(envHeight * 0.2)); + int size = 250 + std::rand() % 100; Uint8 r = 4; Uint8 g = 87; Uint8 b = 0; @@ -56,14 +51,14 @@ void generateProceduralDecorations(std::vector&kelps, std::vector&ro } //Generate Rocks - int numRocks = 10 + std::rand() % 20; + int numRocks = 10 + std::rand() % 10; for (int i = 0; i < numRocks; i++) { int x = std::rand() % envWidth; - int y = envHeight - (std::rand() % (envHeight / 10)); - int size = 10 + std::rand() % 20; + int y = envHeight - (std::rand() % static_cast(envHeight * 0.2)); + int size = 250 + std::rand() % 20; int r = 100 + std::rand() % 156; int g = 100 + std::rand() % 156; int b = 100 + std::rand() % 156; - rocks.emplace_back(Rock(x, y, size, r, g, b)); + rocks.emplace_back(Rock(x, y, size, r, g, b, renderer)); } } diff --git a/decors.h b/decors.h index 47d28a5..4b45016 100644 --- a/decors.h +++ b/decors.h @@ -13,15 +13,15 @@ class Rock { public: - Rock(int x, int y, int size, Uint8 r, Uint8 g, Uint8 b) : x(x), y(y), size(size), r(r), g(g), b(b) {}; + Rock(int x, int y, int size, Uint8 r, Uint8 g, Uint8 b, SDL_Renderer* renderer) : x(x), y(y), size(size), r(r), g(g), b(b) {}; void draw(SDL_Renderer* renderer) const; int x; int y; private: int size; - int r; - int g; - int b; + Uint8 r; + Uint8 g; + Uint8 b; }; class Kelp { diff --git a/env.cpp b/env.cpp index 4a09c6f..dbd9378 100644 --- a/env.cpp +++ b/env.cpp @@ -18,7 +18,7 @@ int fishCount = 0; std::vector texturesVector; bool initEnvironment(SDL_Renderer* renderer) { - SDL_Surface* backgroundSurface = IMG_Load("../img/background.jpg"); + SDL_Surface* backgroundSurface = IMG_Load("../img/background.png"); if (backgroundSurface == nullptr) { std::cerr << "Erreur de chargement de l'image de fond: " << IMG_GetError() << std::endl; return false; @@ -56,12 +56,20 @@ bool initEnvironment(SDL_Renderer* renderer) { std::vector initTexture(SDL_Renderer* renderer) { std::vector textures; - // Load the Kelp texture + //Load the Kelp texture SDL_Surface* kelpSurface = IMG_Load("../img/kelp.png"); if (kelpSurface == nullptr) { std::cerr << "Erreur de chargement de l'image du Kelp: " << IMG_GetError() << std::endl; } textures.push_back(SDL_CreateTextureFromSurface(renderer, kelpSurface)); SDL_FreeSurface(kelpSurface); + + //Load the rock texture + SDL_Surface* rockSurface = IMG_Load("../img/rock.png"); + if (rockSurface == nullptr) { + std::cerr << "Erreur de chargement de l'image du Rock: " << IMG_GetError() << std::endl; + } + textures.push_back(SDL_CreateTextureFromSurface(renderer, rockSurface)); + SDL_FreeSurface(rockSurface); return textures; } \ No newline at end of file diff --git a/img/background.jpg b/img/background.jpg deleted file mode 100644 index 6bcabee..0000000 Binary files a/img/background.jpg and /dev/null differ diff --git a/img/background.png b/img/background.png new file mode 100644 index 0000000..07821eb Binary files /dev/null and b/img/background.png differ diff --git a/img/rock.png b/img/rock.png new file mode 100644 index 0000000..6f883c2 Binary files /dev/null and b/img/rock.png differ