player starting direction is now correct
This commit is contained in:
parent
26b4e9d03d
commit
9472c212c1
@ -27,6 +27,6 @@ WE ./path_to_the_west_texture
|
|||||||
110000101000000000000001
|
110000101000000000000001
|
||||||
110100001000000000000001
|
110100001000000000000001
|
||||||
110111111000000000000001
|
110111111000000000000001
|
||||||
1100000000000000N0000001
|
110000000000000000000001
|
||||||
111111111000000000000001
|
1111111110000000000000N1
|
||||||
111111111111111111111111
|
111111111111111111111111
|
||||||
|
66
src/keys.c
66
src/keys.c
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
|
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/29 12:26:33 by houtworm ######## odam.nl */
|
/* Updated: 2023/10/29 14:46:05 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,55 +21,55 @@ void ft_movementkeys(t_varlist *vl)
|
|||||||
ft_putendl("shoot");
|
ft_putendl("shoot");
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_W))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_W))
|
||||||
{
|
{
|
||||||
/*if (!vl->map[(int)vl->posx + (int)vl->dirx * (int)vl->movespeed][(int)vl->posy])*/
|
if (vl->map[(int)(vl->posx + vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||||
/*{*/
|
{
|
||||||
vl->posx += vl->dirx * vl->movespeed;
|
vl->posx += vl->dirx * vl->movespeed;
|
||||||
vl->posy += vl->diry * vl->movespeed;
|
vl->posy += vl->diry * vl->movespeed;
|
||||||
/*}*/
|
}
|
||||||
/*if (!vl->map[(int)vl->posx][(int)vl->posy + (int)vl->diry * (int)vl->movespeed])*/
|
if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * vl->movespeed)] == '0')
|
||||||
/*{*/
|
{
|
||||||
/*vl->posx += vl->dirx * vl->movespeed;*/
|
vl->posx += vl->dirx * vl->movespeed;
|
||||||
/*vl->posy += vl->diry * vl->movespeed;*/
|
vl->posy += vl->diry * vl->movespeed;
|
||||||
/*}*/
|
}
|
||||||
}
|
}
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_A))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_A))
|
||||||
{
|
{
|
||||||
/*if (!vl->map[(int)vl->posx - (int)vl->dirx * (int)vl->movespeed][(int)vl->posy])*/
|
if (vl->map[(int)(vl->posx - vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||||
/*{*/
|
{
|
||||||
/*vl->posx -= vl->diry * vl->movespeed;*/
|
|
||||||
/*vl->posy += vl->dirx * vl->movespeed;*/
|
|
||||||
/*}*/
|
|
||||||
/*if (!vl->map[(int)vl->posx][(int)vl->posy - (int)vl->diry * (int)vl->movespeed])*/
|
|
||||||
/*{*/
|
|
||||||
vl->posx -= vl->diry * vl->movespeed;
|
vl->posx -= vl->diry * vl->movespeed;
|
||||||
vl->posy += vl->dirx * vl->movespeed;
|
vl->posy += vl->dirx * vl->movespeed;
|
||||||
/*}*/
|
}
|
||||||
|
if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * vl->movespeed)] == '0')
|
||||||
|
{
|
||||||
|
vl->posx -= vl->diry * vl->movespeed;
|
||||||
|
vl->posy += vl->dirx * vl->movespeed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_S))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_S))
|
||||||
{
|
{
|
||||||
/*if (!vl->map[(int)vl->posx - (int)vl->dirx * (int)vl->movespeed][(int)vl->posy])*/
|
if (vl->map[(int)(vl->posx - vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||||
/*{*/
|
{
|
||||||
/*vl->posx -= vl->dirx * vl->movespeed;*/
|
|
||||||
/*vl->posy -= vl->diry * vl->movespeed;*/
|
|
||||||
/*}*/
|
|
||||||
/*if (!vl->map[(int)vl->posx][(int)vl->posy - (int)vl->diry * (int)vl->movespeed])*/
|
|
||||||
/*{*/
|
|
||||||
vl->posx -= vl->dirx * vl->movespeed;
|
vl->posx -= vl->dirx * vl->movespeed;
|
||||||
vl->posy -= vl->diry * vl->movespeed;
|
vl->posy -= vl->diry * vl->movespeed;
|
||||||
/*}*/
|
}
|
||||||
|
if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * vl->movespeed)] == '0')
|
||||||
|
{
|
||||||
|
vl->posx -= vl->dirx * vl->movespeed;
|
||||||
|
vl->posy -= vl->diry * vl->movespeed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_D))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_D))
|
||||||
{
|
{
|
||||||
/*if (!vl->map[(int)vl->posx + (int)vl->dirx * (int)vl->movespeed][(int)vl->posy])*/
|
if (vl->map[(int)(vl->posx + vl->dirx * vl->movespeed)][(int)vl->posy] == '0')
|
||||||
/*{*/
|
{
|
||||||
vl->posx += vl->diry * vl->movespeed;
|
vl->posx += vl->diry * vl->movespeed;
|
||||||
vl->posy -= vl->dirx * vl->movespeed;
|
vl->posy -= vl->dirx * vl->movespeed;
|
||||||
/*}*/
|
}
|
||||||
/*if (!vl->map[(int)vl->posx][(int)vl->posy + (int)vl->diry * (int)vl->movespeed])*/
|
if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * vl->movespeed)] == '0')
|
||||||
/*{*/
|
{
|
||||||
/*vl->posx += vl->diry * vl->movespeed;*/
|
vl->posx += vl->diry * vl->movespeed;
|
||||||
/*vl->posy -= vl->dirx * vl->movespeed;*/
|
vl->posy -= vl->dirx * vl->movespeed;
|
||||||
/*}*/
|
}
|
||||||
}
|
}
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT))
|
||||||
{
|
{
|
||||||
|
36
src/map.c
36
src/map.c
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */
|
/* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/29 14:25:40 by houtworm ######## odam.nl */
|
/* Updated: 2023/10/29 14:59:47 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,14 +17,34 @@ char ft_setplayerpos(t_varlist *vl, char dir, int y, int x)
|
|||||||
{
|
{
|
||||||
vl->posx = x;
|
vl->posx = x;
|
||||||
vl->posy = y;
|
vl->posy = y;
|
||||||
if (dir == 'N' || dir == 'E')
|
if (dir == 'N')
|
||||||
|
{
|
||||||
vl->dirx = -1;
|
vl->dirx = -1;
|
||||||
else
|
|
||||||
vl->dirx = 0;
|
|
||||||
if (dir == 'S' || dir == 'W')
|
|
||||||
vl->diry = -1;
|
|
||||||
else
|
|
||||||
vl->diry = 0;
|
vl->diry = 0;
|
||||||
|
vl->planex = 0;
|
||||||
|
vl->planey = 0.66;
|
||||||
|
}
|
||||||
|
else if (dir == 'E')
|
||||||
|
{
|
||||||
|
vl->dirx = 0;
|
||||||
|
vl->diry = 1;
|
||||||
|
vl->planex = 0.66;
|
||||||
|
vl->planey = 0;
|
||||||
|
}
|
||||||
|
else if (dir == 'S')
|
||||||
|
{
|
||||||
|
vl->dirx = 1;
|
||||||
|
vl->diry = 0;
|
||||||
|
vl->planex = 0;
|
||||||
|
vl->planey = -0.66;
|
||||||
|
}
|
||||||
|
else if (dir == 'W')
|
||||||
|
{
|
||||||
|
vl->dirx = 0;
|
||||||
|
vl->diry = -1;
|
||||||
|
vl->planex = -0.66;
|
||||||
|
vl->planey = 0;
|
||||||
|
}
|
||||||
return ('0');
|
return ('0');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,5 +98,7 @@ char **ft_getmap(t_varlist *vl, int fd)
|
|||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
|
if (x > 500 || y > 500)
|
||||||
|
return (NULL);
|
||||||
return (map);
|
return (map);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */
|
/* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/29 13:54:50 by houtworm ######## odam.nl */
|
/* Updated: 2023/10/29 14:33:27 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -134,5 +134,7 @@ t_varlist ft_parseconfigfile(t_varlist vl, char *filename)
|
|||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
free(line);
|
free(line);
|
||||||
|
if (!vl.map)
|
||||||
|
ft_errorexit("The map is too big, 500x500 max\n", "", 1);
|
||||||
return (vl);
|
return (vl);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user