This commit is contained in:
Camille Chauvet 2023-01-19 13:41:58 +01:00
parent 7d7de10b7a
commit 8b200fb8ba
15 changed files with 164 additions and 41 deletions

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
/* Updated: 2023/01/13 16:03:54 by cchauvet ### ########.fr */
/* Updated: 2023/01/19 13:32:14 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,12 +30,35 @@ static void *ft_gen_asset(char *color, size_t case_size, t_data *data)
return (img);
}
static char **ft_color_gen(void)
{
size_t i;
char **tab;
tab = ft_calloc(NB_COLORS + 1, sizeof(char *));
if (tab == NULL)
return (NULL);
i = 0;
while (i < NB_COLORS)
{
tab[i] = ft_ultoa_base(((1 << 23) * i) / NB_COLORS, HEX);
if (tab[i] == NULL)
{
ft_cancel(tab, i);
return (NULL);
}
i++;
}
tab[i] = NULL;
return (tab);
}
int ft_gen_assets(t_data *data)
{
char **colors;
size_t i;
colors = ft_split(COLORS, '|');
colors = ft_color_gen();
if (colors == NULL)
return (1);
i = 0;
@ -43,9 +66,14 @@ int ft_gen_assets(t_data *data)
{
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
if (data->assets[i] == NULL)
{
ft_freer_tab_ultimate(1, colors);
return (1);
}
data->assets[i + NB_COLORS] = ft_gen_asset(colors[i],
WINDOW_SIZE, data);
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, data);
if (data->assets[i + NB_COLORS] == NULL)
ft_freer_tab_ultimate(1, colors);
if (data->assets[i + NB_COLORS] == NULL)
return (1);
i++;

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
/* Updated: 2023/01/16 18:46:55 by cchauvet ### ########.fr */
/* Updated: 2023/01/19 13:39:23 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -56,11 +56,12 @@ int ft_draw_map(t_data *data)
void *img;
ft_fill_pos(data->map);
data->nb_swaps = ++data->nb_swaps % NB_COLORS;
data->nb_swaps = ft_random_generator(0, NB_COLORS - 6);
patern = ft_get_player_map(*data->map);
if (patern == NULL)
return (1);
ft_draw_img(data, data->assets[data->nb_swaps + NB_COLORS], 0, 0);
ft_draw_img(data, data->assets[data->nb_swaps % NB_COLORS + NB_COLORS], 0,
0);
tab[1] = -1;
while (patern[++tab[1]] != NULL)
{

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
/* Updated: 2023/01/16 18:47:20 by cchauvet ### ########.fr */
/* Updated: 2023/01/19 13:30:11 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,12 +24,15 @@ int ft_initialised(char *path, t_data *data)
}
data->mlx = mlx_init();
ft_printf("Generating assets ...");
ft_gen_assets(data);
if (ft_gen_assets(data))
ft_exit(data);
ft_printf("\rGenerating assets [FINISHED]\n");
data->map = map;
data->window = mlx_new_window(data->mlx, WINDOW_SIZE, WINDOW_SIZE, "long");
data->window = mlx_new_window(data->mlx,
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE,
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, "long");
data->nb_foots = 0;
data->nb_swaps = ft_random_generator(0, NB_COLORS);
data->nb_swaps = ft_random_generator(0, NB_COLORS - 6);
ft_draw_map(data);
mlx_hook(data->window, 17, (0L), ft_exit, data);
mlx_hook(data->window, 2, (1L << 0), ft_key, data);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
/* Updated: 2023/01/16 18:47:59 by cchauvet ### ########.fr */
/* Updated: 2023/01/19 13:40:52 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,20 +17,19 @@
# include <unistd.h>
# include <fcntl.h>
# include "../minilibx-linux/mlx.h"
# define CASE_SIZE 64
# define CASE_SIZE 128
# define XPM_HEADER "\nstatic char * XFACE[] = {\""
# define COLORS "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 NB_COLORS 93
# define RENDER_DISTANCE 5
# define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE
# define RENDER_DISTANCE 4
# define NB_COLORS 100
# define HEX "0123456789abcdef"
typedef struct s_square
typedef struct s_square
{
char *color;
size_t size;
} t_square;
} t_square;
typedef struct s_map
typedef struct s_map
{
size_t x_len;
size_t y_len;
@ -38,9 +37,9 @@ typedef struct s_map
char **patern;
size_t player_pos[2];
size_t exit_pos[2];
} t_map;
} t_map;
typedef struct s_data
typedef struct s_data
{
void *mlx;
void *window;
@ -48,7 +47,7 @@ typedef struct s_data
t_map *map;
size_t nb_swaps;
size_t nb_foots;
} t_data;
} t_data;
int ft_test_map_is_finishable(t_map *map);
int ft_exit(t_data *data);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 13:53:03 by cchauvet #+# #+# */
/* Updated: 2023/01/11 16:53:45 by cchauvet ### ########.fr */
/* Updated: 2023/01/19 12:34:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -74,7 +74,7 @@ static char *ft_gen_xpm_content(t_square square)
free(temp);
if (content == NULL)
return (NULL);
temp = ft_strmerger(5, "/* XPM */", content, "a c ", square.color, "\",\n");
temp = ft_strmerger(5, "/* XPM */", content, "a c #", square.color, "\",\n");
free(content);
if (temp == NULL)
return (NULL);

