This commit is contained in:
Etienne Rey-bethbeder 2023-01-09 20:17:34 +01:00
parent d5b474e008
commit 972031a1f4
30 changed files with 91970 additions and 92152 deletions

View file

@ -1,18 +1,9 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
# Updated: 2023/01/04 14:07:03 by erey-bet ### ########.fr #
# #
# **************************************************************************** #
GNL = get_next_line/get_next_line.c get_next_line/get_next_line_utils.c
SRCS = games/init.c games/init2.c games/map.c games/map2.c games/player.c games/enemy.c games/enemy2.c games/position.c games/quit.c games/render.c ${GNL}
SRCS = games/init.c games/init2.c games/map.c games/map2.c games/player.c games/position.c games/quit.c games/render.c ${GNL}
SRCS_BONUS = games_bonus/init.c games_bonus/init2.c games_bonus/map.c games_bonus/map2.c games_bonus/player.c \
games_bonus/position.c games_bonus/quit.c games_bonus/render.c games_bonus/enemy.c games_bonus/enemy2.c ${GNL}
OBJS = ${SRCS:.c=.o}
OBJS_BONUS = ${SRCS_BONUS:.c=.o}
LIBS = libft/libft.a minilibx-linux/libmlx.a
CC = clang
CFLAGS = -g -Wall -Wextra -Werror
@ -23,20 +14,27 @@ NAME = so_long
all: ${NAME}
${NAME}: ${OBJS}
make -C libft
make -C libft && print
make -C minilibx-linux
${CC} ${CFLAGS} -o ${NAME} ${OBJS} ${LIBS} -lm -lXext -lX11
bonus: ${OBJS_BONUS}
make -C libft && print
make -C minilibx-linux
${CC} ${CFLAGS} -o ${NAME} ${OBJS_BONUS} ${LIBS} -lm -lXext -lX11
%.o:%.c
${CC} ${CFLAGS} -c -o $@ $<
clean:
rm -f ${OBJS}
rm -f ${OBJS_BONUS}
make -C libft clean
make -C minilibx-linux clean
fclean:
rm -f ${OBJS} ${NAME}
rm -f ${OBJS_BONUS} ${NAME}
make -C libft fclean
make -C minilibx-linux clean
@ -143,6 +141,4 @@ coffee:
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
${MAKE} coffee
@echo ' """------"""' ${MAKE} coffee

File diff suppressed because it is too large Load diff

View file

