diff --git a/config.cub b/config.cub index 4f36cb2..18eb5e4 100644 --- a/config.cub +++ b/config.cub @@ -27,6 +27,6 @@ WE ./path_to_the_west_texture 110000101000000000000001 110100001000000000000001 110111111000000000000001 -1100000000000000N0000001 -111111111000000000000001 +110000000000000000000001 +1111111110000000000000N1 111111111111111111111111 diff --git a/src/keys.c b/src/keys.c index b974732..9cb12ea 100644 --- a/src/keys.c +++ b/src/keys.c @@ -6,7 +6,7 @@ /* 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"); 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->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->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_A)) { - /*if (!vl->map[(int)vl->posx - (int)vl->dirx * (int)vl->movespeed][(int)vl->posy])*/ - /*{*/ - /*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])*/ - /*{*/ + 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 - 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 (!vl->map[(int)vl->posx - (int)vl->dirx * (int)vl->movespeed][(int)vl->posy])*/ - /*{*/ - /*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])*/ - /*{*/ + 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 - 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 (!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->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_LEFT)) { diff --git a/src/map.c b/src/map.c index 91e9f86..49279d4 100644 --- a/src/map.c +++ b/src/map.c @@ -6,7 +6,7 @@ /* 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->posy = y; - if (dir == 'N' || dir == 'E') + if (dir == 'N') + { vl->dirx = -1; - else - vl->dirx = 0; - if (dir == 'S' || dir == 'W') - vl->diry = -1; - else 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'); } @@ -78,5 +98,7 @@ char **ft_getmap(t_varlist *vl, int fd) y++; } free(line); + if (x > 500 || y > 500) + return (NULL); return (map); } diff --git a/src/parse.c b/src/parse.c index 53bfa5f..655988b 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,7 +6,7 @@ /* 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); free(line); + if (!vl.map) + ft_errorexit("The map is too big, 500x500 max\n", "", 1); return (vl); }