View File

@ -6,13 +6,13 @@
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
# Updated: 2023/01/12 16:31:55 by cchauvet ### ########.fr #
# Updated: 2023/01/19 12:55:43 by cchauvet ### ########.fr #
# #
# **************************************************************************** #
CC = clang
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c
OBJS = $(SRCS:.c=.o)

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
/* Updated: 2023/01/12 16:32:35 by cchauvet ### ########.fr */
/* Updated: 2023/01/18 19:21:29 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@
# include <fcntl.h>
# include "../libft/libft.h"
char *ft_ultoa_base(unsigned long long n, char *base);
char *get_next_line(int fd);
size_t ft_random_generator(size_t start, size_t stop);
void ft_freer_tab_ultimate(size_t len, ...);

BIN
libftx/extra/ft_ultoa.o Normal file

Binary file not shown.

View File

@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultoa_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 13:49:45 by cchauvet #+# #+# */
/* Updated: 2023/01/19 13:01:09 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
static size_t ft_str_size(unsigned long long n, size_t base_size)
{
size_t size;
size = 1;
if (n == 0)
return (2);
while (n != 0)
{
n = n / base_size;
size++;
}
return (size);
}
static int ft_isdup(char *str)
{
char c;
size_t i;
while (*str != 0)
{
c = *str;
i = 1;
while (str[i] != 0)
{
if (str[i] == c)
return (1);
i++;
}
str++;
}
return (0);
}
static size_t ft_base_size(char *base)
{
size_t len;
if (ft_isdup(base))
return (0);
len = ft_strlen(base);
if (len < 2)
return (0);
return (len);
}
char *ft_ultoa_base(unsigned long long n, char *base)
{
size_t base_size;
int str_size;
char *out;
size_t i;
if (base == NULL)
return (NULL);
base_size = ft_base_size(base);
if (base_size == 0)
return (NULL);
str_size = ft_str_size(n, base_size);
out = ft_calloc(str_size + 1, sizeof(char));
if (out == NULL)
return (NULL);
i = 0;
if (n == 0)
out[0] = base[0];
while (n != 0)
{
out[str_size - 2 - i] = base[n % base_size];
n /= base_size;
i++;
}
out[str_size - 1] = '\0';
return (out);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/01/12 16:33:45 by cchauvet ### ########.fr */
/* Updated: 2023/01/18 19:21:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,7 @@
# include <unistd.h>
# include <stdarg.h>
char *ft_ultoa_base(unsigned long long n, char *base);
int ft_printf(const char *format, ...);
char *get_next_line(int fd);
size_t ft_random_generator(size_t start, size_t stop);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
/* Updated: 2023/01/16 18:27:18 by cchauvet ### ########.fr */
/* Updated: 2023/01/18 17:32:05 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -47,7 +47,7 @@ int ft_gen_assets(t_data *data)
i++;
}
data->assets[NB_COLORS] = ft_gen_asset(colors[i],
WINDOW_SIZE, data);
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, data);
if (data->assets[NB_COLORS] == NULL)
return (1);
ft_freer_tab_ultimate(1, colors);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
/* Updated: 2023/01/16 18:23:34 by cchauvet ### ########.fr */
/* Updated: 2023/01/18 17:31:16 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,7 +31,9 @@ int ft_initialised(char *path, t_data *data)
}
ft_printf("\rGenerating assets [FINISHED]\n");
data->map = map;
data->window = mlx_new_window(data->mlx, WINDOW_SIZE, WINDOW_SIZE, "long");
data->window = mlx_new_window(data->mlx,
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE,
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, "long");
ft_draw_map(data);
mlx_hook(data->window, 17, (0L), ft_exit, data);
mlx_hook(data->window, 2, (1L << 0), ft_key, data);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
/* Updated: 2023/01/16 18:36:30 by cchauvet ### ########.fr */
/* Updated: 2023/01/18 17:29:43 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,15 +22,14 @@
# define COLORS "gold|white|pink|red|gray"
# define NB_COLORS 4
# define RENDER_DISTANCE 5
# define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE
typedef struct s_square
typedef struct s_square
{
char *color;
size_t size;
} t_square;
} t_square;
typedef struct s_map
typedef struct s_map
{
size_t x_len;
size_t y_len;
@ -38,15 +37,15 @@ typedef struct s_map
char **patern;
size_t player_pos[2];
size_t exit_pos[2];
} t_map;
} t_map;
typedef struct s_data
typedef struct s_data
{
void *mlx;
void *window;
void *assets[NB_COLORS + 1];
t_map *map;
} t_data;
} t_data;
//void ft_ultimate_image_destroyer(t_data *data);
int ft_test_map_is_finishable(t_map *map);

View File

@ -1,5 +1,5 @@
1111111111111
10010000000C1
1000011111001
1000011111B01
1P0011E0000C1
1111111111111