diff --git a/src/Confetti.cpp b/src/Confetti.cpp index 32a6080..f0a1113 100644 --- a/src/Confetti.cpp +++ b/src/Confetti.cpp @@ -35,7 +35,7 @@ Confetti::~Confetti() { void Confetti::Burst(int screenWidth, int screenHeight) { particles.clear(); - + std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution xDist(0.0f, static_cast(screenWidth)); @@ -46,7 +46,7 @@ void Confetti::Burst(int screenWidth, int screenHeight) { std::uniform_real_distribution rotSpeedDist(-360.0f, 360.0f); std::uniform_real_distribution sizeDist(4.0f, 12.0f); std::uniform_real_distribution gravityDist(100.0f, 300.0f); - + // Create colorful confetti particles const int numParticles = 200; for (int i = 0; i < numParticles; ++i) { @@ -60,18 +60,42 @@ void Confetti::Burst(int screenWidth, int screenHeight) { particle.size = sizeDist(gen); particle.lifetime = 5.0f; // 5 seconds particle.gravity = gravityDist(gen); - + // Bright, saturated colors int colorChoice = i % 6; switch (colorChoice) { - case 0: particle.r = 255; particle.g = 0; particle.b = 0; break; // Red - case 1: particle.r = 0; particle.g = 255; particle.b = 0; break; // Green - case 2: particle.r = 0; particle.g = 0; particle.b = 255; break; // Blue - case 3: particle.r = 255; particle.g = 255; particle.b = 0; break; // Yellow - case 4: particle.r = 255; particle.g = 0; particle.b = 255; break; // Magenta - case 5: particle.r = 0; particle.g = 255; particle.b = 255; break; // Cyan + case 0: + particle.r = 255; + particle.g = 0; + particle.b = 0; + break; // Red + case 1: + particle.r = 0; + particle.g = 255; + particle.b = 0; + break; // Green + case 2: + particle.r = 0; + particle.g = 0; + particle.b = 255; + break; // Blue + case 3: + particle.r = 255; + particle.g = 255; + particle.b = 0; + break; // Yellow + case 4: + particle.r = 255; + particle.g = 0; + particle.b = 255; + break; // Magenta + case 5: + particle.r = 0; + particle.g = 255; + particle.b = 255; + break; // Cyan } - + particles.push_back(particle); } } @@ -80,23 +104,24 @@ void Confetti::Update(float deltaTime) { // Update all confetti particles for (auto it = particles.begin(); it != particles.end();) { it->lifetime -= deltaTime; - + if (it->lifetime <= 0.0f) { it = particles.erase(it); - } else { + } + else { // Update position it->x += it->vx * deltaTime; it->y += it->vy * deltaTime; - + // Apply gravity it->vy += it->gravity * deltaTime; - + // Update rotation it->rotation += it->rotationSpeed * deltaTime; - + // Add some air resistance it->vx *= 0.99f; - + ++it; } } @@ -109,11 +134,11 @@ void Confetti::Draw(SDL_Renderer* target) { if (particle.lifetime < 1.0f) { alpha = static_cast(255 * particle.lifetime); } - + // Draw confetti as small filled rectangles float halfSize = particle.size / 2.0f; float angle = particle.rotation * M_PI / 180.0f; - + // Simple rectangle for confetti pieces Sint16 x1 = static_cast(particle.x - halfSize * std::cos(angle)); Sint16 y1 = static_cast(particle.y - halfSize * std::sin(angle)); @@ -123,7 +148,7 @@ void Confetti::Draw(SDL_Renderer* target) { Sint16 y3 = static_cast(particle.y + halfSize * std::sin(angle) + halfSize * std::cos(angle)); Sint16 x4 = static_cast(particle.x - halfSize * std::cos(angle) - halfSize * std::sin(angle)); Sint16 y4 = static_cast(particle.y - halfSize * std::sin(angle) + halfSize * std::cos(angle)); - + // Draw a filled polygon (quad) Sint16 vx[] = {x1, x2, x3, x4}; Sint16 vy[] = {y1, y2, y3, y4}; diff --git a/src/ImageHolder.cpp b/src/ImageHolder.cpp index 11d07e5..3991d5e 100644 --- a/src/ImageHolder.cpp +++ b/src/ImageHolder.cpp @@ -112,7 +112,8 @@ void ImageHolder::Draw(SDL_Renderer* target, int x, int y, int max_w, int max_h) double aspect_ratio = static_cast(imgWidth) / imgHeight; if (max_w / aspect_ratio < max_h) { max_h = static_cast(max_w / aspect_ratio); - } else { + } + else { max_w = static_cast(max_h * aspect_ratio); } diff --git a/src/ImageSelectState.cpp b/src/ImageSelectState.cpp index 2951b3d..b837709 100644 --- a/src/ImageSelectState.cpp +++ b/src/ImageSelectState.cpp @@ -83,7 +83,7 @@ bool ImageSelectState::IsActive() { return isActive; } -void ImageSelectState::ProcessInput(const SDL_Event& event, bool &processed) { +void ImageSelectState::ProcessInput(const SDL_Event& event, bool& processed) { if (event.type == SDL_WINDOWEVENT) { if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { logicalResize.SetPhysicalSize(globalData.xsize, globalData.ysize); @@ -130,19 +130,19 @@ void ImageSelectState::Draw(SDL_Renderer* target) { size_t image_number = i + firstImage; if (image_number < imageHolders.size()) { imageHolders[image_number].Draw(target, - frame_physical.x + border_physical_w, - frame_physical.y + border_physical_h, - frame_physical.w - 2 * border_physical_w, - frame_physical.h - 2 * border_physical_h); + frame_physical.x + border_physical_w, + frame_physical.y + border_physical_h, + frame_physical.w - 2 * border_physical_w, + frame_physical.h - 2 * border_physical_h); } if (image_number < imageNameFields.size()) { int text_x_physical, text_y_physical; logicalResize.LogicalToPhysical( - frame_logical.x + frame_size / 2, - frame_logical.y + frame_size - 5, - text_x_physical, text_y_physical); + frame_logical.x + frame_size / 2, + frame_logical.y + frame_size - 5, + text_x_physical, text_y_physical); imageNameFields[image_number].Draw(target, text_x_physical, text_y_physical, - sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::bottom); + sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::bottom); } } @@ -156,7 +156,7 @@ void ImageSelectState::Draw(SDL_Renderer* target) { ImGui::EndMainMenuBar(); ImGui::Begin("Page control"); if (ImGui::Button("Next page")) { - firstImage += number_of_images_per_page; + firstImage += number_of_images_per_page; } if (ImGui::Button("Previous page")) { if (firstImage < number_of_images_per_page) { @@ -187,7 +187,7 @@ void ImageSelectState::Update() { const int logical_height = 720; if (mouse_x_logical > 0 && mouse_x_logical < logical_width && - mouse_y_logical > 0 && mouse_y_logical < logical_height) { + mouse_y_logical > 0 && mouse_y_logical < logical_height) { const int number_of_images_per_page = 6; const int frame_size = 300; const int frame_spacing = 20; @@ -204,9 +204,9 @@ void ImageSelectState::Update() { int rect_y_logical = top_y_logical + y * (frame_size + frame_spacing); if (mouse_x_logical > rect_x_logical && - mouse_x_logical < rect_x_logical + frame_size && - mouse_y_logical > rect_y_logical && - mouse_y_logical < rect_y_logical + frame_size) { + mouse_x_logical < rect_x_logical + frame_size && + mouse_y_logical > rect_y_logical && + mouse_y_logical < rect_y_logical + frame_size) { if (image_number < imageList.size()) { printf("Clicked on image %s\n", imageList[image_number].c_str()); PuzzleSingleImageState psi; @@ -230,8 +230,8 @@ void ImageSelectState::Update() { * @return false if the characters are not equal ignoring case */ static bool ichar_equals(char a, char b) { - return std::tolower(static_cast(a)) == - std::tolower(static_cast(b)); + return std::tolower(static_cast(a)) == + std::tolower(static_cast(b)); } /** @@ -250,12 +250,12 @@ static bool HasExtension(const std::string& filename, const std::string& extensi } static void setFontText(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) { - field.SetHolder(holder); - field.SetFont("freeserif"); - field.SetColor({255,255,255,255}); - field.SetFontSize(24); - field.SetOutline(1, {0,0,0,255}); - field.SetText(text); + field.SetHolder(holder); + field.SetFont("freeserif"); + field.SetColor({255,255,255,255}); + field.SetFontSize(24); + field.SetOutline(1, {0,0,0,255}); + field.SetText(text); } diff --git a/src/MainGameState.cpp b/src/MainGameState.cpp index d17d12b..e89f5d6 100644 --- a/src/MainGameState.cpp +++ b/src/MainGameState.cpp @@ -36,7 +36,7 @@ bool MainGameState::IsActive() { return true; } -void MainGameState::ProcessInput(const SDL_Event& event, bool &processed) { +void MainGameState::ProcessInput(const SDL_Event& event, bool& processed) { } diff --git a/src/PuzzleSingleImageState.cpp b/src/PuzzleSingleImageState.cpp index 600ec68..0dfb6e7 100644 --- a/src/PuzzleSingleImageState.cpp +++ b/src/PuzzleSingleImageState.cpp @@ -31,7 +31,7 @@ https://github.com/sago007/saland #include "rhash.hpp" PuzzleSingleImageState::PuzzleSingleImageState() { - + } PuzzleSingleImageState::~PuzzleSingleImageState() { @@ -43,20 +43,20 @@ bool PuzzleSingleImageState::IsActive() { } bool isEscapeEvent(const SDL_Event& event) { - if ( event.type == SDL_KEYDOWN ) { - if ( event.key.keysym.sym == SDLK_ESCAPE ) { - return true; - } - } - if (event.type == SDL_CONTROLLERBUTTONDOWN) { - if (event.cbutton.button == SDL_CONTROLLER_BUTTON_B || event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK ) { - return true; - } - } - return false; + if ( event.type == SDL_KEYDOWN ) { + if ( event.key.keysym.sym == SDLK_ESCAPE ) { + return true; + } + } + if (event.type == SDL_CONTROLLERBUTTONDOWN) { + if (event.cbutton.button == SDL_CONTROLLER_BUTTON_B || event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK ) { + return true; + } + } + return false; } -void PuzzleSingleImageState::ProcessInput(const SDL_Event& event, bool &processed) { +void PuzzleSingleImageState::ProcessInput(const SDL_Event& event, bool& processed) { if (isEscapeEvent(event)) { isActive = false; processed = true; @@ -104,12 +104,12 @@ void PuzzleSingleImageState::Draw(SDL_Renderer* target) { continue; } rectangleRGBA(target, rect.x+piece.x, rect.y+piece.y, - rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 255, 0, 255); + rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 255, 0, 255); } if (marked_piece > -1 && marked_piece < pieces_physical.size()) { const SDL_Rect& piece = pieces_physical.at(marked_piece); rectangleRGBA(target, rect.x+piece.x, rect.y+piece.y, - rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 0, 0, 255); + rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 0, 0, 255); } } @@ -151,7 +151,7 @@ void PuzzleSingleImageState::Update() { if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && globalData.mouseUp) { globalData.mouseUp = false; - + SDL_Rect rect; rect.x = globalData.xsize/2-resized_image_physical_width/2; rect.y = globalData.ysize/2-resized_image_physical_height/2;; diff --git a/src/SagoImGui.cpp b/src/SagoImGui.cpp index cbb0905..727b43c 100644 --- a/src/SagoImGui.cpp +++ b/src/SagoImGui.cpp @@ -29,7 +29,8 @@ void InitImGui(SDL_Window* window, SDL_Renderer* renderer, int width, int height // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; + ImGuiIO& io = ImGui::GetIO(); + (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; diff --git a/src/sago_common.cpp b/src/sago_common.cpp index a63e25f..7659ab9 100644 --- a/src/sago_common.cpp +++ b/src/sago_common.cpp @@ -66,24 +66,24 @@ void RunGameState(sago::GameStateInterface& state ) { bool mustWriteScreenshot = false; while ( SDL_PollEvent(&event) ) { - UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); - if ( event.type == SDL_QUIT ) { - globalData.isShuttingDown = true; - done = true; - } + UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); + if ( event.type == SDL_QUIT ) { + globalData.isShuttingDown = true; + done = true; + } - if (event.type == SDL_WINDOWEVENT) { - if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - SDL_GetRendererOutputSize(globalData.screen, &globalData.xsize, &globalData.ysize); - } + if (event.type == SDL_WINDOWEVENT) { + if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + SDL_GetRendererOutputSize(globalData.screen, &globalData.xsize, &globalData.ysize); } + } - if ( event.key.keysym.sym == SDLK_F9 ) { - mustWriteScreenshot = true; - } + if ( event.key.keysym.sym == SDLK_F9 ) { + mustWriteScreenshot = true; + } - bool processed = false; - state.ProcessInput(event, processed); + bool processed = false; + state.ProcessInput(event, processed); } @@ -170,7 +170,7 @@ void InitGame() { io.IniFilename = nullptr; imgui_inifile = getPathToSaveFiles() + "/imgui.ini"; ImGui::LoadIniSettingsFromDisk(imgui_inifile.c_str()); - + dataHolder.invalidateAll(globalData.screen); globalData.spriteHolder.reset(new sago::SagoSpriteHolder(dataHolder)); globalData.dataHolder = &dataHolder; diff --git a/src/sago_multi_scrambler_puzzle2.cpp b/src/sago_multi_scrambler_puzzle2.cpp index 66c5777..4a68cb2 100644 --- a/src/sago_multi_scrambler_puzzle2.cpp +++ b/src/sago_multi_scrambler_puzzle2.cpp @@ -104,7 +104,7 @@ int main(int argc, const char* argv[]) { std::cout << GAMENAME << " " << VERSION_NUMBER << "\n"; return 0; } - + InitSagoFS(argc, argv); if (vm.count("input-file")) { const std::vector& input_files = vm["input-file"].as >();