#include <SDL2/SDL.h>
#include <vector>
#include <cstdlib>
#include <ctime>
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
// Struktura dla surowców (gnój i wapno)
struct Resource {
SDL_Rect rect;
int type; // 0 = gnój, 1 = wapno
};
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) return 1;
SDL_Window* window = SDL_CreateWindow("Skarabeusz: Alchemik Pustyni", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
bool running = true;
SDL_Event e;
// Gracz - Skarabeusz
SDL_Rect player = { SCREEN_WIDTH / 2 - 25, SCREEN_HEIGHT / 6 - 25, 50, 50 };
// Surowce na planszy
std::vector<Resource> resources;
std::srand(std::time(nullptr));
for (int i = 0; i < 15; ++i) {
Resource res;
res.rect = { std::rand() % (SCREEN_WIDTH - 20), std::rand() % (SCREEN_HEIGHT - 20), 20, 20 };
res.type = std::rand() % 2; // 50% szans na gnój, 50% na wapno
resources.push_back(res);
}
int inventoryGnoj = 0;
int inventoryWapno = 0;
int waterLevel = 0; // Nasz cel: zdobyć wodę
bool isNight = false;
Uint32 lastTime = SDL_GetTicks();
// Główna pętla gry
while (running) {
// Czas gry (przełączanie dzień/noc)
Uint32 currentTime = SDL_GetTicks();
if (currentTime - lastTime > 5000) { // Co 5 sekund zmiana
isNight = !isNight;
lastTime = currentTime;
// Jeśli zaczyna się noc, przetwarzamy zebrane zasoby w wodę
if (isNight) {
if (inventoryGnoj >= 5 && inventoryWapno >= 3) {
waterLevel += 10; // Sukces!
SDL_Log("Noc alchemii! Woda zdobyta! Poziom wody: %d", waterLevel);
} else {
SDL_Log("Noc nieudana. Za mało zasobów (potrzeba 5 gnoju, 3 wapna).");
}
// Reset zapasów po nocy
inventoryGnoj = 0; inventoryWapno = 0;
}
}
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) running = false;
else if (!isNight && e.type == SDL_MOUSEMOTION) {
player.x = e.motion.x - (player.w / 2);
player.y = e.motion.y - (player.h / 2);
}
}
// Dzień: zbieranie zasobów
if (!isNight) {
for (size_t i = 0; i < resources.size(); ++i) {
if (SDL_HasIntersection(&player, &resources[i].rect)) {
if (resources[i].type == 0) inventoryGnoj++;
else inventoryWapno++;
// Usuń zebrany zasób i dodaj nowy w losowym miejscu
resources.erase(resources.begin() + i);
Resource newRes;
newRes.rect = { std::rand() % (SCREEN_WIDTH - 20), std::rand() % (SCREEN_HEIGHT - 20), 20, 20 };
newRes.type = std::rand() % 2;
resources.push_back(newRes);
break; // Unikaj problemów z iteratorem
}
}
}
// Renderowanie
if (isNight) {
// Noc: ciemno, chłodno (granatowe tło)
SDL_SetRenderDrawColor(renderer, 10, 10, 50, 255);
} else {
// Dzień: jasno, gorąco (żółto-piaskowe tło)
SDL_SetRenderDrawColor(renderer, 240, 230, 140, 255);
}
SDL_RenderClear(renderer);
// Rysuj zasoby (tylko w dzień)
if (!isNight) {
for (const auto& res : resources) {
if (res.type == 0) SDL_SetRenderDrawColor(renderer, 165, 42, 42, 255); // Gnój - brąz
else SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); // Wapno - biel
SDL_RenderFillRect(renderer, &res.rect);
}
}
// Rysuj skarabeusza (ciemny kolor)
SDL_SetRenderDrawColor(renderer, 85, 107, 47, 255);
SDL_RenderFillRect(renderer, &player);
int boxSize = 20 + waterLevel;
SDL_Rect waterBox = { 50, 50, boxSize, boxSize };
// Rysujemy niebieski kwadrat wody
SDL_SetRenderDrawColor(renderer, 0, 191, 255, 255);
SDL_RenderFillRect(renderer, &waterBox);
// SDL_RenderPresent(renderer);
// Wskaźnik wody w norce (np. prostokąt w rogu)
SDL_Rect waterBar = { 10, 10, waterLevel * 2, 20 };
SDL_SetRenderDrawColor(renderer, 0, 191, 255, 255);
SDL_RenderFillRect(renderer, &waterBar);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}

