CA MARCHE
This commit is contained in:
parent
4ab400b5e4
commit
f84f98fe21
41
asset.c
41
asset.c
@ -6,19 +6,34 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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)
|
||||
{
|
||||
char **colors;
|
||||
t_square square;
|
||||
size_t i;
|
||||
int y;
|
||||
char *name;
|
||||
|
||||
colors = ft_split(COLORS, '|');
|
||||
if (colors == NULL)
|
||||
@ -26,17 +41,13 @@ int ft_gen_assets(t_data *data)
|
||||
i = 0;
|
||||
while (i < NB_COLORS)
|
||||
{
|
||||
square.color = colors[i];
|
||||
square.size = CASE_SIZE;
|
||||
name = ft_xpm_gen_file(square);
|
||||
data->assets[i] = mlx_xpm_file_to_image(data->mlx,
|
||||
name, &y, &y);
|
||||
free(name);
|
||||
square.size = WINDOW_SIZE;
|
||||
name = ft_xpm_gen_file(square);
|
||||
data->assets[i + NB_COLORS] = mlx_xpm_file_to_image(data->mlx,
|
||||
name, &y, &y);
|
||||
free(name);
|
||||
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
|
||||
if (data->assets[i] == NULL)
|
||||
return (1);
|
||||
data->assets[i + NB_COLORS] = ft_gen_asset(colors[i],
|
||||
WINDOW_SIZE, data);
|
||||
if (data->assets[i + NB_COLORS] == NULL)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
ft_freer_tab_ultimate(1, colors);
|
||||
|
5
draw.c
5
draw.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
if (BONUS)
|
||||
{
|
||||
foots = ft_itoa(data->nb_foots);
|
||||
if (foots == NULL)
|
||||
{
|
||||
@ -47,6 +49,7 @@ static void ft_draw_foots(t_data *data)
|
||||
ft_printf("\r%s", foots);
|
||||
free(foots);
|
||||
}
|
||||
}
|
||||
|
||||
int ft_draw_map(t_data *data)
|
||||
{
|
||||
|
7
key.c
7
key.c
@ -6,17 +6,16 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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';
|
||||
*player_pos = '0';
|
||||
ft_printf("\r%d", data->nb_foots++);
|
||||
}
|
||||
|
||||
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')
|
||||
data->map->nb_collectable--;
|
||||
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 (data->map->nb_collectable == 0)
|
||||
|
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.
BIN
libftx/libftx.a
BIN
libftx/libftx.a
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.
4
main.c
4
main.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
if (ac != 2)
|
||||
if (ac != 2 || ft_strcmp(av[1] + ft_strlen(av[1]) - 4, ".ber"))
|
||||
{
|
||||
ft_printf("Map error\n");
|
||||
return (1);
|
||||
|
28
parsing.c
28
parsing.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
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);
|
||||
if (map->patern[y][x] == 'C')
|
||||
nb_collectable++;
|
||||
@ -105,13 +107,17 @@ int ft_test_map_is_surronded(t_map map)
|
||||
|
||||
int ft_map_is_correct(t_map *map)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = ft_test_map_dimmention(map);
|
||||
i += ft_test_map_content1(map);
|
||||
i += ft_test_map_content2(map->patern);
|
||||
i += ft_test_map_dimmention(map);
|
||||
i += ft_test_map_is_surronded(*map);
|
||||
i += ft_test_map_is_finishable(map);
|
||||
return (i == 6);
|
||||
if (!ft_test_map_dimmention(map))
|
||||
return (0);
|
||||
if (!ft_test_map_content1(map))
|
||||
return (0);
|
||||
if (!ft_test_map_content2(map->patern))
|
||||
return (0);
|
||||
if (!ft_test_map_dimmention(map))
|
||||
return (0);
|
||||
if (!ft_test_map_is_surronded(*map))
|
||||
return (0);
|
||||
if (!ft_test_map_is_finishable(map))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
54
parsing2.c
54
parsing2.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
if (BONUS)
|
||||
{
|
||||
if (ft_is_in("1B", patern[y][x]))
|
||||
return ;
|
||||
}
|
||||
else
|
||||
if (patern[y][x] == '1')
|
||||
return ;
|
||||
patern[y][x] = '1';
|
||||
ft_collector(patern, y - 1, x);
|
||||
ft_collector(patern, y, x + 1);
|
||||
ft_collector(patern, y + 1, x);
|
||||
ft_collector(patern, y, x - 1);
|
||||
ft_printf("%S\n", patern);
|
||||
ft_collector(patern, x, y - 1);
|
||||
ft_collector(patern, x + 1, y);
|
||||
ft_collector(patern, x, y + 1);
|
||||
ft_collector(patern, x - 1, y);
|
||||
}
|
||||
|
||||
int ft_test_map_is_finishable(t_map *map)
|
||||
static char **ft_patern_dup(char **patern)
|
||||
{
|
||||
size_t i;
|
||||
int ok;
|
||||
char **patern2;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (map->patern[i] != NULL)
|
||||
while (patern[i] != NULL)
|
||||
i++;
|
||||
patern2 = ft_calloc(i + 1, sizeof(char *));
|
||||
if (patern2 == NULL)
|
||||
return (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)
|
||||
{
|
||||
ft_cancel(patern2, i);
|
||||
return (0);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
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_collector(patern2, map->player_pos[0], map->player_pos[1]);
|
||||
ok = ft_test_map_content2(patern2);
|
||||
ft_freer_tab_ultimate(1, patern2);
|
||||
ft_collector(patern, map->player_pos[0], map->player_pos[1]);
|
||||
i = 1;
|
||||
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);
|
||||
}
|
||||
|
BIN
parsing2.o
BIN
parsing2.o
Binary file not shown.
4
solong.h
4
solong.h
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
# include "libftx/libftx.h"
|
||||
# define XPM_PATH "./textures/"
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include "minilibx-linux/mlx.h"
|
||||
@ -25,6 +24,7 @@
|
||||
# define RENDER_DISTANCE 5
|
||||
# define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE
|
||||
# define ABS(Value) (Value * ((Value > 0) - (Value < 0)))
|
||||
# define BONUS 0
|
||||
|
||||
typedef struct s_square
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user