movements - 1Fr3aK2/Cub3d GitHub Wiki

πŸ“ movements

Handles all player movement and rotation actions based on the currently active key inputs stored inside the game’s data structure.

βš™οΈ Parameters

Parameter Type Description
data t_data * Pointer to the main game data structure containing key states, player information, and movement handlers.

πŸ” Returns

Return value Description
void This function does not return a value; instead, it triggers the appropriate movement or rotation functions depending on active key flags.

πŸ“– Description

The movements function processes the current keyboard input flags stored in data->keys and executes the corresponding movement or rotation functions.
It checks each direction/rotation bitmask and calls the appropriate handler:

This function is typically called once per frame (e.g., inside the main loop or update loop) to ensure that player movement feels continuous and responsive.

πŸ” Input Handling

The data->keys field is a bitmask that tracks which movement keys are currently pressed.
By using bitwise checks (&), the function can process multiple simultaneous inputsβ€”such as moving forward while turning.

This allows smooth, natural movement like strafing, diagonal walking, and rotating while moving.

πŸ’‘ Example Usage

// Called each frame in the main loop
void game_loop(void)
{
    t_data *data = data_s();

    movements(data);    // Apply current movement based on key inputs
    render_frame(data); // Draw frame after updating the player's position/direction
}