mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
feat: Improved movements with delta
This commit is contained in:
parent
2bc214103b
commit
008a1f9dc8
1 changed files with 17 additions and 17 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/29 13:58:00 by tchampio #+# #+# */
|
/* Created: 2025/07/29 13:58:00 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/07/29 19:47:38 by tchampio ### ########.fr */
|
/* Updated: 2025/07/31 14:43:57 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,12 +21,12 @@ void move_player_forward(t_cub3d_data *data)
|
||||||
double next_y;
|
double next_y;
|
||||||
|
|
||||||
map = data->map->map;
|
map = data->map->map;
|
||||||
next_x = data->player.x + data->player.dir_x * MOVEMENT_SPEED;
|
next_x = data->player.x + data->player.dir_x * MOVEMENT_SPEED * data->delta;
|
||||||
next_y = data->player.y + data->player.dir_y * MOVEMENT_SPEED;
|
next_y = data->player.y + data->player.dir_y * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||||
data->player.x += data->player.dir_x * MOVEMENT_SPEED;
|
data->player.x += data->player.dir_x * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||||
data->player.y += data->player.dir_y * MOVEMENT_SPEED;
|
data->player.y += data->player.dir_y * MOVEMENT_SPEED * data->delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_player_backward(t_cub3d_data *data)
|
void move_player_backward(t_cub3d_data *data)
|
||||||
|
|
@ -36,12 +36,12 @@ void move_player_backward(t_cub3d_data *data)
|
||||||
double next_y;
|
double next_y;
|
||||||
|
|
||||||
map = data->map->map;
|
map = data->map->map;
|
||||||
next_x = data->player.x - data->player.dir_x * MOVEMENT_SPEED;
|
next_x = data->player.x - data->player.dir_x * MOVEMENT_SPEED * data->delta;
|
||||||
next_y = data->player.y - data->player.dir_y * MOVEMENT_SPEED;
|
next_y = data->player.y - data->player.dir_y * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||||
data->player.x -= data->player.dir_x * MOVEMENT_SPEED;
|
data->player.x -= data->player.dir_x * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||||
data->player.y -= data->player.dir_y * MOVEMENT_SPEED;
|
data->player.y -= data->player.dir_y * MOVEMENT_SPEED * data->delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_player_strafe_left(t_cub3d_data *data)
|
void move_player_strafe_left(t_cub3d_data *data)
|
||||||
|
|
@ -51,12 +51,12 @@ void move_player_strafe_left(t_cub3d_data *data)
|
||||||
double next_y;
|
double next_y;
|
||||||
|
|
||||||
map = data->map->map;
|
map = data->map->map;
|
||||||
next_x = data->player.x - data->player.plane_x * MOVEMENT_SPEED;
|
next_x = data->player.x - data->player.plane_x * MOVEMENT_SPEED * data->delta;
|
||||||
next_y = data->player.y - data->player.plane_y * MOVEMENT_SPEED;
|
next_y = data->player.y - data->player.plane_y * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||||
data->player.x -= data->player.plane_x * MOVEMENT_SPEED;
|
data->player.x -= data->player.plane_x * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||||
data->player.y -= data->player.plane_y * MOVEMENT_SPEED;
|
data->player.y -= data->player.plane_y * MOVEMENT_SPEED * data->delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_player_strafe_right(t_cub3d_data *data)
|
void move_player_strafe_right(t_cub3d_data *data)
|
||||||
|
|
@ -66,12 +66,12 @@ void move_player_strafe_right(t_cub3d_data *data)
|
||||||
double next_y;
|
double next_y;
|
||||||
|
|
||||||
map = data->map->map;
|
map = data->map->map;
|
||||||
next_x = data->player.x + data->player.plane_x * MOVEMENT_SPEED;
|
next_x = data->player.x + data->player.plane_x * MOVEMENT_SPEED * data->delta;
|
||||||
next_y = data->player.y + data->player.plane_y * MOVEMENT_SPEED;
|
next_y = data->player.y + data->player.plane_y * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||||
data->player.x += data->player.plane_x * MOVEMENT_SPEED;
|
data->player.x += data->player.plane_x * MOVEMENT_SPEED * data->delta;
|
||||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||||
data->player.y += data->player.plane_y * MOVEMENT_SPEED;
|
data->player.y += data->player.plane_y * MOVEMENT_SPEED * data->delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_player(t_cub3d_data *data)
|
void move_player(t_cub3d_data *data)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue