Nimbin[12]?SDL & Graphics / mapcreator / src/start_screen/start_screen.hpp

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

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.hpp 2 KB · 92 lines raw
// StartScreen.cpp (single-file SDL3 example)
// Compile: g++ -std=c++20 StartScreen.cpp -o startscreen $(pkg-config --cflags --libs sdl3 SDL3_image)

#pragma once

#include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h>
#include <vector>
#include <random>
#include <numeric>
#include <algorithm>
#include <cstdint>
#include <print>

struct Particle {
    SDL_FPoint original;   // local logo coords (0..w, 0..h) — never change
    SDL_FPoint current;
    SDL_FPoint target;
};


class StartScreen {
public:
    bool running = true;
    StartScreen(SDL_Renderer* r);
    ~StartScreen();

    void Update();

    void Render();

    void UpdateScreen();

private:
    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();

    void StartSpreadToLine();

    void StartFadeToLogo();

    SDL_FPoint GetScreenOriginal(const Particle& p) const;

    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;

    int screen_w = 0, screen_h = 0;
    SDL_Rect logo_dest{};
    SDL_FPoint logo_offset{0,0};
    SDL_FPoint center_dot{0,0};

    int line_y = 0;

    Phase phase = Phase::DOT;
    Uint64 phase_start = 0;
    Uint64 run_start_time = 0;
    Uint64 last_time = 0;

    float char_x = 0.0f;
    int   char_frame = 0;

    // tunable
    float char_speed = 520.0f;
    int char_frame_width = 64;
    int char_height = 64;
    int ground_row_height = 1;          // thicker = denser line

    float bottom_y = 0;

    std::mt19937 rng;
};

namespace StartScreen_Event {
    void event_Loop(SDL_Renderer* renderer);
}