move_right - 1Fr3aK2/Cub3d GitHub Wiki
📝 move_right
Moves the player to the right (strafe) relative to their current facing direction, based on their directional vector and movement speed.
⚙️ Parameters
| Parameter | Type | Description |
|---|---|---|
data |
t_data* |
Pointer to the main game data structure containing the player and map information. |
🔁 Returns
| Return value | Description |
|---|---|
void |
This function does not return a value. |
📖 Description
The move_right function updates the player's position to strafe right relative to the direction they are currently facing. It calculates new potential coordinates by adding the player’s directional vector scaled by a constant movement speed (MOVE_SPEED) to the current position.
Before updating the player's position, the function checks for collisions using the is_wall function to ensure that the new position does not intersect a wall.
If there is no wall in the intended direction of movement, the player’s x and y coordinates are updated independently.
- The function first ensures that the
datapointer is valid. - The new potential position is calculated as:
new_x = player.x + player.dir_x * MOVE_SPEEDnew_y = player.y + player.dir_y * MOVE_SPEED
- Each axis (
xandy) is checked independently to allow smooth sliding along walls, enabling natural strafing movement.
💡 Example Usage
t_data data; // Game data structure containing the map and player info
// Assume data.player.dir_x and data.player.dir_y are set to the direction the player is facing
move_right(&data); // Moves the player right (strafe) if no wall is blocking the path