Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / src/systems/plate_system.cpp

sdl_runtime_compiler git · main

SDL3 game for running and compiling code at runtime

sdl3 c++ compiler dlopen cmake · first commit 2026-04-19 · last commit 2026-07-03 (3 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-runtime-compiler

C++ 72.3% C 26.2%
git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gz
src/systems/plate_system.cpp 1.4 KB · 43 lines raw
#include "entities/player.hpp"
#include "plate_system.hpp"
#include "states/game_state.hpp"
#include "levels/director.hpp"

namespace
Nimbin
{

void
PlateSystem::update(double dt,
                    const Player& player,
                    const DynArray<Level::StepPlate>& plates)
{
    const double px_min = player.pos.x - static_cast<double>(player.radius);
    const double px_max = player.pos.x + static_cast<double>(player.radius);
    const double py_min = player.pos.y - static_cast<double>(player.height);
    [[maybe_unused]] const double py_max = player.pos.y;
    const double pz_min = player.pos.z - static_cast<double>(player.radius);
    const double pz_max = player.pos.z + static_cast<double>(player.radius);

    for (const Level::StepPlate& sp : plates) {
        Plate* plate = sp.plate;
        if (!plate) continue;

        plate->tick(dt);

        const Vec3 min = plate->aabb_Min();
        const Vec3 max = plate->aabb_Max();

        const bool xz_overlap = px_max >= min.x && px_min <= max.x &&
                                pz_max >= min.z && pz_min <= max.z;
        const bool y_close    = py_min <= max.y + 0.2 &&
                                py_min >= min.y - 0.1;
        const bool was_active = plate->active;
        plate->active = xz_overlap && y_close;

        if (plate->active && !was_active)
            plate->pulse = 1.0;
    }
}

} // namespace Nimbin