diff --git a/Makefile b/Makefile index 8eba674..b5d1fe0 100644 --- a/Makefile +++ b/Makefile @@ -11,43 +11,38 @@ # **************************************************************************** # NAME = yochered.filler +LIBFT = libft.a +VISUAL = visu_filler -SRC = $(addprefix $(SRCDIR), main.c additional_funcs.c algorithm.c fill_map_layout.c get_description.c) +SRC = main.c additional_funcs.c algorithm.c fill_map_layout.c get_description.c +VISUAL_SRC = visu.c windows_funcs.c parse.c print.c -VISUAL_SRC = $(addprefix $(VISUAL_DIR), visu.c windows_funcs.c parse.c print.c) +VISUAL_OBJ = $(VISUAL_SRC:.c=.o) +OBJ = $(SRC:.c=.o) VISUAL_DIR = ./visu/ - -VISUAL_OBJ = $(VISUAL_SRC:.c =.o) - +OBJ_DIR = ./obj/ SRCDIR = ./src/ -OBJ = $(SRC:.c=.o) - -LIBFT = libft.a - -VISUAL = show_filler - all: $(NAME) -$(NAME): $(OBJ) $(LIBFT) - gcc -o $(NAME) $(SRC) -L ./libft/ -lft -I ./includes/ +$(NAME): $(LIBFT) $(addprefix $(OBJ_DIR), $(OBJ)) + gcc -o $(NAME) $(addprefix $(OBJ_DIR), $(OBJ)) -L ./libft/ -lft -I ./includes/ -filler: $(VISUAL_OBJ) $(LIBFT) - gcc -o visu_filler $(VISUAL_OBJ) -L ./libft/ -lft -I /usr/local/include -lmlx -framework OpenGL -framework AppKit +filler: $(LIBFT) $(addprefix $(OBJ_DIR), $(VISUAL_OBJ)) + gcc -o $(VISUAL) $(addprefix $(OBJ_DIR), $(VISUAL_OBJ)) -L ./libft/ -lft -I /usr/local/include -lmlx -framework OpenGL -framework AppKit -$(addprefix $(SRCDIR), %.o): $(addprefix $(SRCDIR), %.c) +$(addprefix $(OBJ_DIR), %.o): $(addprefix $(SRCDIR), %.c) gcc -Wall -W -Werror -c -o $@ $< -I ./includes/ -$(addprefix $(VISUAL_DIR), %.o): $(addprefix $(VISUAL_DIR), %.c) - gcc -Wall -W -Werror -c -o $@ $< +$(addprefix $(OBJ_DIR), %.o): $(addprefix $(VISUAL_DIR), %.c) + gcc -Wall -W -Werror -c -o $@ $< -I ./includes/ $(LIBFT): - @make -C ./libft/ --silent + make -C ./libft/ --silent clean: - /bin/rm -f $(OBJ) - /bin/rm -f visu/*.o + /bin/rm -f $(addprefix $(OBJ_DIR), $(OBJ) $(VISUAL_OBJ)) make -C ./libft/ clean --silent fclean: clean diff --git a/filler.trace b/filler.trace index b2e8b0f..a20fef3 100644 --- a/filler.trace +++ b/filler.trace @@ -1,4 +1,4 @@ -seed = 9889 +seed = 8293 ./yochered.filler won Score: -157AGAINST197 +2AGAINST2039 diff --git a/includes/filler.h b/includes/filler.h index a0d05b8..88d2b21 100644 --- a/includes/filler.h +++ b/includes/filler.h @@ -21,8 +21,6 @@ # define MANHATTAN(x1, x2, y1, y2) ((ABS(x2 - x1)) + ABS((y2 - y1))) # define X 0 # define Y 1 -//Delete -# include typedef struct s_shape { diff --git a/libft/ft_atoi.o b/libft/ft_atoi.o deleted file mode 100644 index aba8b23..0000000 Binary files a/libft/ft_atoi.o and /dev/null differ diff --git a/libft/ft_bzero.o b/libft/ft_bzero.o deleted file mode 100644 index ecc3227..0000000 Binary files a/libft/ft_bzero.o and /dev/null differ diff --git a/libft/ft_count_digits.o b/libft/ft_count_digits.o deleted file mode 100644 index e207462..0000000 Binary files a/libft/ft_count_digits.o and /dev/null differ diff --git a/libft/ft_cycle_detector.o b/libft/ft_cycle_detector.o deleted file mode 100644 index f2f90a5..0000000 Binary files a/libft/ft_cycle_detector.o and /dev/null differ diff --git a/libft/ft_isalnum.o b/libft/ft_isalnum.o deleted file mode 100644 index 79d29e8..0000000 Binary files a/libft/ft_isalnum.o and /dev/null differ diff --git a/libft/ft_isalpha.o b/libft/ft_isalpha.o deleted file mode 100644 index 9f664a6..0000000 Binary files a/libft/ft_isalpha.o and /dev/null differ diff --git a/libft/ft_isascii.o b/libft/ft_isascii.o deleted file mode 100644 index 1598f28..0000000 Binary files a/libft/ft_isascii.o and /dev/null differ diff --git a/libft/ft_isdigit.o b/libft/ft_isdigit.o deleted file mode 100644 index 41bace0..0000000 Binary files a/libft/ft_isdigit.o and /dev/null differ diff --git a/libft/ft_isprint.o b/libft/ft_isprint.o deleted file mode 100644 index b0e1607..0000000 Binary files a/libft/ft_isprint.o and /dev/null differ diff --git a/libft/ft_itoa.o b/libft/ft_itoa.o deleted file mode 100644 index 2f6799f..0000000 Binary files a/libft/ft_itoa.o and /dev/null differ diff --git a/libft/ft_itoa_base.o b/libft/ft_itoa_base.o deleted file mode 100644 index 57ef462..0000000 Binary files a/libft/ft_itoa_base.o and /dev/null differ diff --git a/libft/ft_lstadd.o b/libft/ft_lstadd.o deleted file mode 100644 index 89da30b..0000000 Binary files a/libft/ft_lstadd.o and /dev/null differ diff --git a/libft/ft_lstdel.o b/libft/ft_lstdel.o deleted file mode 100644 index 7eaa965..0000000 Binary files a/libft/ft_lstdel.o and /dev/null differ diff --git a/libft/ft_lstdelone.o b/libft/ft_lstdelone.o deleted file mode 100644 index 8606712..0000000 Binary files a/libft/ft_lstdelone.o and /dev/null differ diff --git a/libft/ft_lstiter.o b/libft/ft_lstiter.o deleted file mode 100644 index 68f5a7d..0000000 Binary files a/libft/ft_lstiter.o and /dev/null differ diff --git a/libft/ft_lstmap.o b/libft/ft_lstmap.o deleted file mode 100644 index 94eabab..0000000 Binary files a/libft/ft_lstmap.o and /dev/null differ diff --git a/libft/ft_lstnew.o b/libft/ft_lstnew.o deleted file mode 100644 index da48e62..0000000 Binary files a/libft/ft_lstnew.o and /dev/null differ diff --git a/libft/ft_lstrev.o b/libft/ft_lstrev.o deleted file mode 100644 index 302fd8a..0000000 Binary files a/libft/ft_lstrev.o and /dev/null differ diff --git a/libft/ft_memalloc.o b/libft/ft_memalloc.o deleted file mode 100644 index aaf008b..0000000 Binary files a/libft/ft_memalloc.o and /dev/null differ diff --git a/libft/ft_memccpy.o b/libft/ft_memccpy.o deleted file mode 100644 index 45ea210..0000000 Binary files a/libft/ft_memccpy.o and /dev/null differ diff --git a/libft/ft_memchr.o b/libft/ft_memchr.o deleted file mode 100644 index 6e71b6b..0000000 Binary files a/libft/ft_memchr.o and /dev/null differ diff --git a/libft/ft_memcmp.o b/libft/ft_memcmp.o deleted file mode 100644 index 1e1150a..0000000 Binary files a/libft/ft_memcmp.o and /dev/null differ diff --git a/libft/ft_memcpy.o b/libft/ft_memcpy.o deleted file mode 100644 index 0359936..0000000 Binary files a/libft/ft_memcpy.o and /dev/null differ diff --git a/libft/ft_memdel.o b/libft/ft_memdel.o deleted file mode 100644 index a7b9cd3..0000000 Binary files a/libft/ft_memdel.o and /dev/null differ diff --git a/libft/ft_memmove.o b/libft/ft_memmove.o deleted file mode 100644 index d757127..0000000 Binary files a/libft/ft_memmove.o and /dev/null differ diff --git a/libft/ft_memset.o b/libft/ft_memset.o deleted file mode 100644 index c417876..0000000 Binary files a/libft/ft_memset.o and /dev/null differ diff --git a/libft/ft_print_memory.o b/libft/ft_print_memory.o deleted file mode 100644 index 0892305..0000000 Binary files a/libft/ft_print_memory.o and /dev/null differ diff --git a/libft/ft_printf.o b/libft/ft_printf.o deleted file mode 100644 index a816835..0000000 Binary files a/libft/ft_printf.o and /dev/null differ diff --git a/libft/ft_putchar.o b/libft/ft_putchar.o deleted file mode 100644 index 9699a4f..0000000 Binary files a/libft/ft_putchar.o and /dev/null differ diff --git a/libft/ft_putchar_fd.o b/libft/ft_putchar_fd.o deleted file mode 100644 index ea29042..0000000 Binary files a/libft/ft_putchar_fd.o and /dev/null differ diff --git a/libft/ft_putendl.o b/libft/ft_putendl.o deleted file mode 100644 index c211bb5..0000000 Binary files a/libft/ft_putendl.o and /dev/null differ diff --git a/libft/ft_putendl_fd.o b/libft/ft_putendl_fd.o deleted file mode 100644 index a46f0d7..0000000 Binary files a/libft/ft_putendl_fd.o and /dev/null differ diff --git a/libft/ft_putnbr.o b/libft/ft_putnbr.o deleted file mode 100644 index cb8bb4c..0000000 Binary files a/libft/ft_putnbr.o and /dev/null differ diff --git a/libft/ft_putnbr_fd.o b/libft/ft_putnbr_fd.o deleted file mode 100644 index 8f86514..0000000 Binary files a/libft/ft_putnbr_fd.o and /dev/null differ diff --git a/libft/ft_putstr.o b/libft/ft_putstr.o deleted file mode 100644 index a67a04c..0000000 Binary files a/libft/ft_putstr.o and /dev/null differ diff --git a/libft/ft_putstr_fd.o b/libft/ft_putstr_fd.o deleted file mode 100644 index 28808fb..0000000 Binary files a/libft/ft_putstr_fd.o and /dev/null differ diff --git a/libft/ft_strcat.o b/libft/ft_strcat.o deleted file mode 100644 index 2e91d19..0000000 Binary files a/libft/ft_strcat.o and /dev/null differ diff --git a/libft/ft_strchr.o b/libft/ft_strchr.o deleted file mode 100644 index 7b20710..0000000 Binary files a/libft/ft_strchr.o and /dev/null differ diff --git a/libft/ft_strclr.o b/libft/ft_strclr.o deleted file mode 100644 index 06364d0..0000000 Binary files a/libft/ft_strclr.o and /dev/null differ diff --git a/libft/ft_strcmp.o b/libft/ft_strcmp.o deleted file mode 100644 index 962ad0e..0000000 Binary files a/libft/ft_strcmp.o and /dev/null differ diff --git a/libft/ft_strcpy.o b/libft/ft_strcpy.o deleted file mode 100644 index 20e8767..0000000 Binary files a/libft/ft_strcpy.o and /dev/null differ diff --git a/libft/ft_strdel.o b/libft/ft_strdel.o deleted file mode 100644 index 4f7e4a3..0000000 Binary files a/libft/ft_strdel.o and /dev/null differ diff --git a/libft/ft_strdup.o b/libft/ft_strdup.o deleted file mode 100644 index 006d945..0000000 Binary files a/libft/ft_strdup.o and /dev/null differ diff --git a/libft/ft_strequ.o b/libft/ft_strequ.o deleted file mode 100644 index e36f5d0..0000000 Binary files a/libft/ft_strequ.o and /dev/null differ diff --git a/libft/ft_striter.o b/libft/ft_striter.o deleted file mode 100644 index a1fc0e5..0000000 Binary files a/libft/ft_striter.o and /dev/null differ diff --git a/libft/ft_striteri.o b/libft/ft_striteri.o deleted file mode 100644 index 60bc3ff..0000000 Binary files a/libft/ft_striteri.o and /dev/null differ diff --git a/libft/ft_strjoin.o b/libft/ft_strjoin.o deleted file mode 100644 index d75ad5b..0000000 Binary files a/libft/ft_strjoin.o and /dev/null differ diff --git a/libft/ft_strlcat.o b/libft/ft_strlcat.o deleted file mode 100644 index b8535e8..0000000 Binary files a/libft/ft_strlcat.o and /dev/null differ diff --git a/libft/ft_strlen.o b/libft/ft_strlen.o deleted file mode 100644 index f9eacb6..0000000 Binary files a/libft/ft_strlen.o and /dev/null differ diff --git a/libft/ft_strmap.o b/libft/ft_strmap.o deleted file mode 100644 index 884e873..0000000 Binary files a/libft/ft_strmap.o and /dev/null differ diff --git a/libft/ft_strmapi.o b/libft/ft_strmapi.o deleted file mode 100644 index f85d187..0000000 Binary files a/libft/ft_strmapi.o and /dev/null differ diff --git a/libft/ft_strncat.o b/libft/ft_strncat.o deleted file mode 100644 index d4cb0eb..0000000 Binary files a/libft/ft_strncat.o and /dev/null differ diff --git a/libft/ft_strncmp.o b/libft/ft_strncmp.o deleted file mode 100644 index ed161ed..0000000 Binary files a/libft/ft_strncmp.o and /dev/null differ diff --git a/libft/ft_strncpy.o b/libft/ft_strncpy.o deleted file mode 100644 index d79c525..0000000 Binary files a/libft/ft_strncpy.o and /dev/null differ diff --git a/libft/ft_strnequ.o b/libft/ft_strnequ.o deleted file mode 100644 index beedb9e..0000000 Binary files a/libft/ft_strnequ.o and /dev/null differ diff --git a/libft/ft_strnew.o b/libft/ft_strnew.o deleted file mode 100644 index 5830479..0000000 Binary files a/libft/ft_strnew.o and /dev/null differ diff --git a/libft/ft_strnstr.o b/libft/ft_strnstr.o deleted file mode 100644 index a5a5190..0000000 Binary files a/libft/ft_strnstr.o and /dev/null differ diff --git a/libft/ft_strrchr.o b/libft/ft_strrchr.o deleted file mode 100644 index ec6ed25..0000000 Binary files a/libft/ft_strrchr.o and /dev/null differ diff --git a/libft/ft_strsplit.o b/libft/ft_strsplit.o deleted file mode 100644 index 748a59f..0000000 Binary files a/libft/ft_strsplit.o and /dev/null differ diff --git a/libft/ft_strstr.o b/libft/ft_strstr.o deleted file mode 100644 index db39920..0000000 Binary files a/libft/ft_strstr.o and /dev/null differ diff --git a/libft/ft_strsub.o b/libft/ft_strsub.o deleted file mode 100644 index 14bc068..0000000 Binary files a/libft/ft_strsub.o and /dev/null differ diff --git a/libft/ft_strtrim.o b/libft/ft_strtrim.o deleted file mode 100644 index 67fbda2..0000000 Binary files a/libft/ft_strtrim.o and /dev/null differ diff --git a/libft/ft_tolower.o b/libft/ft_tolower.o deleted file mode 100644 index dc1e8d8..0000000 Binary files a/libft/ft_tolower.o and /dev/null differ diff --git a/libft/ft_toupper.o b/libft/ft_toupper.o deleted file mode 100644 index 62df763..0000000 Binary files a/libft/ft_toupper.o and /dev/null differ diff --git a/libft/get_next_line.o b/libft/get_next_line.o deleted file mode 100644 index 83252d5..0000000 Binary files a/libft/get_next_line.o and /dev/null differ diff --git a/libft/libft.a b/libft/libft.a index 1150ebf..a25de28 100644 Binary files a/libft/libft.a and b/libft/libft.a differ diff --git a/libft/printf_src/allowed_symbols.o b/libft/printf_src/allowed_symbols.o deleted file mode 100644 index d5d7a83..0000000 Binary files a/libft/printf_src/allowed_symbols.o and /dev/null differ diff --git a/libft/printf_src/bonus_types.o b/libft/printf_src/bonus_types.o deleted file mode 100644 index 13f3057..0000000 Binary files a/libft/printf_src/bonus_types.o and /dev/null differ diff --git a/libft/printf_src/convert_to_str.o b/libft/printf_src/convert_to_str.o deleted file mode 100644 index ce9f566..0000000 Binary files a/libft/printf_src/convert_to_str.o and /dev/null differ diff --git a/libft/printf_src/function_array.o b/libft/printf_src/function_array.o deleted file mode 100644 index 030b95b..0000000 Binary files a/libft/printf_src/function_array.o and /dev/null differ diff --git a/libft/printf_src/handlers.o b/libft/printf_src/handlers.o deleted file mode 100644 index 0c22bb8..0000000 Binary files a/libft/printf_src/handlers.o and /dev/null differ diff --git a/libft/printf_src/mem_funcs.o b/libft/printf_src/mem_funcs.o deleted file mode 100644 index 510dd69..0000000 Binary files a/libft/printf_src/mem_funcs.o and /dev/null differ diff --git a/libft/printf_src/print_float.o b/libft/printf_src/print_float.o deleted file mode 100644 index 7cdfa0b..0000000 Binary files a/libft/printf_src/print_float.o and /dev/null differ diff --git a/libft/printf_src/print_funcs.o b/libft/printf_src/print_funcs.o deleted file mode 100644 index 3970313..0000000 Binary files a/libft/printf_src/print_funcs.o and /dev/null differ diff --git a/libft/printf_src/print_int.o b/libft/printf_src/print_int.o deleted file mode 100644 index 17172d4..0000000 Binary files a/libft/printf_src/print_int.o and /dev/null differ diff --git a/libft/printf_src/print_pointer.o b/libft/printf_src/print_pointer.o deleted file mode 100644 index 60f4775..0000000 Binary files a/libft/printf_src/print_pointer.o and /dev/null differ diff --git a/libft/printf_src/print_str.o b/libft/printf_src/print_str.o deleted file mode 100644 index fed0959..0000000 Binary files a/libft/printf_src/print_str.o and /dev/null differ diff --git a/libft/printf_src/print_uint.o b/libft/printf_src/print_uint.o deleted file mode 100644 index 12bcbb3..0000000 Binary files a/libft/printf_src/print_uint.o and /dev/null differ diff --git a/libft/printf_src/str_functions.o b/libft/printf_src/str_functions.o deleted file mode 100644 index acabedb..0000000 Binary files a/libft/printf_src/str_functions.o and /dev/null differ diff --git a/res.txt b/res.txt index e619f4d..8bb3843 100644 --- a/res.txt +++ b/res.txt @@ -7,1824 +7,9533 @@ launched players/carli.filler $$$ exec p1 : [players/carli.filler] launched ./yochered.filler $$$ exec p2 : [./yochered.filler] -Plateau 24 40: - 0123456789012345678901234567890123456789 -000 ........................................ -001 ........................................ -002 ........................................ -003 ...O.................................... -004 ........................................ -005 ........................................ -006 ........................................ -007 ........................................ -008 ........................................ -009 ........................................ -010 ........................................ -011 ........................................ -012 ........................................ -013 ........................................ -014 ........................................ -015 ........................................ -016 ........................................ -017 ........................................ -018 ........................................ -019 ................................X....... -020 ........................................ -021 ........................................ -022 ........................................ -023 ........................................ -Piece 2 2: -.* -** - 0) { - if (ft_strstr(line, "yochered.filler")) + if (ft_strstr(line, "[./yochered.filler]")) { d->m_c = *(line + 10) == 1 ? 'O' : 'X'; - d->e_c = d->m_c = 'O' ? 'X' : 'O'; + d->e_c = (d->m_c == 'O') ? 'X' : 'O'; } if (ft_strnequ(line, "Plateau", 7)) insert_to_list(&head, fd, line, d); + if (ft_strnequ(line, "launched", 8) && !ft_strstr(line, "yochered.filler")) + d->enemy = ft_strdup(line + 17); + if (CHAR(*(line + 3), d->e_c) && ft_strstr(line, "fin:")) + d->e_score = ft_atoi(line + 10); + else if (CHAR(*(line + 3), d->m_c) && ft_strstr(line, "fin:")) + d->my_score = ft_atoi(line + 10); } + if (d->m_c == 'O') + d->i = 0; return (head); } diff --git a/visu/print.c b/visu/print.c index b92f8e2..e535dde 100644 --- a/visu/print.c +++ b/visu/print.c @@ -18,7 +18,11 @@ t_img *new_image(t_desc *d) if (!(img = (t_img*)malloc(sizeof(t_img)))) return (NULL); - img->img = mlx_new_image(d->mlx, MAP_W, MAP_H); + img->sq_size = MIN((WIDTH - 400) / d->map_w, (HEIGHT - 200) / d->map_h); + img->height = d->map_h * img->sq_size; + img->width = d->map_w * img->sq_size; + img->bor = img->sq_size < 20 ? 1 : 2; + img->img = mlx_new_image(d->mlx, img->width, img->height); img->ptr = mlx_get_data_addr(img->img, &img->bpp, &img->s_l, &img->endian); img->bpp /= 8; return (img); @@ -26,9 +30,9 @@ t_img *new_image(t_desc *d) void img_putpixel(t_img *img, int x, int y, int color) { - if (x < 0 || y < 0 || x > MAP_W || y > MAP_H) + if (x < 0 || y < 0 || x >= img->width || y >= img->height) return ; - *(int*)(img->ptr + ((x + y * MAP_W) * img->bpp)) = color; + *(int*)(img->ptr + ((x + y * img->width) * img->bpp)) = color; } void putsquare(t_img *img, int x, int y, int color) @@ -36,13 +40,20 @@ void putsquare(t_img *img, int x, int y, int color) int w; int h; - w = x * SIZE; - h = y * SIZE; - while (y <= h) + w = x + img->sq_size; + h = y + img->sq_size; + while (y < h) { - x = w / SIZE - 1; - while (++x <= w) - img_putpixel(img, x, y, color); + x = w - img->sq_size; + while (x < w) + { + if (x < w - img->sq_size + img->bor || x >= w - img->bor + || y < h - img->sq_size + img->bor || y >= h - img->bor) + img_putpixel(img, x, y, B_COL); + else + img_putpixel(img, x, y, color); + x++; + } y++; } } @@ -52,27 +63,46 @@ void print_map(t_img *img, t_desc *d, t_frames *frame) int i; int j; - i = -1; + i = 0; while (++i < d->map_h) { j = -1; while (++j < d->map_w) { if (frame->map[i][j] == '.') - putsquare(img, j, i, 0xFFFFFF); + putsquare(img, j * img->sq_size, i * img->sq_size, 0xecebec); + else if (CHAR(frame->map[i][j], d->m_c)) + putsquare(img, j * img->sq_size, i * img->sq_size, d->my_col); + else if (CHAR(frame->map[i][j], d->e_c)) + putsquare(img, j * img->sq_size, i * img->sq_size, d->enem_col); } } - mlx_put_image_to_window(d->mlx, d->win, img->img,(WIDTH - MAP_W) / 2, (HEIGHT - MAP_H) / 2); + mlx_put_image_to_window(d->mlx, d->win, img->img, (WIDTH - img->width) / 2, (HEIGHT - img->height) / 2); } -void fill_window(t_desc *d, t_frames *head) +int fill_window(t_desc *d, t_frames *head, int flag) { - t_img *img; + static t_frames *cur; + t_img *img; img = new_image(d); - // while (head) - // { - print_map(img, d, head); - // head = head->next; - // } + cur = cur ? cur : head; + if (!cur) + return (0); + if (d->i && g_my_score < d->my_score) + g_my_score += (flag == 1 ? 1 : -1); + else if (!d->i && g_e_score < d->e_score) + g_e_score += (flag == 1 ? 1 : -1); + d->i += (flag == 1 ? 1 : -1); + if (cur->prev && flag == -1) + cur = cur->prev; + else if (cur->next && flag == 1) + cur = cur->next; + print_map(img, d, cur); + if (!cur->next) + { + print_score(d); + return (0); + } + return (1); } \ No newline at end of file diff --git a/visu/visu.c b/visu/visu.c index fddfd28..2ad5eec 100644 --- a/visu/visu.c +++ b/visu/visu.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "visu.h" +#include void put_error(char *str) { @@ -25,6 +26,10 @@ void init_description(t_desc *d) { d->map_h = 0; d->map_w = 0; + d->my_col = 0x0ad7e7; + d->enem_col = 0xea0f0f; + g_my_score = 1; + g_e_score = 1; } int main(int ac, char **av) @@ -40,17 +45,10 @@ int main(int ac, char **av) { if ((fd = open(av[1], 0)) == -1) put_error(NULL); - create_window(&d); head = parse_file(&d, fd); - fill_window(&d, head); - // while (head) - // { - // for(int i = 0; i < d.map_h; i++) - // ft_printf(CYAN("%s\n"), head->map[i]); - // ft_printf("\n\n"); - // head = head->next; - // } - mlx_hook(d.win, 2, 5, key_hook, &d); + create_window(&d); + d.head = head; + mlx_hook(d.win, 2, 3, key_hook, &d); mlx_loop(d.mlx); if ((close(fd) == -1)) put_error(NULL); diff --git a/visu/visu.h b/visu/visu.h index 0fc0436..0708192 100644 --- a/visu/visu.h +++ b/visu/visu.h @@ -18,11 +18,15 @@ # include # include # include +# define MIN(x, y) (x) < (y) ? (x) : (y) # define WIDTH 1920 # define HEIGHT 1280 -# define MAP_H 1000 -# define MAP_W 1000 -# define SIZE 30 +# define CHAR(x, c) ((x) == (c) || (x) == (c + 32) ? 1 : 0) +# define B_COL 0x2a472a +# define TIME 1000 + +int g_my_score; +int g_e_score; typedef struct s_desc { @@ -30,8 +34,16 @@ typedef struct s_desc void *win; char m_c; char e_c; + int my_col; + int enem_col; int map_h; int map_w; + char *enemy; + int my_score; + int e_score; + struct s_img *scale; + struct s_frames *head; + int i; } t_desc; typedef struct s_frames @@ -45,15 +57,21 @@ typedef struct s_img { void *img; void *ptr; + int sq_size; int bpp; int s_l; int endian; + int height; + int width; + int bor; } t_img; t_frames *parse_file(t_desc *d, int fd); void create_window(t_desc *d); int key_hook(int key, void *param); -void fill_window(t_desc *d, t_frames *head); +int fill_window(t_desc *d, t_frames *head, int flag); void img_putpixel(t_img *img, int x, int y, int color); +void print_score(t_desc *d); +t_img *create_scale(t_desc *d); #endif diff --git a/visu/windows_funcs.c b/visu/windows_funcs.c index 393bf64..6d3c3a1 100644 --- a/visu/windows_funcs.c +++ b/visu/windows_funcs.c @@ -12,10 +12,72 @@ #include "visu.h" +void print_players(t_desc *d) +{ + mlx_string_put(d->mlx, d->win, WIDTH / 2 - 200, 50, d->my_col, "yochered.filler"); + mlx_string_put(d->mlx, d->win, WIDTH / 2 - 10, 50, 0xffffff, "VS"); + mlx_string_put(d->mlx, d->win, WIDTH / 2 + 50, 50, d->enem_col, d->enemy); +} + +void update_scale(t_desc *d, t_img *img) +{ + int tmp1; + int tmp2; + int border; + int i; + + border = ((double)img->width / 100) * (double)(g_my_score / ((double)(g_my_score + g_e_score) / 100)); + i = -1; + while (++i < img->height) + { + tmp1 = -1; + tmp2 = img->width; + while (++tmp1 <= border) + img_putpixel(img, tmp1, i, d->my_col); + while (--tmp2 >= border) + img_putpixel(img, tmp2, i, d->enem_col); + } + mlx_put_image_to_window(d->mlx, d->win, img->img, (WIDTH - img->width) / 2, HEIGHT - 100); +} + +t_img *create_scale(t_desc *d) +{ + t_img *img; + + if (!(img = (t_img*)malloc(sizeof(t_img)))) + return (NULL); + img->height = 15; + img->width = 400; + img->img = mlx_new_image(d->mlx, img->width, img->height); + img->ptr = mlx_get_data_addr(img->img, &img->bpp, &img->s_l, &img->endian); + img->bpp /= 8; + return (img); +} + +void print_score(t_desc *d) +{ + char *res; + + if (d->e_score > d->my_score) + { + res = ft_strjoin("WINNER: ", d->enemy); + mlx_string_put(d->mlx, d->win, WIDTH / 2 - ft_strlen(res) * 5, HEIGHT - 60, d->enem_col, res); + free(res); + } + else + { + res = ft_strjoin("WINNER: ", "yochered.filler"); + mlx_string_put(d->mlx, d->win, WIDTH / 2 - ft_strlen(res) * 5, HEIGHT - 60, d->my_col, res); + free(res); + } +} + void create_window(t_desc *d) { d->mlx = mlx_init(); d->win = mlx_new_window(d->mlx, WIDTH, HEIGHT, "FILLER"); + print_players(d); + d->scale = create_scale(d); } int key_hook(int key, void *param) @@ -23,10 +85,20 @@ int key_hook(int key, void *param) t_desc *desc; desc = (t_desc*)param; + while (key == 49 && fill_window(desc, desc->head, 1)) + { + mlx_do_sync(desc->mlx); + update_scale(desc, desc->scale); + } if (key == 53) { mlx_destroy_window(desc->mlx, desc->win); exit(0); } + if (key == 123 || key == 124) + { + fill_window(desc, desc->head, key == 123 ? -1 : 1); + update_scale(desc, desc->scale); + } return (0); } diff --git a/visu_filler b/visu_filler deleted file mode 100755 index b9597cf..0000000 Binary files a/visu_filler and /dev/null differ diff --git a/yochered.filler b/yochered.filler deleted file mode 100755 index b6c2e16..0000000 Binary files a/yochered.filler and /dev/null differ