From 0c006f726bc8001cf75797e85697cc9a9f2903a5 Mon Sep 17 00:00:00 2001 From: djonker Date: Sun, 5 Nov 2023 19:22:04 +0100 Subject: [PATCH] working on wallgliding --- maps/spritetest.cub | 2 +- src/draw/raycast.c | 2 +- src/input/move.c | 30 +++++++++++++++--------------- src/main/main.c | 21 ++++++++++++++++++++- src/parse/map.c | 2 +- src/parse/sprite.c | 2 +- 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/maps/spritetest.cub b/maps/spritetest.cub index 8e56a71..611d22e 100644 --- a/maps/spritetest.cub +++ b/maps/spritetest.cub @@ -10,6 +10,6 @@ WE ./assets/wall/wood.png 1BbLAPpVfTslC1 1$#*&987[]3421 1 1 -1 K N 1 +1 N 1 1 1 11111111111111 diff --git a/src/draw/raycast.c b/src/draw/raycast.c index 98f8efd..23c238e 100644 --- a/src/draw/raycast.c +++ b/src/draw/raycast.c @@ -6,7 +6,7 @@ /* By: djonker +#+ */ /* +#+ */ /* Created: 2023/10/27 14:36:42 by djonker #+# #+# */ -/* Updated: 2023/11/05 07:28:58 by houtworm ######## odam.nl */ +/* Updated: 2023/11/05 19:05:24 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/input/move.c b/src/input/move.c index 7bc914d..3776e05 100644 --- a/src/input/move.c +++ b/src/input/move.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */ -/* Updated: 2023/11/05 09:05:31 by houtworm ######## odam.nl */ +/* Updated: 2023/11/05 19:21:34 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -21,9 +21,9 @@ void ft_moveforward(t_varlist *vl, double movespeed) else distance = vl->sidedistx - vl->deltadistx; if (vl->map[(int)(vl->posx + vl->dirx * movespeed)][(int)vl->posy] == '0' && distance > 0.4) - vl->posx += vl->dirx * movespeed * vl->run; + vl->posx += vl->dirx * movespeed; if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * movespeed)] == '0' && distance > 0.4) - vl->posy += vl->diry * movespeed * vl->run; + vl->posy += vl->diry * movespeed; } void ft_movebackward(t_varlist *vl, double movespeed) @@ -35,9 +35,9 @@ void ft_movebackward(t_varlist *vl, double movespeed) else distance = vl->sidedistx - vl->deltadistx; if (vl->map[(int)(vl->posx - vl->dirx * movespeed)][(int)vl->posy] == '0' && distance > 0.4) - vl->posx -= vl->dirx * movespeed * vl->run; + vl->posx -= vl->dirx * movespeed; if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * movespeed)] == '0' && distance > 0.4) - vl->posy -= vl->diry * movespeed * vl->run; + vl->posy -= vl->diry * movespeed; } void ft_moveleft(t_varlist *vl, double movespeed) @@ -49,9 +49,9 @@ void ft_moveleft(t_varlist *vl, double movespeed) else distance = vl->sidedistx - vl->deltadistx; if (vl->map[(int)(vl->posx - vl->dirx * movespeed)][(int)vl->posy] == '0' && distance > 0.4) - vl->posx -= vl->diry * movespeed * vl->run; - if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * movespeed)] == '0' && distance > 0.4) - vl->posy += vl->dirx * movespeed * vl->run; + vl->posx -= vl->diry * movespeed; + if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * movespeed)] == '0' && distance > 0.4) + vl->posy += vl->dirx * movespeed; } void ft_moveright(t_varlist *vl, double movespeed) @@ -63,19 +63,19 @@ void ft_moveright(t_varlist *vl, double movespeed) else distance = vl->sidedistx - vl->deltadistx; if (vl->map[(int)(vl->posx + vl->dirx * movespeed)][(int)vl->posy] == '0' && distance > 0.4) - vl->posx += vl->diry * movespeed * vl->run; - if (vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * movespeed)] == '0' && distance > 0.4) - vl->posy -= vl->dirx * movespeed * vl->run; + vl->posx += vl->diry * movespeed; + if (vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * movespeed)] == '0' && distance > 0.4) + vl->posy -= vl->dirx * movespeed; } void ft_processmove(t_varlist *vl, double movespeed) { if (mlx_is_key_down(vl->mlx, MLX_KEY_W)) - ft_moveforward(vl, movespeed); + ft_moveforward(vl, movespeed * vl->run); if (mlx_is_key_down(vl->mlx, MLX_KEY_A)) - ft_moveleft(vl, movespeed); + ft_moveleft(vl, movespeed * vl->run); if (mlx_is_key_down(vl->mlx, MLX_KEY_S)) - ft_movebackward(vl, movespeed); + ft_movebackward(vl, movespeed * vl->run); if (mlx_is_key_down(vl->mlx, MLX_KEY_D)) - ft_moveright(vl, movespeed); + ft_moveright(vl, movespeed * vl->run); } diff --git a/src/main/main.c b/src/main/main.c index 6f85593..8acdc34 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */ -/* Updated: 2023/11/05 12:41:47 by houtworm ######## odam.nl */ +/* Updated: 2023/11/05 19:21:37 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -21,6 +21,24 @@ void ft_replaceimage(t_varlist *vl) vl->img = mlx_new_image(vl->mlx, vl->w, vl->h); } +void ft_printmap(t_varlist *vl) +{ + int i; + + i = 0; + while (vl->map[i]) + { + ft_putendl(vl->map[i]); + i++; + } + double movespeed; + movespeed = vl->frametime * 3.0; + printf("foreward: %c, %c\n", vl->map[(int)(vl->posx + vl->dirx * movespeed)][(int)vl->posy], vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * movespeed)]); + printf("backward: %c, %c\n", vl->map[(int)(vl->posx - vl->dirx * movespeed)][(int)vl->posy], vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * movespeed)]); + printf("leftward: %c, %c\n", vl->map[(int)(vl->posx - vl->dirx * movespeed)][(int)vl->posy], vl->map[(int)vl->posx][(int)(vl->posy + vl->diry * movespeed)]); + printf("righward: %c, %c\n", vl->map[(int)(vl->posx + vl->dirx * movespeed)][(int)vl->posy], vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * movespeed)]); +} + void mainloop(void *param) { t_varlist *vl; @@ -37,6 +55,7 @@ void mainloop(void *param) /*ft_enemyaction(vl);*/ vl->frametime = vl->mlx->delta_time; ft_processinput(vl); + /*ft_printmap(vl);*/ if (!vl->img || (mlx_image_to_window(vl->mlx, vl->img, 0, 0) < 0)) ft_errorexit("image to window failed ", "mainloop", 1); mlx_set_instance_depth(vl->img->instances, 1); diff --git a/src/parse/map.c b/src/parse/map.c index 725fa28..429c456 100644 --- a/src/parse/map.c +++ b/src/parse/map.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */ -/* Updated: 2023/11/05 12:56:48 by houtworm ######## odam.nl */ +/* Updated: 2023/11/05 19:05:34 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/parse/sprite.c b/src/parse/sprite.c index a5862e8..a0c6fb0 100644 --- a/src/parse/sprite.c +++ b/src/parse/sprite.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */ -/* Updated: 2023/11/05 11:50:59 by houtworm ######## odam.nl */ +/* Updated: 2023/11/05 18:50:53 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */