strichmaennchen git · main
git clone https://git.christianimmanuel.de/games/strichmaennchen.gitwget https://git.christianimmanuel.de/games/strichmaennchen/archive/strichmaennchen.tar.gzinput.c raw
#include <SDL3/SDL.h>
#include "input.h"
void Input_reset(Userinput* input) {
input->running = true;
input->move_forward = 0;
input->move_sideway = 0;
input->rotate_object_forward = 0;
input->rotate_object_sideway = 0;
input->yaw_delta = 0;
input->pitch_delta = 0;
input->jump = 0;
}
void Input_process(Userinput* userinput) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_QUIT) {
userinput->running = false;
}
}
const bool *keys = SDL_GetKeyboardState(NULL);
// Input: only directions
if (keys[SDL_SCANCODE_LCTRL]) {
if (keys[SDL_SCANCODE_W]) userinput->rotate_object_forward += 1.0f;
if (keys[SDL_SCANCODE_S]) userinput->rotate_object_forward -= 1.0f;
if (keys[SDL_SCANCODE_A]) userinput->rotate_object_sideway -= 1.0f;
if (keys[SDL_SCANCODE_D]) userinput->rotate_object_sideway += 1.0f;
} else {
if (keys[SDL_SCANCODE_W]) userinput->move_forward += 1.0f;
if (keys[SDL_SCANCODE_S]) userinput->move_forward -= 1.0f;
if (keys[SDL_SCANCODE_A]) userinput->move_sideway -= 1.0f;
if (keys[SDL_SCANCODE_D]) userinput->move_sideway += 1.0f;
if (keys[SDL_SCANCODE_SPACE]) userinput->jump = 1;
if (keys[SDL_SCANCODE_LSHIFT]) {
if (keys[SDL_SCANCODE_SPACE]) userinput->jump = 2;
}
// sprint intent
userinput->sprint = keys[SDL_SCANCODE_LSHIFT];
}
float dx, dy;
SDL_GetRelativeMouseState(&dx, &dy);
userinput->yaw_delta = (float)dx * 0.1f;
userinput->pitch_delta = -1* (float)dy * 0.1f;
}