Nimbin[12]?SDL & Graphics / sdl3_3d_oop_basic_game / src/systems/input_system.cpp

sdl3_3d_oop_basic_game git · main

SDL3 3D OOP basic game (entities, systems, CMake)

sdl3 3d c++ game cmake · first commit 2026-04-19 · last commit 2026-04-19 (7 months ago) · synced 1 hour ago · upstream: git.ide3.de/chfis005/sdl3_3d_oop_basic_game

C++ 99%
git clone https://git.christianimmanuel.de/sdl-graphics/sdl3_3d_oop_basic_game.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl3_3d_oop_basic_game/archive/sdl3_3d_oop_basic_game.tar.gz
src/systems/input_system.cpp 756 B · 22 lines raw
#include "systems/input_system.hpp"

void InputSystem::handleEvent(const SDL_Event& e, PlayerInputState& input, Player& player)
{
    switch (e.type) {
        case SDL_EVENT_MOUSE_MOTION:
            player.addLook((int)e.motion.xrel, (int)e.motion.yrel);
            break;
        case SDL_EVENT_KEY_DOWN:
        case SDL_EVENT_KEY_UP: {
            bool down = (e.type == SDL_EVENT_KEY_DOWN);
            SDL_Keycode sym = e.key.key;

            if (sym == SDLK_W) input.forward = down;
            if (sym == SDLK_A) input.left = down;
            if (sym == SDLK_S) input.backward = down;
            if (sym == SDLK_D) input.right = down;
            if (sym == SDLK_SPACE && down) player.jump_pressed = true;
            break;
        }
    }
}