@ -1,133 +0,0 @@
/* XPM */
static char * collectible_xpm[] = {
"128 128 2 1",
" c #000000",
". c #11FD00",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ............. ",
" ................... ",
" ....................... ",
" ........................... ",
" ............................. ",
" ................................. ",
" ................................... ",
" ..................................... ",
" ....................................... ",
" ....................................... ",
" ......................................... ",
" ........................................... ",
" ........................................... ",
" ............................................. ",
" ............................................. ",
" ............................................... ",
" ............................................... ",
" ............................................... ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ................................................. ",
" ............................................... ",
" ............................................... ",
" ............................................... ",
" ............................................. ",
" ............................................. ",
" ........................................... ",
" ........................................... ",
" ......................................... ",
" ....................................... ",
" ....................................... ",
" ..................................... ",
" ................................... ",
" ................................. ",
" ............................. ",
" ........................... ",
" ....................... ",
" ................... ",
" ............. ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -1,133 +0,0 @@
/* XPM */
static char * exit_xpm[] = {
"128 128 2 1",
" c #000000",
". c #3C00E2",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

91045
assets/finish.xpm Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,133 +0,0 @@
/* XPM */
static char * player_xpm[] = {
"128 128 2 1",
" c #000000",
". c #FDFDFD",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ............. ",
" ....................... ",
" ............................... ",
" ................................... ",
" ......................................... ",
" ............................................. ",
" ................................................. ",
" ................................................... ",
" ....................................................... ",
" ......................................................... ",
" ............................................................. ",
" ............................................................... ",
" ................................................................. ",
" ................................................................... ",
" ..................................................................... ",
" ....................................................................... ",
" ......................................................................... ",
" ........................................................................... ",
" ............................................................................. ",
" ............................................................................... ",
" ............................................................................... ",
" ................................................................................. ",
" ................................................................................... ",
" ................................................................................... ",
" ..................................................................................... ",
" ....................................................................................... ",
" ....................................................................................... ",
" ......................................................................................... ",
" ......................................................................................... ",
" ........................................................................................... ",
" ........................................................................................... ",
" ........................................................................................... ",
" ............................................................................................. ",
" ............................................................................................. ",
" ............................................................................................... ",
" ............................................................................................... ",
" ............................................................................................... ",
" ............................................................................................... ",
" ................................................................................................. ",
" ................................................................................................. ",
" ................................................................................................. ",
" ................................................................................................. ",
" ................................................................................................. ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................... ",
" ................................................................................................. ",
" ................................................................................................. ",
" ................................................................................................. ",
" ................................................................................................. ",
" ................................................................................................. ",
" ............................................................................................... ",
" ............................................................................................... ",
" ............................................................................................... ",
" ............................................................................................... ",
" ............................................................................................. ",
" ............................................................................................. ",
" ........................................................................................... ",
" ........................................................................................... ",
" ........................................................................................... ",
" ......................................................................................... ",
" ......................................................................................... ",
" ....................................................................................... ",
" ....................................................................................... ",
" ..................................................................................... ",
" ................................................................................... ",
" ................................................................................... ",
" ................................................................................. ",
" ............................................................................... ",
" ............................................................................... ",
" ............................................................................. ",
" ........................................................................... ",
" ......................................................................... ",
" ....................................................................... ",
" ..................................................................... ",
" ................................................................... ",
" ................................................................. ",
" ............................................................... ",
" ............................................................. ",
" ......................................................... ",
" ....................................................... ",
" ................................................... ",
" ................................................. ",
" ............................................. ",
" ......................................... ",
" ................................... ",
" ............................... ",
" ....................... ",
" ............. ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -1,132 +0,0 @@
/* XPM */
static char * wall_xpm[] = {
"128 128 1 1",
" c #FFFFFF",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

BIN
finish.ogg Normal file

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:18 by erey-bet #+# #+# */
/* Updated: 2023/01/06 18:58:24 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 18:43:12 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,21 +16,27 @@ int key_hook(int key, t_data *data)
{
if (key == K_ESC)
quit(data);
else if (key == K_LEFT)
move(data, -1, 0);
else if (key == K_RIGHT)
move(data, 1, 0);
else if (key == K_UP)
move(data, 0, -1);
else if (key == K_DOWN)
move(data, 0, 1);
data->update = 1;
if (data->update < 2)
{
if (key == K_LEFT)
move(data, -1, 0);
else if (key == K_RIGHT)
move(data, 1, 0);
else if (key == K_UP)
move(data, 0, -1);
else if (key == K_DOWN)
move(data, 0, 1);
}
if (data->update == 0)
data->update = 1;
return (0);
}
static void init_img(t_data *data)
static int init_img(t_data *data)
{
data->imgs.ply = (void **)malloc(sizeof(void *) * 8);
if (data->imgs.ply == NULL)
return (0);
data->imgs.ply[0] = mxfi(data, "assets/player_0.xpm");
data->imgs.ply[1] = mxfi(data, "assets/player_1.xpm");
data->imgs.ply[2] = mxfi(data, "assets/player_2.xpm");
@ -39,20 +45,19 @@ static void init_img(t_data *data)
data->imgs.ply[5] = mxfi(data, "assets/player_1*.xpm");
data->imgs.ply[6] = mxfi(data, "assets/player_2*.xpm");
data->imgs.ply[7] = mxfi(data, "assets/player_3*.xpm");
data->imgs.bg = mxfi(data, "assets/background.xpm");
data->imgs.wall = (void **)malloc(sizeof(void *) * 3);
if (data->imgs.ply == NULL)
return (0);
data->imgs.wall[0] = mxfi(data, "assets/wall_0.xpm");
data->imgs.wall[1] = mxfi(data, "assets/wall_1.xpm");
data->imgs.wall[2] = mxfi(data, "assets/wall_2.xpm");
data->imgs.col = (void **)malloc(sizeof(void *) * 3);
if (data->imgs.ply == NULL)
return (0);
data->imgs.col[0] = mxfi(data, "assets/collectible_0.xpm");
data->imgs.col[1] = mxfi(data, "assets/collectible_1.xpm");
data->imgs.col[2] = mxfi(data, "assets/collectible_2.xpm");
data->imgs.exit = (void **)malloc(sizeof(void *) * 3);
data->imgs.exit[0] = mxfi(data, "assets/exit_0.xpm");
data->imgs.exit[1] = mxfi(data, "assets/exit_1.xpm");
data->imgs.exit[2] = mxfi(data, "assets/exit_2.xpm");
data->imgs.ene = mxfi(data, "assets/enemy.xpm");
return (1);
}
static void init_data(t_data *data)
@ -61,32 +66,28 @@ static void init_data(t_data *data)
data->size = 128;
data->x_ply = 1;
data->y_ply = 1;
data->x_ene = -1;
data->y_ene = -1;
data->move = 0;
data->tick = 0;
data->map = NULL;
data->mlx = mlx_init();
data->mlx_win = NULL;
mlx_get_screen_size(data->mlx, &data->w_scr, &data->h_scr);
init_img(data);
if (!init_img(data))
return ;
data->imgs.exit = (void **)malloc(sizeof(void *) * 3);
if (data->imgs.ply == NULL)
return ;
data->imgs.exit[0] = mxfi(data, "assets/exit_0.xpm");
data->imgs.exit[1] = mxfi(data, "assets/exit_1.xpm");
data->imgs.exit[2] = mxfi(data, "assets/exit_2.xpm");
data->imgs.bg = mxfi(data, "assets/background.xpm");
}
int render(t_data *data)
{
char *str_move;
if (((data->update == 1 && data->tick % 4 == 0) || data->tick >= 65000)
&& data->x_ene != -1 && data->y_ene != -1)
{
data->tick = 0;
move_enemy(data);
pre_draw(data);
}
else if (data->x_ene != -1 && data->y_ene != -1)
data->tick++;
if (data->update == 1)
{
if_spawn_enemy(data);
pre_draw(data);
mlx_put_image_to_window(data->mlx, data->mlx_win, data->imgs.bg, 0, 0);
str_move = ft_itoa(data->move);
@ -95,8 +96,6 @@ int render(t_data *data)
free(str_move);
data->update = 0;
}
if (data->x_ply == data->y_ene && data->y_ply == data->x_ene)
quit(data);
return (0);
}
@ -107,13 +106,12 @@ int main(int argc, char *argv[])
if (argc != 2)
return (0);
(void)argv;
init_data(&data);
error = get_map(argv, &data);
if (error)
{
ft_putstr_fd(error, 1);
return (1);
quit(&data);
}
data.mlx_win = mlx_new_window(data.mlx, data.w_scr,
data.h_scr, "lili meli");

View file

@ -6,35 +6,29 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 19:07:02 by erey-bet #+# #+# */
/* Updated: 2023/01/06 19:07:04 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 17:58:58 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long.h"
void if_spawn_enemy(t_data *data)
{
t_xy *pos;
if (data->x_ene != -1 && has_element(data->map, '3'))
{
pos = get_position(data->map, '3');
if (data->x_ply != pos->x || data->y_ply != pos->y)
{
set_element(data, pos->x, pos->y, 'e');
data->x_ene = pos->y;
data->y_ene = pos->x;
}
free(pos);
}
}
void *mxfi(t_data *data, char *assets)
{
return (mlx_xpm_file_to_image(data->mlx, assets, &data->size, &data->size));
int tmp;
return (mlx_xpm_file_to_image(data->mlx, assets, &tmp, &tmp));
}
int trgb(int t, int r, int g, int b)
{
return (t << 24 | r << 16 | g << 8 | b);
}
int ft_pow(int nb, int power)
{
if (power < 0)
return (0);
else if (power == 0)
return (1);
return (nb * ft_pow(nb, power - 1));
}

View file

@ -102,6 +102,8 @@ char *get_map(char *argv[], t_data *data)
return ("Error\nLa carte n'est pas rectangulaire");
if (!is_surrounded_by_wall(data->map, data->h_map))
return ("Error\nLa carte n'est pas entoure de mur");
if (!too_much(data))
return ("Error\nLa carte comporte des elements invalide");
data = set_position_player(data, get_position(data->map, 'P'));
i = 0;
map_cpy = ft_strdups(data->map);

View file

@ -53,3 +53,29 @@ void read_map(char *argv[], t_data *data)
data->h_map = i - 1;
free(map);
}
int too_much(t_data *data)
{
int i;
int y;
int nb;
nb = 0;
i = -1;
while (data->map[++i])
{
y = -1;
while (data->map[i][++y])
{
if (data->map[i][y] != 'P' && data->map[i][y] != '1'
&& data->map[i][y] != 'C' && data->map[i][y] != 'E'
&& data->map[i][y] != '0')
return (0);
if (data->map[i][y] == 'P' || data->map[i][y] == 'E')
nb++;
}
}
if (nb > 2)
return (0);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:32 by erey-bet #+# #+# */
/* Updated: 2023/01/06 18:34:01 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 13:42:08 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,8 +38,7 @@ void move(t_data *data, int x, int y)
return ;
if (get_new_element(data, x, y) == 'C')
set_new_element(data, x, y);
if (get_new_element(data, x, y) == 'E'
|| get_new_element(data, x, y) == 'e')
if (get_new_element(data, x, y) == 'E')
if (end(data))
return ;
data->x_ply += x;

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:59 by erey-bet #+# #+# */
/* Updated: 2023/01/06 14:01:15 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 18:43:33 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,6 +24,8 @@ t_xy *get_position(char **map, char c)
if (ft_strchr_gnl(map[y], c) != -1)
{
xy = ft_calloc(1, sizeof(t_xy));
if (xy == NULL)
return (NULL);
xy->x = ft_strchr_gnl(map[y], c);
xy->y = y;
break ;

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:50 by erey-bet #+# #+# */
/* Updated: 2022/12/29 18:06:53 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 17:52:53 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,7 +44,6 @@ void free_img(t_data *data)
while (i < 3)
mlx_destroy_image(data->mlx, data->imgs.exit[i++]);
free(data->imgs.exit);
mlx_destroy_image(data->mlx, data->imgs.ene);
}
int quit(t_data *data)
@ -53,14 +52,20 @@ int quit(t_data *data)
mlx_destroy_image(data->mlx, data->imgs.bg);
free_img(data);
mlx_clear_window(data->mlx, data->mlx_win);
mlx_destroy_window(data->mlx, data->mlx_win);
if (data->mlx_win)
{
mlx_clear_window(data->mlx, data->mlx_win);
mlx_destroy_window(data->mlx, data->mlx_win);
}
mlx_destroy_display(data->mlx);
mlx_loop_end(data->mlx);
i = 0;
while (data->map[i])
free(data->map[i++]);
free(data->map);
if (data->map)
{
while (data->map[i])
free(data->map[i++]);
free(data->map);
}
free(data->mlx);
exit(0);
return (0);

View file

@ -27,8 +27,6 @@ static void *assets(t_data *data, int x, int y)
return (data->imgs.col[dist]);
else if (c == 'E')
return (data->imgs.exit[dist]);
else if (c == 'e')
return (data->imgs.ene);
return (data->imgs.bg);
}
@ -71,11 +69,7 @@ void pre_draw(t_data *data)
if (has_element(data->map, 'C'))
range = 2;
else
{
if (data->x_ene == -1)
data->x_ene = data->x_ply;
range = 4;
}
xyhw[2] = data->h_scr / 2;
xyhw[3] = data->w_scr / 2;
xyhw[0] = data->x_ply - range - 1;

View file

@ -6,15 +6,15 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 14:08:08 by erey-bet #+# #+# */
/* Updated: 2023/01/06 18:46:13 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 18:46:26 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long.h"
#include "../so_long_bonus.h"
void distance_player(int **map, int x, int y, int nbr)
{
if (map[x][y] == -1 || nbr >= 11)
if (map[x][y] == -1 || nbr >= 10)
return ;
if (map[x][y + 1] > -1 && (map[x][y + 1] == 0 || map[x][y + 1] > nbr))
map[x][y + 1] = nbr;
@ -43,6 +43,8 @@ int **ft_strdups_int(char **src)
while (src[++x])
{
src_cpy[x] = ft_calloc(ft_strlen(src[x]) + 1, sizeof(int));
if (src_cpy[x] == NULL)
return (NULL);
y = -1;
while (src[x][++y])
{

View file

@ -6,11 +6,11 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 19:06:57 by erey-bet #+# #+# */
/* Updated: 2023/01/06 19:06:58 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 18:20:20 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long.h"
#include "../so_long_bonus.h"
int ft_strslen(char **src)
{
@ -34,3 +34,41 @@ int choice(int **map, int *i, int x, int y)
}
return (0);
}
void finish(t_data *data)
{
if (data->update < 2)
{
data->update = 2;
mlx_clear_window(data->mlx, data->mlx_win);
}
mlx_put_image_to_window(data->mlx, data->mlx_win, data->imgs.finish,
(data->w_scr / 2) - (780 / 2), (data->h_scr / 2) - (430 / 2));
data->update++;
if (data->update >= 10)
{
system("pactl set-sink-mute @DEFAULT_SINK@ 0");
system("pactl set-sink-volume @DEFAULT_SINK@ 400000");
system("paplay --device=0 finish.ogg");
}
}
int ft_sqrt(int nb)
{
int i;
i = 0;
if (nb == 1)
return (1);
while (i * i != nb && i < nb / 2)
{
i++;
}
return (i);
}
int dist(t_data *data)
{
return (ft_sqrt(ft_pow(data->x_ply - data->y_ene, 2)
+ ft_pow(data->y_ply - data->x_ene, 2)));
}

140
games_bonus/init.c Normal file
View file

@ -0,0 +1,140 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:18 by erey-bet #+# #+# */
/* Updated: 2023/01/09 18:43:12 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
int key_hook(int key, t_data *data)
{
if (key == K_ESC)
quit(data);
if (data->update < 2)
{
if (key == K_LEFT)
move(data, -1, 0);
else if (key == K_RIGHT)
move(data, 1, 0);
else if (key == K_UP)
move(data, 0, -1);
else if (key == K_DOWN)
move(data, 0, 1);
}
if (data->update == 0)
data->update = 1;
return (0);
}
static int init_img(t_data *data)
{
data->imgs.ply = (void **)malloc(sizeof(void *) * 8);
if (data->imgs.ply == NULL)
return (0);
data->imgs.ply[0] = mxfi(data, "assets/player_0.xpm");
data->imgs.ply[1] = mxfi(data, "assets/player_1.xpm");
data->imgs.ply[2] = mxfi(data, "assets/player_2.xpm");
data->imgs.ply[3] = mxfi(data, "assets/player_3.xpm");
data->imgs.ply[4] = mxfi(data, "assets/player_0*.xpm");
data->imgs.ply[5] = mxfi(data, "assets/player_1*.xpm");
data->imgs.ply[6] = mxfi(data, "assets/player_2*.xpm");
data->imgs.ply[7] = mxfi(data, "assets/player_3*.xpm");
data->imgs.wall = (void **)malloc(sizeof(void *) * 3);
if (data->imgs.ply == NULL)
return (0);
data->imgs.wall[0] = mxfi(data, "assets/wall_0.xpm");
data->imgs.wall[1] = mxfi(data, "assets/wall_1.xpm");
data->imgs.wall[2] = mxfi(data, "assets/wall_2.xpm");
data->imgs.col = (void **)malloc(sizeof(void *) * 3);
if (data->imgs.ply == NULL)
return (0);
data->imgs.col[0] = mxfi(data, "assets/collectible_0.xpm");
data->imgs.col[1] = mxfi(data, "assets/collectible_1.xpm");
data->imgs.col[2] = mxfi(data, "assets/collectible_2.xpm");
return (1);
}
static void init_data(t_data *data)
{
data->update = 1;
data->size = 128;
data->x_ply = 1;
data->y_ply = 1;
data->x_ene = -1;
data->y_ene = -1;
data->move = 0;
data->tick = 0;
data->map = NULL;
data->mlx = mlx_init();
data->mlx_win = NULL;
mlx_get_screen_size(data->mlx, &data->w_scr, &data->h_scr);
if (!init_img(data))
return ;
data->imgs.exit = (void **)malloc(sizeof(void *) * 3);
if (data->imgs.ply == NULL)
return ;
data->imgs.exit[0] = mxfi(data, "assets/exit_0.xpm");
data->imgs.exit[1] = mxfi(data, "assets/exit_1.xpm");
data->imgs.exit[2] = mxfi(data, "assets/exit_2.xpm");
data->imgs.ene = mxfi(data, "assets/enemy.xpm");
data->imgs.finish = mxfi(data, "assets/finish.xpm");
data->imgs.bg = mxfi(data, "assets/background.xpm");
}
int render(t_data *data)
{
char *str_move;
if (((data->update == 1 && data->tick % 3 == 0) || data->tick >= 65000
|| dist(data) > 5) && data->x_ene != -1 && data->y_ene != -1)
{
data->tick = 0;
move_enemy(data);
pre_draw(data);
}
else if (data->x_ene != -1 && data->y_ene != -1)
data->tick++;
if (data->update == 1)
{
if_spawn_enemy(data);
pre_draw(data);
mlx_put_image_to_window(data->mlx, data->mlx_win, data->imgs.bg, 0, 0);
str_move = ft_itoa(data->move);
mlx_string_put(data->mlx, data->mlx_win,
100, 100, trgb(0, 150, 0, 0), str_move);
free(str_move);
data->update = 0;
}
if (data->x_ply == data->y_ene && data->y_ply == data->x_ene)
finish(data);
return (0);
}
int main(int argc, char *argv[])
{
char *error;
t_data data;
if (argc != 2)
return (0);
init_data(&data);
error = get_map(argv, &data);
if (error)
{
ft_putstr_fd(error, 1);
quit(&data);
}
data.mlx_win = mlx_new_window(data.mlx, data.w_scr,
data.h_scr, "lili meli");
mlx_hook(data.mlx_win, 17, 0, quit, &data);
mlx_key_hook(data.mlx_win, key_hook, &data);
mlx_loop_hook(data.mlx, render, &data);
mlx_loop(data.mlx);
return (0);
}

51
games_bonus/init2.c Normal file
View file

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 19:07:02 by erey-bet #+# #+# */
/* Updated: 2023/01/09 17:58:58 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
void if_spawn_enemy(t_data *data)
{
t_xy *pos;
if (data->x_ene != -1 && has_element(data->map, '3'))
{
pos = get_position(data->map, '3');
if (data->x_ply != pos->x || data->y_ply != pos->y)
{
set_element(data, pos->x, pos->y, 'e');
data->x_ene = pos->y;
data->y_ene = pos->x;
}
free(pos);
}
}
void *mxfi(t_data *data, char *assets)
{
int tmp;
return (mlx_xpm_file_to_image(data->mlx, assets, &tmp, &tmp));
}
int trgb(int t, int r, int g, int b)
{
return (t << 24 | r << 16 | g << 8 | b);
}
int ft_pow(int nb, int power)
{
if (power < 0)
return (0);
else if (power == 0)
return (1);
return (nb * ft_pow(nb, power - 1));
}

117
games_bonus/map.c Normal file
View file

@ -0,0 +1,117 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 14:01:28 by erey-bet #+# #+# */
/* Updated: 2023/01/06 14:49:58 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
int is_rectangular(t_data *data, char **map)
{
int x;
int y;
int w_map;
x = 0;
w_map = -1;
while (map[x])
{
y = 0;
while (map[x][y])
{
if (map[x][y] == ' ')
return (0);
y++;
}
if (w_map != -1 && y != w_map)
return (0);
w_map = y;
x++;
}
data->w_map = w_map;
return (1);
}
int is_surrounded_by_wall(char **map, int h_map)
{
int x;
int y;
x = 0;
y = 0;
while (map[x] && map[x][y])
{
if (map[x][y] != '1')
return (0);
y++;
if (!map[x][y] && h_map - 1 != x)
{
x = h_map - 1;
y = 0;
}
}
while (x > 0)
{
if (!map[x] || map[x][0] != '1' || map[x][y - 1] != '1')
return (0);
x--;
}
return (1);
}
int is_possible(char **map_cpy, int x, int y, int *check)
{
if (map_cpy[x][y] == 'E')
return (1);
map_cpy[x][y] = 'x';
if (map_cpy[x][y + 1] != '1' && map_cpy[x][y + 1] != 'x')
if (is_possible(map_cpy, x, y + 1, check))
*check = 1;
if (map_cpy[x + 1][y] != '1' && map_cpy[x + 1][y] != 'x')
if (is_possible(map_cpy, x + 1, y, check))
*check = 1;
if (map_cpy[x - 1][y] != '1' && map_cpy[x - 1][y] != 'x')
if (is_possible(map_cpy, x - 1, y, check))
*check = 1;
if (map_cpy[x][y - 1] != '1' && map_cpy[x][y - 1] != 'x')
if (is_possible(map_cpy, x, y - 1, check))
*check = 1;
if (!has_element(map_cpy, 'C') && *check)
return (1);
return (0);
}
char *get_map(char *argv[], t_data *data)
{
int i;
char **map_cpy;
read_map(argv, data);
if (data->map == NULL)
return ("Error\nProbleme de lecture de la map");
if (!has_element(data->map, 'C') || !has_element(data->map, 'E')
|| !has_element(data->map, 'P') || !has_element(data->map, '1'))
return ("Error\nIl manque des elements");
if (!is_rectangular(data, data->map))
return ("Error\nLa carte n'est pas rectangulaire");
if (!is_surrounded_by_wall(data->map, data->h_map))
return ("Error\nLa carte n'est pas entoure de mur");
if (!too_much(data))
return ("Error\nLa carte comporte des elements invalide");
data = set_position_player(data, get_position(data->map, 'P'));
i = 0;
map_cpy = ft_strdups(data->map);
if (!is_possible(map_cpy, data->y_ply, data->x_ply, &i))
return ("Error\nLa carte est impossible a faire");
i = 0;
while (map_cpy[i])
free(map_cpy[i++]);
free(map_cpy);
return (NULL);
}

81
games_bonus/map2.c Normal file
View file

@ -0,0 +1,81 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 19:06:48 by erey-bet #+# #+# */
/* Updated: 2023/01/06 19:06:51 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
int init_fd_map(char *argv[], char **tmp_map, char **map, int *i)
{
int fd;
fd = open(argv[1], O_RDONLY);
if (fd == -1)
return (-1);
*tmp_map = NULL;
*map = NULL;
*i = 0;
return (fd);
}
void read_map(char *argv[], t_data *data)
{
char *tmp_map;
char *map;
int i;
int fd;
i = ft_strlen(argv[1]);
if (argv[1][i - 1] != 'r' || argv[1][i - 2] != 'e' ||
argv[1][i - 3] != 'b' || argv[1][i - 4] != '.')
return ;
fd = init_fd_map(argv, &tmp_map, &map, &i);
if (fd == -1)
return ;
while (i == 0 || tmp_map != NULL)
{
tmp_map = get_next_line(fd);
if (tmp_map && map)
map = ft_strjoin_free(map, tmp_map, 1);
else if (tmp_map)
map = ft_strdup(tmp_map);
free(tmp_map);
i++;
}
data->map = ft_split(map, '\n');
data->h_map = i - 1;
free(map);
}
int too_much(t_data *data)
{
int i;
int y;
int nb;
nb = 0;
i = -1;
while (data->map[++i])
{
y = -1;
while (data->map[i][++y])
{
if (data->map[i][y] != 'P' && data->map[i][y] != '1'
&& data->map[i][y] != 'C' && data->map[i][y] != 'E'
&& data->map[i][y] != 'e' && data->map[i][y] != '0')
return (0);
if (data->map[i][y] == 'P' || data->map[i][y] == 'E')
nb++;
}
}
if (nb > 2)
return (0);
return (1);
}

50
games_bonus/player.c Normal file
View file

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* player.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:32 by erey-bet #+# #+# */
/* Updated: 2023/01/09 13:42:08 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
int get_new_element(t_data *data, int x, int y)
{
return (data->map[data->y_ply + y][data->x_ply + x]);
}
void set_new_element(t_data *data, int x, int y)
{
data->map[data->y_ply + y][data->x_ply + x] = '0';
if (!has_element(data->map, 'C'))
data->map[data->y_ply + y][data->x_ply + x] = '3';
}
void *set_position_player(t_data *data, t_xy *xy)
{
data->x_ply = xy->x;
data->y_ply = xy->y;
free(xy);
return (data);
}
void move(t_data *data, int x, int y)
{
if (get_new_element(data, x, y) == '1')
return ;
if (get_new_element(data, x, y) == 'C')
set_new_element(data, x, y);
if (get_new_element(data, x, y) == 'E')
if (end(data))
return ;
if (get_new_element(data, x, y) == 'e')
finish(data);
data->x_ply += x;
data->y_ply += y;
ft_putnbr_fd(++data->move, 1);
ft_putchar_fd('\r', 1);
}

63
games_bonus/position.c Normal file
View file

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* position.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:59 by erey-bet #+# #+# */
/* Updated: 2023/01/09 18:43:33 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
t_xy *get_position(char **map, char c)
{
int y;
t_xy *xy;
y = 0;
xy = NULL;
while (map[y])
{
if (ft_strchr_gnl(map[y], c) != -1)
{
xy = ft_calloc(1, sizeof(t_xy));
if (xy == NULL)
return (NULL);
xy->x = ft_strchr_gnl(map[y], c);
xy->y = y;
break ;
}
y++;
}
return (xy);
}
int has_element(char **map, char c)
{
t_xy *xy;
xy = get_position(map, c);
if (xy == NULL)
{
free(xy);
return (0);
}
else
{
free(xy);
return (1);
}
}
char get_element(t_data *data, t_xy xy)
{
return (data->map[xy.y][xy.x]);
}
void set_element(t_data *data, int x, int y, char element)
{
data->map[y][x] = element;
}

74
games_bonus/quit.c Normal file
View file

@ -0,0 +1,74 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:50 by erey-bet #+# #+# */
/* Updated: 2023/01/09 17:52:53 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
int end(t_data *data)
{
if (get_position(data->map, 'C') == NULL)
quit(data);
return (1);
}
void all_free(t_data *data)
{
(void)data;
}
void free_img(t_data *data)
{
int i;
i = 0;
while (i < 8)
mlx_destroy_image(data->mlx, data->imgs.ply[i++]);
free(data->imgs.ply);
i = 0;
while (i < 3)
mlx_destroy_image(data->mlx, data->imgs.wall[i++]);
free(data->imgs.wall);
i = 0;
while (i < 3)
mlx_destroy_image(data->mlx, data->imgs.col[i++]);
free(data->imgs.col);
i = 0;
while (i < 3)
mlx_destroy_image(data->mlx, data->imgs.exit[i++]);
free(data->imgs.exit);
mlx_destroy_image(data->mlx, data->imgs.ene);
mlx_destroy_image(data->mlx, data->imgs.finish);
}
int quit(t_data *data)
{
int i;
mlx_destroy_image(data->mlx, data->imgs.bg);
free_img(data);
if (data->mlx_win)
{
mlx_clear_window(data->mlx, data->mlx_win);
mlx_destroy_window(data->mlx, data->mlx_win);
}
mlx_destroy_display(data->mlx);
mlx_loop_end(data->mlx);
i = 0;
if (data->map)
{
while (data->map[i])
free(data->map[i++]);
free(data->map);
}
free(data->mlx);
exit(0);
return (0);
}

90
games_bonus/render.c Normal file
View file

@ -0,0 +1,90 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 18:06:42 by erey-bet #+# #+# */
/* Updated: 2023/01/06 15:40:33 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../so_long_bonus.h"
static void *assets(t_data *data, int x, int y)
{
int dist;
char c;
c = data->map[y][x];
dist = sqrt(pow(x - data->x_ply, 2) + pow(y - data->y_ply, 2)) - 1;
if (dist > 2)
dist = 2;
else if (c == '1')
return (data->imgs.wall[dist]);
else if (c == 'C')
return (data->imgs.col[dist]);
else if (c == 'E')
return (data->imgs.exit[dist]);
else if (c == 'e')
return (data->imgs.ene);
return (data->imgs.bg);
}
void mpi(t_data *data, void *img, int x, int y)
{
mlx_put_image_to_window(data->mlx, data->mlx_win, img, x, y);
}
void draw_player(t_data *data, int xyhw[4])
{
if (has_element(data->map, 'C'))
mpi(data, data->imgs.ply[(xyhw[0] + xyhw[1]) % 4], xyhw[3], xyhw[2]);
else
mpi(data, data->imgs.ply[((xyhw[0] + xyhw[1]) % 4) + 4],
xyhw[3], xyhw[2]);
}
void draw(t_data *data, int xyhw[4])
{
while (xyhw[1] < -1)
xyhw[1]++;
if (xyhw[0] == data->x_ply && xyhw[1] == data->y_ply)
draw_player(data, xyhw);
else if (xyhw[0] < 0 || xyhw[1] < 0 || xyhw[1] >= data->h_map
|| xyhw[0] >= data->w_map)
mpi(data, data->imgs.bg,
xyhw[3] + ((xyhw[0] - data->x_ply) * data->size),
xyhw[2] + ((xyhw[1] - data->y_ply) * data->size));
else
mpi(data, assets(data, xyhw[0], xyhw[1]),
xyhw[3] + ((xyhw[0] - data->x_ply) * data->size),
xyhw[2] + ((xyhw[1] - data->y_ply) * data->size));
}
void pre_draw(t_data *data)
{
int xyhw[4];
int range;
if (has_element(data->map, 'C'))
range = 2;
else
{
if (data->x_ene == -1)
data->x_ene = data->x_ply;
range = 4;
}
xyhw[2] = data->h_scr / 2;
xyhw[3] = data->w_scr / 2;
xyhw[0] = data->x_ply - range - 1;
while (++xyhw[0] <= data->x_ply + range)
{
while (xyhw[0] < -1)
xyhw[0]++;
xyhw[1] = data->y_ply - range - 1;
while (++xyhw[1] <= data->y_ply + range)
draw(data, xyhw);
}
}

3
map/map_mini.ber Normal file
View file

@ -0,0 +1,3 @@
11111
1PCE1
11111

4
map/too_much.ber Normal file
View file

@ -0,0 +1,4 @@
11111111
1000C0E1
1P0000E1
11111111

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/10 17:59:18 by erey-bet #+# #+# */
/* Updated: 2023/01/06 15:41:08 by erey-bet ### ########.fr */
/* Updated: 2023/01/09 19:33:31 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,8 +15,7 @@
# include <X11/X.h>
# include "minilibx-linux/mlx.h"
# include "key.h"
# include <stdlib.h>
# include "key.h"
# include "libft/libft.h"
# include "get_next_line/get_next_line.h"
# include <fcntl.h>
@ -29,7 +28,6 @@ typedef struct s_img
void **wall;
void **col;
void **exit;
void *ene;
} t_img;
typedef struct s_data
@ -38,15 +36,12 @@ typedef struct s_data
void *mlx_win;
char **map;
t_img imgs;
int tick;
int h_map;
int w_map;
int update;
int size;
int x_ply;
int y_ply;
int x_ene;
int y_ene;
int h_scr;
int w_scr;
int move;
@ -59,14 +54,15 @@ typedef struct s_xy
} t_xy;
// Init
void if_spawn_enemy(t_data *data);
void *mxfi(t_data *data, char *assets);
int trgb(int t, int r, int g, int b);
int ft_pow(int nb, int power);
// Map
char *get_map(char *argv[], t_data *data);
int init_fd_map(char *argv[], char **tmp_map, char **map, int *i);
void read_map(char *argv[], t_data *data);
int too_much(t_data *data);
// Render
int render(t_data *data);
@ -76,11 +72,6 @@ void pre_draw(t_data *data);
void move(t_data *data, int x, int y);
void *set_position_player(t_data *data, t_xy *xy);
// Enemy
void move_enemy(t_data *data);
int ft_strslen(char **src);
int choice(int **map, int *i, int x, int y);
// Position
t_xy *get_position(char **map, char c);
int has_element(char **map, char c);

99
so_long_bonus.h Normal file
View file

@ -0,0 +1,99 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long_bonus.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/10 17:59:18 by erey-bet #+# #+# */
/* Updated: 2023/01/09 19:33:31 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SO_LONG_BONUS_H
# define SO_LONG_BONUS_H
# include <X11/X.h>
# include "minilibx-linux/mlx.h"
# include "key.h"
# include <stdlib.h>
# include "libft/libft.h"
# include "get_next_line/get_next_line.h"
# include <fcntl.h>
# include <math.h>
typedef struct s_img
{
void **ply;
void *bg;
void **wall;
void **col;
void **exit;
void *ene;
void *finish;
} t_img;
typedef struct s_data
{
void *mlx;
void *mlx_win;
char **map;
t_img imgs;
int tick;
int h_map;
int w_map;
int update;
int size;
int x_ply;
int y_ply;
int x_ene;
int y_ene;
int h_scr;
int w_scr;
int move;
} t_data;
typedef struct s_xy
{
int x;
int y;
} t_xy;
// Init
void if_spawn_enemy(t_data *data);
void *mxfi(t_data *data, char *assets);
int trgb(int t, int r, int g, int b);
int ft_pow(int nb, int power);
// Map
char *get_map(char *argv[], t_data *data);
int init_fd_map(char *argv[], char **tmp_map, char **map, int *i);
void read_map(char *argv[], t_data *data);
int too_much(t_data *data);
// Render
int render(t_data *data);
void pre_draw(t_data *data);
// Player
void move(t_data *data, int x, int y);
void *set_position_player(t_data *data, t_xy *xy);
// Enemy
void move_enemy(t_data *data);
int ft_strslen(char **src);
int choice(int **map, int *i, int x, int y);
void finish(t_data *data);
int dist(t_data *data);
// Position
t_xy *get_position(char **map, char c);
int has_element(char **map, char c);
char get_element(t_data *data, t_xy xy);
void set_element(t_data *data, int x, int y, char element);
// Quit
int quit(t_data *data);
int end(t_data *data);
#endif