diff --git a/Makefile b/Makefile index ad5b931..b8ac58e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SRCS = draw.c main.c map.c shape.c xpm.c +SRCS = asset.c draw.c main.c map.c parsing.c shape.c xpm.c OBJ = ${SRCS:.c=.o} diff --git a/asset.c b/asset.c new file mode 100644 index 0000000..0439501 --- /dev/null +++ b/asset.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* asset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet # include +void *ft_cancel(char **tab, size_t len); int ft_atoi(const char *nptr); void ft_bzero(void *s, size_t n); void *ft_calloc(size_t nmemb, size_t size); diff --git a/libftx/libftx.a b/libftx/libftx.a new file mode 100644 index 0000000..e977f77 Binary files /dev/null and b/libftx/libftx.a differ diff --git a/libftx/libftx.h b/libftx/libftx.h index 79c7dca..d3f01a4 100644 --- a/libftx/libftx.h +++ b/libftx/libftx.h @@ -6,7 +6,7 @@ /* By: cchauvet patern = ft_readfile(path); + if (ft_map_is_correct(map) == 0) + return (NULL); + return (map); +} + +char **ft_get_player_map(t_map map) +{ + char **player_map; + ssize_t y; + ssize_t i; + + player_map = malloc(RENDER_DISTANCE * 2 + 2); + if (player_map == NULL) + return (NULL); + y = -RENDER_DISTANCE; + while (y < map.y_len - map.player_pos[1] - RENDER_DISTANCE) + { + i = map.player_pos[1] + y; + player_map[y] = ft_strndup(map.patern[i], RENDER_DISTANCE * 2 + 1); + if (player_map[y] == NULL) + { + ft_cancel(player_map, RENDER_DISTANCE - y); + return (NULL); + } + y++; + } + player_map[y] = NULL; + return (player_map); +} + + diff --git a/map.o b/map.o index b72b3bc..3b13760 100644 Binary files a/map.o and b/map.o differ diff --git a/maps/map_big.ber b/maps/map_big.ber new file mode 100644 index 0000000..d6e9426 --- /dev/null +++ b/maps/map_big.ber @@ -0,0 +1,35 @@ +1111111111111111111111111111111111111111111111 +1P0C000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1C00000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1011111111111111111111111111111111111111111101 +1000000000000000000000000000000000000000000001 +1111000000000000000000000000000000000000001111 +1000000000000000000000000000000000000000000001 +100000000000000000000000000000000E000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1000000000000000000000000000000000000000000001 +1111111111111111111111111111111111111111111111 diff --git a/maps/map_test.ber b/maps/map_test.ber new file mode 100644 index 0000000..4f3015c --- /dev/null +++ b/maps/map_test.ber @@ -0,0 +1,5 @@ +1111111111111 +10010000000C1 +1000011111001 +1P0011E0000C1 +1111111111111 diff --git a/maps/map_test2.ber b/maps/map_test2.ber new file mode 100644 index 0000000..1bb91f5 --- /dev/null +++ b/maps/map_test2.ber @@ -0,0 +1,6 @@ +1111111111111111111111111111111111 +1E0000000000000C00000C000000000001 +1010010100100000101001000000010101 +1010010010101010001001000000010101 +1P0000000C00C0000000000000000000C1 +1111111111111111111111111111111111 diff --git a/maps/map_test3.ber b/maps/map_test3.ber new file mode 100644 index 0000000..2171504 --- /dev/null +++ b/maps/map_test3.ber @@ -0,0 +1,8 @@ +111111111111111111111111111111111 +1P1C000000010101010C100C001000001 +10101101110001C00000100C001011101 +10101000C10101110100101110101C101 +10C00001010000C00100001C101010101 +111111110101010101111010101010101 +1E0000000100C001000C1C10000010001 +111111111111111111111111111111111 diff --git a/maps/not_minimun.ber b/maps/not_minimun.ber new file mode 100644 index 0000000..86fc037 --- /dev/null +++ b/maps/not_minimun.ber @@ -0,0 +1,3 @@ +11111 +10CE1 +11111 diff --git a/maps/not_possible.ber b/maps/not_possible.ber new file mode 100644 index 0000000..2fb3e33 --- /dev/null +++ b/maps/not_possible.ber @@ -0,0 +1,5 @@ +1111111111111 +1P1C010110001 +1011100010101 +10000010001E1 +1111111111111 diff --git a/maps/not_rectangular.ber b/maps/not_rectangular.ber new file mode 100644 index 0000000..9d7781c --- /dev/null +++ b/maps/not_rectangular.ber @@ -0,0 +1,4 @@ +11111 +1P01 +10CE1 +11111 diff --git a/maps/not_surrounded.ber b/maps/not_surrounded.ber new file mode 100644 index 0000000..051dcac --- /dev/null +++ b/maps/not_surrounded.ber @@ -0,0 +1,4 @@ +11111 +1PCE1 +10001 +1111E diff --git a/parsing.c b/parsing.c new file mode 100644 index 0000000..8acda88 --- /dev/null +++ b/parsing.c @@ -0,0 +1,104 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsing.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet patern[0]); + i = 1; + while (map->patern[i] != NULL) + { + if (ft_strlen(map->patern[i]) != len) + return (0); + i++; + } + map->x_len = len; + map->y_len = i; + return (1); +} + +int ft_test_map_content1(t_map *map) +{ + size_t x; + size_t y; + size_t nb_collectable; + + nb_collectable = 0; + y = 0; + while (y < map->y_len) + { + x = 0; + while (x < map->x_len) + { + if (ft_is_in("01CEP", map->patern[y][x]) == 0) + return (0); + if (map->patern[y][x] == 'C') + nb_collectable++; + x++; + } + y++; + } + if (nb_collectable == 0) + return (0); + map->nb_collectable = nb_collectable; + return (1); +} + +int ft_test_map_content2(t_map *map) +{ + ssize_t cord[2]; + + cord[1] = -1; + while ((size_t) ++cord[1] < map->y_len) + { + cord[0] = -1; + while ((size_t) ++cord[0] < map->x_len) + { + if (map->patern[cord[1]][cord[0]] == 'E') + { + map->exit[0] = cord[0]; + map->exit[1] = cord[1]; + map->exit[2]++; + } + else if (map->patern[cord[1]][cord[0]] == 'P') + { + map->player_pos[0] = cord[0]; + map->player_pos[1] = cord[1]; + map->player_pos[2]++; + } + } + } + if (map->player_pos[2] == 1 && map->exit[2] == 1) + return (1); + return (0); +} + +int ft_test_map_is_finishable(t_map map) +{ + (void) map; + return (1); +} + +int ft_map_is_correct(t_map *map) +{ + int i; + + i = ft_test_map_content1(map); + i += ft_test_map_content2(map); + i += ft_test_map_dimmention(map); + i += ft_test_map_is_finishable(*map); + return (i == 4); +} diff --git a/parsing.o b/parsing.o new file mode 100644 index 0000000..0a212d5 Binary files /dev/null and b/parsing.o differ diff --git a/shape.c b/shape.c index 1097221..a1945c0 100644 --- a/shape.c +++ b/shape.c @@ -6,7 +6,7 @@ /* By: cchauvet # include # include "minilibx-linux/mlx.h" +# define CASE_SIZE 64 +# define XPM_HEADER "\nstatic char * XFACE[] = {\"" +# define COLORS "black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua|aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen" +# define BACKGROUND_COLOR "black" +# define SHAPES "square" +# define RENDER_DISTANCE 5 +# define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE typedef struct s_shape { char *color; char *bcolor; char *shape; size_t size; - size_t x; - size_t y; } t_shape; + +typedef struct s_map +{ + size_t x_len; + size_t y_len; + size_t nb_collectable; + char **patern; + size_t player_pos[3]; + size_t exit[3]; +} t_map; + +typedef struct s_data +{ + void *mlx; + void *window; + char *bcolor; + char *pcolor; + char *ccolor; + char *wcolor; + size_t size; +} t_data; + +t_map *ft_getmap(char *path); void ft_draw_xpm(void *mlx, void *window, char *file, size_t *cord); void ft_draw_square(void *window_manager, void *window, t_shape shape); -char *xpm_square_generator(t_shape); +char *xpm_square_generator(t_shape); char *ft_gen_xpm_file(t_shape); char *ft_square(char c, size_t x_len, size_t y_len); char *ft_triangle(char c, char b, size_t x_len, size_t y_len); char *ft_xpm_gen_file(t_shape shape); char **ft_readfile(char *path); +int ft_map_is_correct(t_map *map); +int ft_gen_assets(void); +char **ft_get_player_map(t_map map); #endif diff --git a/t b/t new file mode 100644 index 0000000..32f64f4 --- /dev/null +++ b/t @@ -0,0 +1 @@ +t \ No newline at end of file diff --git a/textures/square_yellow_25x25.xpm b/textures/square_yellow_25x25.xpm deleted file mode 100644 index 5324a6a..0000000 --- a/textures/square_yellow_25x25.xpm +++ /dev/null @@ -1,30 +0,0 @@ -/* XPM */ -static char * XFACE[] = {" -25 25 2 1", -"a c yellow", -"b c black", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa", -"aaaaaaaaaaaaaaaaaaaaaaaaa"}; \ No newline at end of file diff --git a/xpm.c b/xpm.c index c12b6c5..ad8857e 100644 --- a/xpm.c +++ b/xpm.c @@ -6,7 +6,7 @@ /* By: cchauvet