mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
fix: prevent crash due to out-of-bounds when game lags
This commit is contained in:
parent
1d6d97ef25
commit
a18c115ef1
7 changed files with 90 additions and 26 deletions
|
|
@ -6,79 +6,80 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/05 12:53:06 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/05 12:53:06 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/08/06 11:46:04 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d_data.h"
|
||||
#include "angle.h"
|
||||
#include "../consts.h"
|
||||
#include "../map/collision.h"
|
||||
|
||||
void move_player_forward(t_cub3d_data *data)
|
||||
{
|
||||
char **map;
|
||||
t_mapdata *map;
|
||||
double next_x;
|
||||
double next_y;
|
||||
float movspeed;
|
||||
|
||||
movspeed = MOVEMENT_SPEED * data->delta;
|
||||
map = data->map->map;
|
||||
map = data->map;
|
||||
next_x = data->player.x + data->player.dir_x * movspeed;
|
||||
next_y = data->player.y + data->player.dir_y * movspeed;
|
||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||
if (!blocks_movement(map, (int)data->player.y, (int)next_x))
|
||||
data->player.x += data->player.dir_x * movspeed;
|
||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||
if (!blocks_movement(map, (int)next_y, (int)data->player.x))
|
||||
data->player.y += data->player.dir_y * movspeed;
|
||||
}
|
||||
|
||||
void move_player_backward(t_cub3d_data *data)
|
||||
{
|
||||
char **map;
|
||||
t_mapdata *map;
|
||||
double next_x;
|
||||
double next_y;
|
||||
float movspeed;
|
||||
|
||||
movspeed = MOVEMENT_SPEED * data->delta;
|
||||
map = data->map->map;
|
||||
map = data->map;
|
||||
next_x = data->player.x - data->player.dir_x * movspeed;
|
||||
next_y = data->player.y - data->player.dir_y * movspeed;
|
||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||
if (!blocks_movement(map, (int)data->player.y, (int)next_x))
|
||||
data->player.x -= data->player.dir_x * movspeed;
|
||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||
if (!blocks_movement(map, (int)next_y, (int)data->player.x))
|
||||
data->player.y -= data->player.dir_y * movspeed;
|
||||
}
|
||||
|
||||
void move_player_strafe_left(t_cub3d_data *data)
|
||||
{
|
||||
char **map;
|
||||
t_mapdata *map;
|
||||
double next_x;
|
||||
double next_y;
|
||||
float movspeed;
|
||||
|
||||
movspeed = MOVEMENT_SPEED * data->delta;
|
||||
map = data->map->map;
|
||||
map = data->map;
|
||||
next_x = data->player.x - data->player.plane_x * movspeed;
|
||||
next_y = data->player.y - data->player.plane_y * movspeed;
|
||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||
if (!blocks_movement(map, (int)data->player.y, (int)next_x))
|
||||
data->player.x -= data->player.plane_x * movspeed;
|
||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||
if (!blocks_movement(map, (int)next_y, (int)data->player.x))
|
||||
data->player.y -= data->player.plane_y * movspeed;
|
||||
}
|
||||
|
||||
void move_player_strafe_right(t_cub3d_data *data)
|
||||
{
|
||||
char **map;
|
||||
t_mapdata *map;
|
||||
double next_x;
|
||||
double next_y;
|
||||
float movspeed;
|
||||
|
||||
movspeed = MOVEMENT_SPEED * data->delta;
|
||||
map = data->map->map;
|
||||
map = data->map;
|
||||
next_x = data->player.x + data->player.plane_x * movspeed;
|
||||
next_y = data->player.y + data->player.plane_y * movspeed;
|
||||
if (map[(int)data->player.y][(int)next_x] == '0')
|
||||
if (!blocks_movement(map, (int)data->player.y, (int)next_x))
|
||||
data->player.x += data->player.plane_x * movspeed;
|
||||
if (map[(int)next_y][(int)data->player.x] == '0')
|
||||
if (!blocks_movement(map, (int)next_y, (int)data->player.x))
|
||||
data->player.y += data->player.plane_y * movspeed;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue