CA MARCHE

This commit is contained in:
Camille Chauvet 2023-01-13 16:10:11 +01:00
parent 4ab400b5e4
commit f84f98fe21
86 changed files with 102 additions and 67 deletions

41
asset.c
View File

@ -6,19 +6,34 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */ /* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
/* Updated: 2023/01/11 19:08:46 by cchauvet ### ########.fr */ /* Updated: 2023/01/13 16:03:54 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "solong.h" #include "solong.h"
static void *ft_gen_asset(char *color, size_t case_size, t_data *data)
{
t_square square;
char *name;
int dimmension;
void *img;
square.color = color;
square.size = case_size;
name = ft_xpm_gen_file(square);
if (name == NULL)
return (NULL);
img = mlx_xpm_file_to_image(data->mlx,
name, &dimmension, &dimmension);
free(name);
return (img);
}
int ft_gen_assets(t_data *data) int ft_gen_assets(t_data *data)
{ {
char **colors; char **colors;
t_square square;
size_t i; size_t i;
int y;
char *name;
colors = ft_split(COLORS, '|'); colors = ft_split(COLORS, '|');
if (colors == NULL) if (colors == NULL)
@ -26,17 +41,13 @@ int ft_gen_assets(t_data *data)
i = 0; i = 0;
while (i < NB_COLORS) while (i < NB_COLORS)
{ {
square.color = colors[i]; data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
square.size = CASE_SIZE; if (data->assets[i] == NULL)
name = ft_xpm_gen_file(square); return (1);
data->assets[i] = mlx_xpm_file_to_image(data->mlx, data->assets[i + NB_COLORS] = ft_gen_asset(colors[i],
name, &y, &y); WINDOW_SIZE, data);
free(name); if (data->assets[i + NB_COLORS] == NULL)
square.size = WINDOW_SIZE; return (1);
name = ft_xpm_gen_file(square);
data->assets[i + NB_COLORS] = mlx_xpm_file_to_image(data->mlx,
name, &y, &y);
free(name);
i++; i++;
} }
ft_freer_tab_ultimate(1, colors); ft_freer_tab_ultimate(1, colors);

BIN
asset.o

Binary file not shown.

5
draw.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */ /* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
/* Updated: 2023/01/13 15:14:02 by cchauvet ### ########.fr */ /* Updated: 2023/01/13 16:04:19 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,6 +37,8 @@ static void ft_draw_foots(t_data *data)
{ {
char *foots; char *foots;
if (BONUS)
{
foots = ft_itoa(data->nb_foots); foots = ft_itoa(data->nb_foots);
if (foots == NULL) if (foots == NULL)
{ {
@ -46,6 +48,7 @@ static void ft_draw_foots(t_data *data)
mlx_string_put(data->mlx, data->window, 10, 10, 255, foots); mlx_string_put(data->mlx, data->window, 10, 10, 255, foots);
ft_printf("\r%s", foots); ft_printf("\r%s", foots);
free(foots); free(foots);
}
} }
int ft_draw_map(t_data *data) int ft_draw_map(t_data *data)

BIN
draw.o

Binary file not shown.

7
key.c
View File

@ -6,17 +6,16 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/09 18:35:27 by cchauvet #+# #+# */ /* Created: 2023/01/09 18:35:27 by cchauvet #+# #+# */
/* Updated: 2023/01/12 13:30:13 by cchauvet ### ########.fr */ /* Updated: 2023/01/13 15:40:38 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "solong.h" #include "solong.h"
static void ft_case_update(char *new_pos, char *player_pos, t_data *data) static void ft_case_update(char *new_pos, char *player_pos)
{ {
*new_pos = 'P'; *new_pos = 'P';
*player_pos = '0'; *player_pos = '0';
ft_printf("\r%d", data->nb_foots++);
} }
static void ft_epileptic_mod(t_data *data) static void ft_epileptic_mod(t_data *data)
@ -51,7 +50,7 @@ static void ft_move(t_data *data, char direction)
if (*new_pos == 'C') if (*new_pos == 'C')
data->map->nb_collectable--; data->map->nb_collectable--;
if (*new_pos == '0' || *new_pos == 'C') if (*new_pos == '0' || *new_pos == 'C')
ft_case_update(new_pos, &data->map->patern[tab[1]][tab[0]], data); ft_case_update(new_pos, &data->map->patern[tab[1]][tab[0]]);
if (*new_pos == 'E') if (*new_pos == 'E')
{ {
if (data->map->nb_collectable == 0) if (data->map->nb_collectable == 0)

BIN
key.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
m
View File

@ -1,3 +0,0 @@
111111
1PCBE1
111111

4
main.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */ /* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
/* Updated: 2023/01/13 14:25:33 by cchauvet ### ########.fr */ /* Updated: 2023/01/13 15:44:38 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -65,7 +65,7 @@ int main(int ac, char **av)
{ {
t_data data; t_data data;
if (ac != 2) if (ac != 2 || ft_strcmp(av[1] + ft_strlen(av[1]) - 4, ".ber"))
{ {
ft_printf("Map error\n"); ft_printf("Map error\n");
return (1); return (1);

BIN
main.o

Binary file not shown.

BIN
map.o

Binary file not shown.

3
n
View File

@ -1,3 +0,0 @@
1111
1P01
1111

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/05 20:14:44 by cchauvet #+# #+# */ /* Created: 2023/01/05 20:14:44 by cchauvet #+# #+# */
/* Updated: 2023/01/13 14:15:05 by cchauvet ### ########.fr */ /* Updated: 2023/01/13 15:47:42 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -43,7 +43,9 @@ int ft_test_map_content1(t_map *map)
x = 0; x = 0;
while (x < map->x_len) while (x < map->x_len)
{ {
if (ft_is_in("01CEPB", map->patern[y][x]) == 0) if (!BONUS && ft_is_in("01CEP", map->patern[y][x]) == 0)
return (0);
if (BONUS && ft_is_in("01CEPB", map->patern[y][x]) == 0)
return (0); return (0);
if (map->patern[y][x] == 'C') if (map->patern[y][x] == 'C')
nb_collectable++; nb_collectable++;
@ -105,13 +107,17 @@ int ft_test_map_is_surronded(t_map map)
int ft_map_is_correct(t_map *map) int ft_map_is_correct(t_map *map)
{ {
int i; if (!ft_test_map_dimmention(map))
return (0);
i = ft_test_map_dimmention(map); if (!ft_test_map_content1(map))
i += ft_test_map_content1(map); return (0);
i += ft_test_map_content2(map->patern); if (!ft_test_map_content2(map->patern))
i += ft_test_map_dimmention(map); return (0);
i += ft_test_map_is_surronded(*map); if (!ft_test_map_dimmention(map))
i += ft_test_map_is_finishable(map); return (0);
return (i == 6); if (!ft_test_map_is_surronded(*map))
return (0);
if (!ft_test_map_is_finishable(map))
return (0);
return (1);
} }

BIN
parsing.o

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/12 16:17:20 by cchauvet #+# #+# */ /* Created: 2023/01/12 16:17:20 by cchauvet #+# #+# */
/* Updated: 2023/01/13 14:48:02 by cchauvet ### ########.fr */ /* Updated: 2023/01/13 16:07:39 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,43 +14,65 @@
static void ft_collector(char **patern, size_t x, size_t y) static void ft_collector(char **patern, size_t x, size_t y)
{ {
if (BONUS)
{
if (ft_is_in("1B", patern[y][x]))
return ;
}
else
if (patern[y][x] == '1') if (patern[y][x] == '1')
return ; return ;
patern[y][x] = '1'; patern[y][x] = '1';
ft_collector(patern, y - 1, x); ft_collector(patern, x, y - 1);
ft_collector(patern, y, x + 1); ft_collector(patern, x + 1, y);
ft_collector(patern, y + 1, x); ft_collector(patern, x, y + 1);
ft_collector(patern, y, x - 1); ft_collector(patern, x - 1, y);
ft_printf("%S\n", patern);
} }
int ft_test_map_is_finishable(t_map *map) static char **ft_patern_dup(char **patern)
{ {
size_t i;
int ok;
char **patern2; char **patern2;
size_t i;
i = 0; i = 0;
while (map->patern[i] != NULL) while (patern[i] != NULL)
i++; i++;
patern2 = ft_calloc(i + 1, sizeof(char *)); patern2 = ft_calloc(i + 1, sizeof(char *));
if (patern2 == NULL) if (patern2 == NULL)
return (0); return (0);
i = 0; i = 0;
while (map->patern[i] != NULL) while (patern[i] != NULL)
{ {
patern2[i] = ft_strdup(map->patern[i]); patern2[i] = ft_strdup(patern[i]);
if (patern2[i] == NULL) if (patern2[i] == NULL)
{ {
ft_cancel(patern2, i); ft_cancel(patern2, i);
return (0); return (NULL);
} }
i++; i++;
} }
patern2[i] = NULL; patern2[i] = NULL;
return (patern2);
}
int ft_test_map_is_finishable(t_map *map)
{
size_t i;
int ok;
char **patern;
patern = ft_patern_dup(map->patern);
if (patern == NULL)
return (1);
ft_fill_pos(map); ft_fill_pos(map);
ft_collector(patern2, map->player_pos[0], map->player_pos[1]); ft_collector(patern, map->player_pos[0], map->player_pos[1]);
ok = ft_test_map_content2(patern2); i = 1;
ft_freer_tab_ultimate(1, patern2); ok = 1;
while (patern[i + 1] != NULL)
{
if (ft_is_in(patern[i], 'C') || ft_is_in(patern[i], 'E'))
ok = 0;
i++;
}
ft_freer_tab_ultimate(1, patern);
return (ok); return (ok);
} }

Binary file not shown.

BIN
so_long

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */ /* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
/* Updated: 2023/01/13 14:13:30 by cchauvet ### ########.fr */ /* Updated: 2023/01/13 15:50:03 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,6 @@
# define SOLONG_H # define SOLONG_H
# include "libftx/libftx.h" # include "libftx/libftx.h"
# define XPM_PATH "./textures/" # define XPM_PATH "./textures/"
# include <stdio.h>
# include <unistd.h> # include <unistd.h>
# include <fcntl.h> # include <fcntl.h>
# include "minilibx-linux/mlx.h" # include "minilibx-linux/mlx.h"
@ -25,6 +24,7 @@
# define RENDER_DISTANCE 5 # define RENDER_DISTANCE 5
# define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE # define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE
# define ABS(Value) (Value * ((Value > 0) - (Value < 0))) # define ABS(Value) (Value * ((Value > 0) - (Value < 0)))
# define BONUS 0
typedef struct s_square typedef struct s_square
{ {

BIN
xpm.o

Binary file not shown.