mapcreator git · master
SDL3 2.5D game and engine using assets, with map editor
C++ 99.3%git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz..
src/start_screen/start_screen.cpp | 75 ++++++++++++++++++++++++++++++++++++--- src/start_screen/start_screen.hpp | 7 +++- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/start_screen/start_screen.cpp b/src/start_screen/start_screen.cpp index 5842daf..a5d05e5 100644 --- a/src/start_screen/start_screen.cpp +++ b/src/start_screen/start_screen.cpp @@ -2,10 +2,40 @@ StartScreen::StartScreen(SDL_Renderer* r) : renderer(r) { Init(); } StartScreen::~StartScreen() { - if (char_texture) SDL_DestroyTexture(char_texture); - if (logo_surface) SDL_DestroySurface(logo_surface); + if (char_texture) SDL_DestroyTexture(char_texture); + if (logo_surface) SDL_DestroySurface(logo_surface); + if (props_texture) SDL_DestroyTexture(props_texture); + if (props_surface) SDL_DestroySurface(props_surface); } + +void StartScreen::StartShowProps() { + if (!props_surface) return; + + phase = Phase::SHOW_PROPS; + phase_start = SDL_GetTicks(); + + // Extract visible pixels + const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(props_surface->format); + Uint32* pixels = static_cast<Uint32*>(props_surface->pixels); + int pitch = props_surface->pitch / (int)sizeof(Uint32); + int w = props_surface->w, h = props_surface->h; + + particles.clear(); + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + Uint32 p = pixels[y * pitch + x]; + Uint8 r,g,b,a; + SDL_GetRGBA(p, details, NULL, &r, &g, &b, &a); + if (a > 180) { // or check color if you want black only + particles.push_back({ {static_cast<float>(x), static_cast<float>(y)}, + {screen_w/2.0f, screen_h/2.0f}, // start from center + {screen_w/2.0f, screen_h/2.0f} }); + } + } + } +} + void StartScreen::Update() { Uint64 now = SDL_GetTicks(); float dt = static_cast<float>(now - last_time) / 1000.0f; @@ -62,12 +92,30 @@ void StartScreen::Update() { } case Phase::SHOW_LOGO: { if (now - phase_start > static_cast<Uint64>(logo_display_time * 1000.0f)) { + StartShowProps(); // Time's up → quit the application - running = false; // will break main loop + //running = false; // will break main loop // or: SDL_Quit(); return; // but better to let main clean up } break; } + + case Phase::SHOW_PROPS: { + float p = (now - phase_start) / 1000.0f; // 1 second animation + if (p >= 1.0f) p = 1.0f; + props_anim_progress = p; + + for (auto& pt : particles) { + pt.current.x = Lerp(pt.current.x, pt.original.x + (screen_w - props_surface->w)/2.0f, p); + pt.current.y = Lerp(pt.current.y, pt.original.y + (screen_h - props_surface->h)/2.0f, p); + } + + // optionally, end scene after animation finishes + if (p >= 1.0f && now - phase_start > 3500) { // 1.5s after animation ends + running = false; + } + break; + } } } @@ -85,7 +133,6 @@ void StartScreen::Render() { float scale = 4.0f; // double size as requested float sw = char_frame_width * scale; float sh = char_height * scale; - std::print("{0} {1} {2}\n", "FEET: ", bottom_y, sh); float dy = static_cast<float>(bottom_y) - sh + 46.0f; // feet on line SDL_FRect src { static_cast<float>(char_frame * char_frame_width), 0.0f, @@ -94,6 +141,23 @@ void StartScreen::Render() { SDL_RenderTexture(renderer, char_texture, &src, &dst); } + else + if (phase == Phase::SHOW_PROPS) { + if (props_anim_progress < 2.0f) { + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + for (const auto& p : particles) { + SDL_FRect r { p.current.x, p.current.y, 1.0f, 1.0f }; + SDL_RenderFillRect(renderer, &r); + } + } else { + SDL_FRect dst { (screen_w - props_surface->w)/2.0f, + (screen_h - props_surface->h)/2.0f, + static_cast<float>(props_surface->w), + static_cast<float>(props_surface->h) }; + SDL_SetTextureAlphaMod(props_texture, 255); + SDL_RenderTexture(renderer, props_texture, nullptr, &dst); + } + } SDL_RenderPresent(renderer); } @@ -163,6 +227,9 @@ void StartScreen::Init() { logo_surface = IMG_Load("logo/logo.png"); char_texture = IMG_LoadTexture(renderer, "logo/Run_Side-Sheet.png"); + props_surface = IMG_Load("logo/props.png"); + props_texture = SDL_CreateTextureFromSurface(renderer, props_surface); + SDL_GetRenderOutputSize(renderer, &screen_w, &screen_h); // Extract black pixels (local coords) diff --git a/src/start_screen/start_screen.hpp b/src/start_screen/start_screen.hpp index 208c5a4..3bd24c5 100644 --- a/src/start_screen/start_screen.hpp +++ b/src/start_screen/start_screen.hpp @@ -32,10 +32,11 @@ public: void UpdateScreen(); private: - enum class Phase { SHOW_LOGO, DOT, SPREAD_TO_LINE, LINE_WAIT, RUNNING, FADE_TO_LOGO }; + enum class Phase { SHOW_LOGO, DOT, SPREAD_TO_LINE, LINE_WAIT, RUNNING, FADE_TO_LOGO, SHOW_PROPS }; float desired_cross_time = 1.8f; // seconds float extra_distance = 600.0f; // px left + right float logo_display_time = 3.2f; + float props_anim_progress = 0.0f; // 0.0 → 1.0 void Init(); @@ -47,10 +48,14 @@ private: static float Lerp(float a, float b, float t); + void StartShowProps(); + private: SDL_Renderer* renderer = nullptr; SDL_Surface* logo_surface = nullptr; SDL_Texture* char_texture = nullptr; + SDL_Surface* props_surface = nullptr; + SDL_Texture* props_texture = nullptr; std::vector<Particle> particles; std::vector<SDL_FPoint> line_positions;