← All work

IMPLEMENTATION NOTES / C++ / SDL2

Color Wall Game

A small action game in C++ and SDL2. Move with WASD to the wall of the called color and touch it before time runs out.

C++SDL2SDL2_ttf

IMPLEMENTATION / EQUATIONS & SOURCE

Follow the inputs through the code.

Read each section as purpose → equation → actual source. Snippets are excerpts of the working implementation, not standalone programs. Follow the source link for surrounding context.

01 / Interpolate movement toward a wall

Input selects a destination wall and stores starting position/time. Divide elapsed time by MOVE_DURATION and linearly interpolate to the destination. On completion, compare the selected wall’s color to the directive; this is not a general circle-versus-rectangle physics test.

Equation
t = min(1, elapsed / MOVE_DURATION)
pos(t) = start + t(target−start)
src/Player.cpp : 69COMMIT 811457c
    Uint32 elapsed = currentTime - moveStartTime;
    float t = static_cast<float>(elapsed) / MOVE_DURATION;

    // 移動完了後は位置を固定
    if (t >= 1.0f) {
        t = 1.0f;
    }

    // 線形補間で位置を更新
    x = startX + t * (targetX - startX);
    y = startY + t * (targetY - startY);
Read this source on GitHub ↗

02 / Reduce the time limit every five successes

A success increments score and success count. Every fifth success subtracts 0.2 seconds from the round limit, clamped at MIN_MAX_TIME. The next round resets remaining time to the new limit.

Equation
T(k) = max(Tmin, T₀ − 0.2 floor(k/5))

k: cumulative successes; T₀ and Tmin: configured limits. Remaining time decreases by deltaTime during both playing and moving states.

src/game.cpp : 352COMMIT 811457c
                if (successCount % 5 == 0) {
                    currentMaxTime -= 0.2f;
                    if (currentMaxTime < MIN_MAX_TIME) {
                        currentMaxTime = MIN_MAX_TIME;
                    }
                }
Read this source on GitHub ↗

SOURCE / SCOPE

Scope of the notes.

Each source excerpt comes from the linked fixed commit. Equations describe those operations. Apart from worked examples, no new performance or quality measurements are claimed. Refer to the repository for build steps and dependencies.

Open repository ↗