player can run now:)
This commit is contained in:
parent
9472c212c1
commit
0148ee755e
4
Makefile
4
Makefile
@ -6,13 +6,13 @@
|
||||
# By: houtworm <codam@houtworm.net> +#+ #
|
||||
# +#+ #
|
||||
# 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
|
||||
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
|
||||
RM =rm -rf
|
||||
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
|
||||
|
12
config.cub
12
config.cub
@ -1,10 +1,10 @@
|
||||
C 0,100,255
|
||||
F 100,100,100
|
||||
|
||||
NO ./path_to_the_north_texture
|
||||
EA ./path_to_the_east_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
NO ./assets/bluestone.png
|
||||
EA ./assets/colorstone.png
|
||||
SO ./assets/redbrick.png
|
||||
WE ./assets/wood.png
|
||||
|
||||
111111111111111111111111
|
||||
100000000000000000000001
|
||||
@ -26,7 +26,7 @@ WE ./path_to_the_west_texture
|
||||
110100001000000000000001
|
||||
110000101000000000000001
|
||||
110100001000000000000001
|
||||
110111111000000000000001
|
||||
11011111100000000000N001
|
||||
110000000000000000000001
|
||||
1111111110000000000000N1
|
||||
111111111000000000000001
|
||||
111111111111111111111111
|
||||
|
3
cub3d.h
3
cub3d.h
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 hit;
|
||||
int side;
|
||||
double run;
|
||||
double oldmouseposx;
|
||||
double oldmouseposy; // only needed if we do vertical aiming
|
||||
int32_t fcolor;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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.southwt = NULL;
|
||||
vl.westwt = NULL;
|
||||
vl.planex = 0;
|
||||
vl.planey = 0.66;
|
||||
vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true);
|
||||
if (!vl.mlx)
|
||||
ft_errorexit("MLX failed to init", "initvarlist", 1);
|
||||
|
38
src/keys.c
38
src/keys.c
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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')
|
||||
{
|
||||
vl->posx += vl->dirx * vl->movespeed;
|
||||
vl->posy += vl->diry * vl->movespeed;
|
||||
vl->posx += vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy += vl->diry * vl->movespeed * vl->run;
|
||||
}
|
||||
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;
|
||||
vl->posx += vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy += vl->diry * vl->movespeed * vl->run;
|
||||
}
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_A))
|
||||
{
|
||||
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;
|
||||
vl->posx -= vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy += vl->dirx * vl->movespeed * vl->run;
|
||||
}
|
||||
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;
|
||||
vl->posx -= vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy += vl->dirx * vl->movespeed * vl->run;
|
||||
}
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_S))
|
||||
{
|
||||
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;
|
||||
vl->posx -= vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->diry * vl->movespeed * vl->run;
|
||||
}
|
||||
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;
|
||||
vl->posx -= vl->dirx * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->diry * vl->movespeed * vl->run;
|
||||
}
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_D))
|
||||
{
|
||||
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;
|
||||
vl->posx += vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->dirx * vl->movespeed * vl->run;
|
||||
}
|
||||
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;
|
||||
vl->posx += vl->diry * vl->movespeed * vl->run;
|
||||
vl->posy -= vl->dirx * vl->movespeed * vl->run;
|
||||
}
|
||||
}
|
||||
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)
|
||||
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)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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;
|
||||
ft_putnbr(1 / vl->frametime);
|
||||
ft_putendl(" FPS");
|
||||
vl->movespeed = vl->frametime * 5.0;
|
||||
vl->movespeed = vl->frametime * 3.0;
|
||||
vl->rotspeed = vl->frametime * 3.0;
|
||||
}
|
||||
|
||||
|
23
src/map.c
23
src/map.c
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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;
|
||||
while (y <= 512 && ret > 0)
|
||||
{
|
||||
if (y > 500)
|
||||
return (NULL);
|
||||
map[y] = ft_calloc(512, 8);
|
||||
while (ret > 0)
|
||||
{
|
||||
@ -70,22 +72,15 @@ char **ft_getmap(t_varlist *vl, int fd)
|
||||
}
|
||||
if (ret == 0)
|
||||
{
|
||||
map[y] = NULL;
|
||||
int i;
|
||||
i = 0;
|
||||
while (i < y)
|
||||
{
|
||||
printf("%s\n", map[i]);
|
||||
i++;
|
||||
}
|
||||
free(map[y]);
|
||||
free(line);
|
||||
printf("xpos: %lf ypos %lf xdir %lf ydir %lf\n\n", vl->posy, vl->posx, vl->dirx, vl->diry);
|
||||
return (map);
|
||||
}
|
||||
printf("line: %s\n", line);
|
||||
x = 0;
|
||||
while (x <= 512 && line[x])
|
||||
{
|
||||
if (x > 500)
|
||||
return (NULL);
|
||||
if (ft_strchr(" 0", line[x]))
|
||||
map[y][x] = '0';
|
||||
else if (ft_strchr("1", line[x]))
|
||||
@ -97,8 +92,6 @@ char **ft_getmap(t_varlist *vl, int fd)
|
||||
free(line);
|
||||
y++;
|
||||
}
|
||||
free(line);
|
||||
if (x > 500 || y > 500)
|
||||
return (NULL);
|
||||
return (map);
|
||||
ft_errorexit("Something went wrong", "ft_getmap", 1);
|
||||
return (0);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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)
|
||||
ft_errorexit("Double config declaration in .cub file", error, 1);
|
||||
if (vl.ccolor && vl.fcolor && vl.northwt && vl.eastwt && vl.southwt && vl.westwt)
|
||||
{
|
||||
vl.map = ft_getmap(&vl, fd);
|
||||
break ;
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
close(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user