Avancement
This commit is contained in:
parent
191fba3a12
commit
5e57f44071
2
Makefile
2
Makefile
|
@ -15,7 +15,7 @@ SRCS = games/init.c games/map.c games/player.c games/position.c games/quit.c gam
|
|||
OBJS = ${SRCS:.c=.o}
|
||||
LIBS = libft/libft.a minilibx-linux/libmlx.a
|
||||
CC = clang
|
||||
CFLAGS = -gdwarf-4 -g -Wall -Wextra -Werror
|
||||
CFLAGS = -g -Wall -Wextra -Werror
|
||||
NAME = so_long
|
||||
|
||||
# PENSER ENLEVER -G
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
int pathfinding(char **map, char **map_cpy, int x, int y, int *check)
|
||||
int path_finding(char **map_cpy, t_xy cur, t_xy ply, int nbr)
|
||||
{
|
||||
if (map[x][y] == 'E')
|
||||
return (1);
|
||||
if (cur.x == ply.x && cur.y == ply.y)
|
||||
return (nbr);
|
||||
map_cpy[x][y] = 'x';
|
||||
if (map_cpy[x][y + 1] != '1' && map_cpy[x][y + 1] != 'x')
|
||||
if (is_possible(map, map_cpy, x, y + 1, check))
|
||||
*check = 1;
|
||||
if (is_possible(map, map_cpy, x, y + 1, nbr++))
|
||||
|
||||
if (map_cpy[x + 1][y] != '1' && map_cpy[x + 1][y] != 'x')
|
||||
if (is_possible(map, map_cpy, x + 1, y, check))
|
||||
*check = 1;
|
||||
if (is_possible(map, map_cpy, x + 1, y, nbr))
|
||||
|
||||
if (map_cpy[x - 1][y] != '1' && map_cpy[x - 1][y] != 'x')
|
||||
if (is_possible(map, map_cpy, x - 1, y, check))
|
||||
*check = 1;
|
||||
if (is_possible(map, map_cpy, x - 1, y, nbr))
|
||||
*check =
|
||||
if (map_cpy[x][y - 1] != '1' && map_cpy[x][y - 1] != 'x')
|
||||
if (is_possible(map, map_cpy, x, y - 1, check))
|
||||
if (is_possible(map, map_cpy, x, y - 1, nbr))
|
||||
*check = 1;
|
||||
if (!has_element(map_cpy, 'C') && *check)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
29
games/init.c
29
games/init.c
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:18 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/01 19:49:56 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
|
||||
int key_hook(int key, t_data *data)
|
||||
|
@ -61,18 +73,28 @@ int trgb(int t, int r, int g, int b)
|
|||
|
||||
int render(t_data *data)
|
||||
{
|
||||
char *str_move;
|
||||
t_xy pos;
|
||||
|
||||
/*if (data->tick >= 5 && data->x_ene != -1)
|
||||
{
|
||||
data->tick = 0;
|
||||
move_enemy(data);
|
||||
}
|
||||
else
|
||||
else if (data->x_ene != -1)
|
||||
data->tick++;*/
|
||||
if (data->update == 1)
|
||||
{
|
||||
if (has_element(data->map, '3'))
|
||||
{
|
||||
pos = get_position(data->map, '3');
|
||||
|
||||
}
|
||||
draw(data);
|
||||
mlx_put_image_to_window(data->mlx, data->mlx_win, data->imgs.bg, 0, 0);
|
||||
mlx_string_put(data->mlx, data->mlx_win, 100, 100, trgb(0, 150, 0, 0), ft_itoa(data->move));
|
||||
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;
|
||||
}
|
||||
return (0);
|
||||
|
@ -117,7 +139,8 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
t_data data;
|
||||
|
||||
(void)argc;
|
||||
if (argc != 2)
|
||||
return (0);
|
||||
(void)argv;
|
||||
init_data(&data);
|
||||
if (get_map(argv, &data) == NULL)
|
||||
|
|
19
games/map.c
19
games/map.c
|
@ -7,6 +7,11 @@ void *read_map(char *argv[], t_data *data)
|
|||
int i;
|
||||
int fd;
|
||||
|
||||
if (argv[1][ft_strlen(argv[1]) - 1] != 'r' ||
|
||||
argv[1][ft_strlen(argv[1]) - 2] != 'e' ||
|
||||
argv[1][ft_strlen(argv[1]) - 3] != 'b' ||
|
||||
argv[1][ft_strlen(argv[1]) - 4] != '.')
|
||||
return (NULL);
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (fd == -1)
|
||||
return NULL;
|
||||
|
@ -83,22 +88,22 @@ int is_surrounded_by_wall(char **map, int h_map)
|
|||
return (1);
|
||||
}
|
||||
|
||||
int is_possible(char **map, char **map_cpy, int x, int y, int *check)
|
||||
int is_possible(char **map_cpy, int x, int y, int *check)
|
||||
{
|
||||
if (map[x][y] == 'E')
|
||||
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, map_cpy, x, y + 1, check))
|
||||
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, map_cpy, x + 1, y, check))
|
||||
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, map_cpy, x - 1, y, check))
|
||||
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, map_cpy, x, y - 1, check))
|
||||
if (is_possible(map_cpy, x, y - 1, check))
|
||||
*check = 1;
|
||||
if (!has_element(map_cpy, 'C') && *check)
|
||||
return (1);
|
||||
|
@ -156,7 +161,7 @@ void *get_map(char *argv[], t_data *data)
|
|||
data = set_position_player(data, get_position(data->map, 'P'));
|
||||
i = 0;
|
||||
map_cpy = ft_strdups(data->map);
|
||||
if (!is_possible(data->map, map_cpy, data->y_player, data->x_player, &i))
|
||||
if (!is_possible(map_cpy, data->y_player, data->x_player, &i))
|
||||
{
|
||||
write(1, "Error\nLa carte est impossible a faire", 37);
|
||||
return (NULL);
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* player.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:32 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/01 19:39:28 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
|
||||
static int get_new_element(t_data *data, int x, int y)
|
||||
|
@ -8,6 +20,9 @@ static int get_new_element(t_data *data, int x, int y)
|
|||
static void set_new_element(t_data *data, int x, int y)
|
||||
{
|
||||
data->map[data->y_player + y][data->x_player + x] = '0';
|
||||
if (!has_element(data->map, 'C'))
|
||||
data->map[data->y_player + y][data->x_player + x] = '3';
|
||||
|
||||
}
|
||||
|
||||
void *set_position_player(t_data *data, t_xy *xy)
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* position.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:59 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/12/29 18:07:01 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
|
||||
t_xy *get_position(char **map, char c)
|
||||
|
|
12
games/quit.c
12
games/quit.c
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* quit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
|
||||
int end(t_data *data)
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* render.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:42 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/01 19:39:55 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
|
||||
static void *assets(t_data *data, int x, int y)
|
||||
|
@ -9,15 +21,13 @@ static void *assets(t_data *data, int x, int y)
|
|||
dist = sqrt(pow(x - data->x_player, 2) + pow(y - data->y_player, 2)) - 1;
|
||||
if (dist > 2)
|
||||
dist = 2;
|
||||
if (c == '0' || c == 'P')
|
||||
return (data->imgs.bg);
|
||||
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]);
|
||||
return (NULL);
|
||||
return (data->imgs.bg);
|
||||
}
|
||||
|
||||
void draw(t_data *data)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/09/28 16:32:55 by erey-bet ### ########.fr */
|
||||
/* Updated: 2022/12/29 18:05:24 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
14
so_long.c
14
so_long.c
|
@ -1,14 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* so_long.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/09 14:18:18 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/12/14 17:15:45 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "so_long.h"
|
||||
#include <stdio.h>
|
Loading…
Reference in a new issue