Browse Source

working gnl

master
narnaud 3 years ago
parent
commit
249035e506
  1. 10
      Makefile
  2. 13
      includes/cub3d.h
  3. 116
      includes/mlx_keycode.h
  4. 11
      maps/inv.cub
  5. 22
      maps/inv2.cub
  6. 22
      maps/map.cub
  7. 20
      maps/sqr.cub
  8. 22
      sources/main.c
  9. 49
      sources/utils/getline.c

10
Makefile

@ -1,8 +1,8 @@
NAME = cub3d
LIBFT = libft.a
SRCS = sources/cub3d.c
OBJS = $(SRCS:.c=.o)
SRCS = sources/main.c sources/utils/getline.c
OBJS = ${SRCS:.c=.o}
CC = gcc
RM = rm -rf
@ -29,9 +29,9 @@ $(LIBFT):
all: $(NAME)
$(NAME): $(LIBFT) $(OBJS)
@echo "Making Cub3D."
@${CC} -g ${OBJS} -o ${NAME} ${LFLAGS}
@echo "Done."
@echo "Making Cub3D."
@${CC} -g ${OBJS} -o ${NAME} ${LFLAGS}
@echo "Done."
clean:
@echo "Cleaning objects."

13
includes/cub3d.h

@ -6,13 +6,14 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */
/* Updated: 2022/05/22 14:10:24 by narnaud ### ########.fr */
/* Updated: 2022/05/23 10:44:57 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# define BUFFER_SIZE 4096
# define UNIT 100
# define WALL_HEIGHT 200
# define PLAYER_HEIGHT 170
@ -22,7 +23,7 @@
# include <stdio.h>
# include <fcntl.h>
# include <errno.h>
# include <sting.h>
# include <string.h>
# include <math.h>
# include "../includes/libft.h"
# ifdef __linux__
@ -36,9 +37,15 @@ typedef struct s_vector
{
int x;
int y;
int z;
} t_vec;
typedef struct s_map
{
size_t wide;
size_t deep;
char **map;
} t_map;
char *get_next_line(int fd);
#endif

116
includes/mlx_keycode.h

@ -0,0 +1,116 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx_keycode.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bledda <bledda@student.42nice.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/10 20:43:21 by bledda #+# #+# */
/* Updated: 2022/05/23 09:42:56 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MLX_KEYCODE_H
# define MLX_KEYCODE_H
# ifdef __linux__
# define KEY_Q 113
# define KEY_W 119
# define KEY_E 101
# define KEY_R 114
# define KEY_T 116
# define KEY_Y 121
# define KEY_U 117
# define KEY_I 105
# define KEY_O 111
# define KEY_P 112
# define KEY_A 97
# define KEY_S 115
# define KEY_D 100
# define KEY_F 102
# define KEY_G 103
# define KEY_H 104
# define KEY_J 106
# define KEY_K 107
# define KEY_L 108
# define KEY_Z 122
# define KEY_X 120
# define KEY_C 99
# define KEY_V 118
# define KEY_B 98
# define KEY_N 110
# define KEY_M 109
# define KEY_ECHAP 65307
# define KEY_ENTER 65293
# define KEY_ARROW_LEFT 65361
# define KEY_ARROW_RIGHT 65363
# define KEY_ARROW_DOWN 65364
# define KEY_ARROW_UP 65362
# define KEY_DELETE 65288
# define KEY_0 48
# define KEY_1 49
# define KEY_2 50
# define KEY_3 51
# define KEY_4 52
# define KEY_5 53
# define KEY_6 54
# define KEY_7 55
# define KEY_8 56
# define KEY_9 57
# define KEY_TAB 65289
# define KEY_MAJ 65509
# define KEY_SHFT 65505
# define KEY_CTRL 65507
# define KEY_SPACE 32
# elif __APPLE__
# define KEY_Q 12
# define KEY_W 13
# define KEY_E 14
# define KEY_R 15
# define KEY_T 17
# define KEY_Y 16
# define KEY_U 32
# define KEY_I 34
# define KEY_O 31
# define KEY_P 35
# define KEY_A 0
# define KEY_S 1
# define KEY_D 2
# define KEY_F 3
# define KEY_G 5
# define KEY_H 4
# define KEY_J 38
# define KEY_K 40
# define KEY_L 37
# define KEY_Z 6
# define KEY_X 7
# define KEY_C 8
# define KEY_V 9
# define KEY_B 11
# define KEY_N 45
# define KEY_M 46
# define KEY_ECHAP 53
# define KEY_ENTER 36
# define KEY_ARROW_LEFT 123
# define KEY_ARROW_RIGHT 124
# define KEY_ARROW_DOWN 125
# define KEY_ARROW_UP 126
# define KEY_DELETE 51
# define KEY_0 29
# define KEY_1 18
# define KEY_2 19
# define KEY_3 20
# define KEY_4 21
# define KEY_5 23
# define KEY_6 22
# define KEY_7 26
# define KEY_8 28
# define KEY_9 25
# define KEY_TAB 48
# define KEY_MAJ 272
# define KEY_SHFT 257
# define KEY_CTRL 256
# define KEY_SPACE 49
# endif
#endif

11
maps/inv.cub

@ -0,0 +1,11 @@
NO ./textures/brick.xpm
SO ./textures/blue.xpm
WE ./textures/wood.xpm
EA ./textures/grey.xpm
F 100,0,100
C 0,0,0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 W 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

22
maps/inv2.cub

@ -0,0 +1,22 @@
NO ./textures/brick.xpm
SO ./textures/blue.xpm
WE ./textures/wood.xpm
EA ./textures/grey.xpm
F 224,172,105
C 205,249,255
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1
1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 W 0 1 0 0 0 0 1
1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1
1 1 1 1 0 1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0 0 0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1
1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1
1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

20
maps/sqr.cub

@ -0,0 +1,20 @@
NO ./textures/brick.xpm
SO ./textures/blue.xpm
WE ./textures/wood.xpm
EA ./textures/grey.xpm
F 224,172,105
C 205,249,255
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 N 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

22
sources/main.c

@ -6,29 +6,35 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */
/* Updated: 2022/05/22 22:34:44 by narnaud ### ########.fr */
/* Updated: 2022/05/23 09:54:53 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "../includes/cub3d.h"
t_map *parse_map(char *map_filename)
t_map parse_map(char *map_filename)
{
static t_map ret;
int fd;
char *file_line;
t_map *ret;
fd = open(map_filenamem, O_RDONLY);
fd = open(map_filename, O_RDONLY);
file_line = get_next_line(fd);
ret = ft_calloc(sizeof(t_map));
while (file_line)
{
ret.deep++;
printf("%s", file_line);
free(file_line);
file_line = get_next_line(fd);
}
return (ret);
}
int main(int argc, char **argv)
{
t_map *map;
t_map map;
(void)argc;
map = parse_map(argv[1]);
return (EXIT_SUCCESS);

49
sources/utils/getline.c

@ -9,43 +9,58 @@
/* */
/* ************************************************************************** */
#include "../../includes/libft.h"
#include "../../includes/cub3d.h"
char *save_buffer(char *buffer, int *i)
{
int j;
int j;
char *part1;
char *part2;
char *ret;
line = ft_calloc(512);
part1 = ft_calloc(512, sizeof(char));
j = 0;
while (j < 512)
while (j < 512 && buffer[*i])
{
line[j++] = buffer[(*i)++];
if (buffer[*i] == '\n')
return (line)
part1[j++] = buffer[*i];
if (buffer[(*i)++] == '\n')
return (part1);
}
return (ft_strjoin(line, save_buffer(buffer, i)));
part2 = save_buffer(buffer, i);
ret = ft_strjoin(part1, part2);
free(part1);
free(part2);
return (ret);
}
char *get_next_line(int fd)
{
static char *buffer[BUFFER_SIZE];
static char buffer[BUFFER_SIZE + 1];
static int i;
ssize_t read_size;
char *line;
char *ret;
if (!*buffer)
{
read_size = read(fd, buffer, BUFFER_SIZE);
line = ft_calloc(1);
while (read_size)
buffer[read_size] = 0;
}
ret = ft_calloc(1, sizeof(char));
while (buffer[i])
{
line = ft_strjoin(line, save_buffer(buffer, i));
if (line[i] == '\n')
return (line);
line = ft_strjoin(ret, save_buffer(buffer, &i));
free(ret);
ret = line;
if (buffer[i - 1] == '\n')
break ;
read_size = read(fd, buffer, BUFFER_SIZE);
buffer[read_size] = 0;
i = 0;
}
if (*line)
return (line);
free(line);
if (*ret)
return (ret);
free(ret);
return (NULL);
}

Loading…
Cancel
Save