handle_keyrelease - 1Fr3aK2/Cub3d GitHub Wiki
📝 handle_keyrelease
Handles the release of a key by updating the player's movement or rotation state flags in the main game data structure. When a key is released, the corresponding bit in the keys bitmask is cleared, stopping the associated movement or rotation action.
⚙️ Parameters
| Parameter | Type | Description |
|---|---|---|
key |
int |
The keycode of the key that was released. |
data |
t_data* |
Pointer to the main game data structure containing player and key state information. |
🔁 Returns
| Return value | Description |
|---|---|
int |
Always returns 0 (used for compatibility with the event handler). |
📖 Description
The handle_keyrelease function checks which key was released and clears the corresponding bit in the data->keys bitmask using the helper function set_bit. This ensures that the game stops performing the action associated with that key.
Supported key releases:
XK_w→ clears theFORWARDflag.XK_s→ clears theBACKWARDSflag.XK_a→ clears theLEFT_Sflag.XK_d→ clears theRIGHT_Sflag.XK_Left→ clears theTURN_Lflag.XK_Right→ clears theTURN_Rflag.
Notes:
- Each movement or rotation flag corresponds to a bit in the
keysbitmask. - Clearing the bit ensures the player stops moving or turning in that direction.
- The function does not perform movement directly; it only updates the state used by the game loop.
💡 Example Usage
t_data data;
// Assume the keys bitmask is already initialized and a key event is triggered
handle_keyrelease(XK_w, &data); // Stops the player from moving forward
handle_keyrelease(XK_Left, &data); // Stops the player from turning left