fixed segfault when walking into outer wall
This commit is contained in:
parent
d5c4fc5713
commit
663de33fc0
@ -8,7 +8,7 @@ WE ./assets/wood.png
|
||||
|
||||
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
1 B1 1 1 1 1 1
|
||||
1 K D K K 1 C D D X 1
|
||||
1 K D K K 1 C D D K K X 1
|
||||
1 1 1 1 1 1 1
|
||||
1 11111111111 11111111111 111111111111111111111 1 1111111111 1111111111
|
||||
1 1B C B1 1 1 1 1 1 D K K 1 1
|
||||
|
23
src/keys.c
23
src/keys.c
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
|
||||
/* Updated: 2023/10/29 17:35:38 by houtworm ######## odam.nl */
|
||||
/* Updated: 2023/10/29 18:57:04 by houtworm ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,17 +16,22 @@ void ft_movementkeys(t_varlist *vl)
|
||||
{
|
||||
double olddirx;
|
||||
double oldplanex;
|
||||
double distance;
|
||||
|
||||
if (vl->side)
|
||||
distance = vl->sidedisty - vl->deltadisty;
|
||||
else
|
||||
distance = vl->sidedistx - vl->deltadistx;
|
||||
if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT))
|
||||
ft_putendl("shoot");
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_W))
|
||||
{
|
||||
if (vl->map[(int)(vl->posx + vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||
if (vl->map[(int)(vl->posx + vl->dirx * vl->movespeed)][(int)vl->posy] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx += vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy += vl->diry * vl->movespeed * vl->run;
|
||||
}
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * vl->movespeed)] == '0')
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * vl->movespeed)] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx += vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy += vl->diry * vl->movespeed * vl->run;
|
||||
@ -34,12 +39,12 @@ void ft_movementkeys(t_varlist *vl)
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_A))
|
||||
{
|
||||
if (vl->map[(int)(vl->posx - vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||
if (vl->map[(int)(vl->posx - vl->dirx * vl->movespeed)][(int)vl->posy] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx -= vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy += vl->dirx * vl->movespeed * vl->run;
|
||||
}
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * vl->movespeed)] == '0')
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * vl->movespeed)] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx -= vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy += vl->dirx * vl->movespeed * vl->run;
|
||||
@ -47,12 +52,12 @@ void ft_movementkeys(t_varlist *vl)
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_S))
|
||||
{
|
||||
if (vl->map[(int)(vl->posx - vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||
if (vl->map[(int)(vl->posx - vl->dirx * vl->movespeed)][(int)vl->posy] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx -= vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->diry * vl->movespeed * vl->run;
|
||||
}
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * vl->movespeed)] == '0')
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * vl->movespeed)] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx -= vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->diry * vl->movespeed * vl->run;
|
||||
@ -60,12 +65,12 @@ void ft_movementkeys(t_varlist *vl)
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_D))
|
||||
{
|
||||
if (vl->map[(int)(vl->posx + vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||
if (vl->map[(int)(vl->posx + vl->dirx * vl->movespeed)][(int)vl->posy] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx += vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->dirx * vl->movespeed * vl->run;
|
||||
}
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * vl->movespeed)] == '0')
|
||||
if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * vl->movespeed)] == '0' && distance > 0.5)
|
||||
{
|
||||
vl->posx += vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->dirx * vl->movespeed * vl->run;
|
||||
|
Loading…
Reference in New Issue
Block a user