player can run now:)

This commit is contained in:
djonker 2023-10-29 15:59:24 +01:00
parent 9472c212c1
commit 0148ee755e
8 changed files with 46 additions and 47 deletions

View File

@ -6,13 +6,13 @@
# By: houtworm <codam@houtworm.net> +#+ # # By: houtworm <codam@houtworm.net> +#+ #
# +#+ # # +#+ #
# Created: 2023/10/26 10:46:29 by houtworm #+# #+# # # Created: 2023/10/26 10:46:29 by houtworm #+# #+# #
# Updated: 2023/10/29 06:31:28 by houtworm ######## odam.nl # # Updated: 2023/10/29 15:24:58 by houtworm ######## odam.nl #
# # # #
# **************************************************************************** # # **************************************************************************** #
NAME =cub3d NAME =cub3d
CC =gcc CC =gcc
FC =-Wall -Werror -Wextra -Wunreachable-code -Ofast -g -fsanitize=address FC =-Wall -Werror -Wextra -Wunreachable-code -Ofast# -g -fsanitize=address
HEAD =-I ./include -I $(MLX)/include HEAD =-I ./include -I $(MLX)/include
RM =rm -rf RM =rm -rf
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm

View File

@ -1,10 +1,10 @@
C 0,100,255 C 0,100,255
F 100,100,100 F 100,100,100
NO ./path_to_the_north_texture NO ./assets/bluestone.png
EA ./path_to_the_east_texture EA ./assets/colorstone.png
SO ./path_to_the_south_texture SO ./assets/redbrick.png
WE ./path_to_the_west_texture WE ./assets/wood.png
111111111111111111111111 111111111111111111111111
100000000000000000000001 100000000000000000000001
@ -26,7 +26,7 @@ WE ./path_to_the_west_texture
110100001000000000000001 110100001000000000000001
110000101000000000000001 110000101000000000000001
110100001000000000000001 110100001000000000000001
110111111000000000000001 11011111100000000000N001
110000000000000000000001 110000000000000000000001
1111111110000000000000N1 111111111000000000000001
111111111111111111111111 111111111111111111111111

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */ /* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
/* Updated: 2023/10/29 13:46:54 by houtworm ######## odam.nl */ /* Updated: 2023/10/29 15:54:07 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,6 +51,7 @@ typedef struct s_varlist
int stepy; int stepy;
int hit; int hit;
int side; int side;
double run;
double oldmouseposx; double oldmouseposx;
double oldmouseposy; // only needed if we do vertical aiming double oldmouseposy; // only needed if we do vertical aiming
int32_t fcolor; int32_t fcolor;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */ /* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
/* Updated: 2023/10/29 13:52:03 by houtworm ######## odam.nl */ /* Updated: 2023/10/29 15:23:35 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,8 +24,6 @@ t_varlist initvarlist(void)
vl.eastwt = NULL; vl.eastwt = NULL;
vl.southwt = NULL; vl.southwt = NULL;
vl.westwt = NULL; vl.westwt = NULL;
vl.planex = 0;
vl.planey = 0.66;
vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true); vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true);
if (!vl.mlx) if (!vl.mlx)
ft_errorexit("MLX failed to init", "initvarlist", 1); ft_errorexit("MLX failed to init", "initvarlist", 1);

View File

@ -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 14:46:05 by houtworm ######## odam.nl */ /* Updated: 2023/10/29 15:55:18 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,52 +23,52 @@ void ft_movementkeys(t_varlist *vl)
{ {
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')
{ {
vl->posx += vl->dirx * vl->movespeed; vl->posx += vl->dirx * vl->movespeed * vl->run;
vl->posy += vl->diry * vl->movespeed; 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')
{ {
vl->posx += vl->dirx * vl->movespeed; vl->posx += vl->dirx * vl->movespeed * vl->run;
vl->posy += vl->diry * vl->movespeed; vl->posy += vl->diry * vl->movespeed * vl->run;
} }
} }
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 - vl->dirx * vl->movespeed)][(int)vl->posy] == '0') 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->run;
vl->posy += vl->dirx * vl->movespeed; 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')
{ {
vl->posx -= vl->diry * vl->movespeed; vl->posx -= vl->diry * vl->movespeed * vl->run;
vl->posy += vl->dirx * vl->movespeed; vl->posy += vl->dirx * vl->movespeed * vl->run;
} }
} }
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 - vl->dirx * vl->movespeed)][(int)vl->posy] == '0') 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->run;
vl->posy -= vl->diry * vl->movespeed; 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')
{ {
vl->posx -= vl->dirx * vl->movespeed; vl->posx -= vl->dirx * vl->movespeed * vl->run;
vl->posy -= vl->diry * vl->movespeed; vl->posy -= vl->diry * vl->movespeed * vl->run;
} }
} }
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 + vl->dirx * vl->movespeed)][(int)vl->posy] == '0') 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->run;
vl->posy -= vl->dirx * vl->movespeed; 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')
{ {
vl->posx += vl->diry * vl->movespeed; vl->posx += vl->diry * vl->movespeed * vl->run;
vl->posy -= vl->dirx * vl->movespeed; vl->posy -= vl->dirx * vl->movespeed * vl->run;
} }
} }
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT)) if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT))
@ -105,6 +105,10 @@ void keyhook(mlx_key_data_t kd, void *param)
} }
if (kd.key == MLX_KEY_H && kd.action == MLX_PRESS) if (kd.key == MLX_KEY_H && kd.action == MLX_PRESS)
ft_putendl("H is pressed"); ft_putendl("H is pressed");
if (kd.modifier == MLX_SHIFT)
vl->run = 2;
else
vl->run = 1;
} }
void scrollhook(double xdelta, double ydelta, void *param) void scrollhook(double xdelta, double ydelta, void *param)

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */ /* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
/* Updated: 2023/10/29 12:26:20 by houtworm ######## odam.nl */ /* Updated: 2023/10/29 15:56:15 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ void ft_frametime(t_varlist *vl)
vl->frametime = vl->mlx->delta_time; vl->frametime = vl->mlx->delta_time;
ft_putnbr(1 / vl->frametime); ft_putnbr(1 / vl->frametime);
ft_putendl(" FPS"); ft_putendl(" FPS");
vl->movespeed = vl->frametime * 5.0; vl->movespeed = vl->frametime * 3.0;
vl->rotspeed = vl->frametime * 3.0; vl->rotspeed = vl->frametime * 3.0;
} }

View File

@ -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:59:47 by houtworm ######## odam.nl */ /* Updated: 2023/10/29 15:23:13 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -61,6 +61,8 @@ char **ft_getmap(t_varlist *vl, int fd)
ret = 1; ret = 1;
while (y <= 512 && ret > 0) while (y <= 512 && ret > 0)
{ {
if (y > 500)
return (NULL);
map[y] = ft_calloc(512, 8); map[y] = ft_calloc(512, 8);
while (ret > 0) while (ret > 0)
{ {
@ -70,22 +72,15 @@ char **ft_getmap(t_varlist *vl, int fd)
} }
if (ret == 0) if (ret == 0)
{ {
map[y] = NULL; free(map[y]);
int i;
i = 0;
while (i < y)
{
printf("%s\n", map[i]);
i++;
}
free(line); free(line);
printf("xpos: %lf ypos %lf xdir %lf ydir %lf\n\n", vl->posy, vl->posx, vl->dirx, vl->diry);
return (map); return (map);
} }
printf("line: %s\n", line);
x = 0; x = 0;
while (x <= 512 && line[x]) while (x <= 512 && line[x])
{ {
if (x > 500)
return (NULL);
if (ft_strchr(" 0", line[x])) if (ft_strchr(" 0", line[x]))
map[y][x] = '0'; map[y][x] = '0';
else if (ft_strchr("1", line[x])) else if (ft_strchr("1", line[x]))
@ -97,8 +92,6 @@ char **ft_getmap(t_varlist *vl, int fd)
free(line); free(line);
y++; y++;
} }
free(line); ft_errorexit("Something went wrong", "ft_getmap", 1);
if (x > 500 || y > 500) return (0);
return (NULL);
return (map);
} }

View File

@ -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 14:33:27 by houtworm ######## odam.nl */ /* Updated: 2023/10/29 15:14:40 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -129,7 +129,10 @@ t_varlist ft_parseconfigfile(t_varlist vl, char *filename)
if (error) if (error)
ft_errorexit("Double config declaration in .cub file", error, 1); ft_errorexit("Double config declaration in .cub file", error, 1);
if (vl.ccolor && vl.fcolor && vl.northwt && vl.eastwt && vl.southwt && vl.westwt) if (vl.ccolor && vl.fcolor && vl.northwt && vl.eastwt && vl.southwt && vl.westwt)
{
vl.map = ft_getmap(&vl, fd); vl.map = ft_getmap(&vl, fd);
break ;
}
free(line); free(line);
} }
close(fd); close(fd);