working on wallgliding

This commit is contained in:
djonker 2023-11-05 19:22:04 +01:00
parent 5f1d9216cf
commit 0c006f726b
6 changed files with 39 additions and 20 deletions

View File

@ -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

View File

@ -6,7 +6,7 @@
/* By: djonker <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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);
}

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */