avancement
This commit is contained in:
parent
8c14fce5ee
commit
c0a0d33aed
4
Makefile
4
Makefile
|
@ -6,12 +6,12 @@
|
|||
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
|
||||
# Updated: 2022/12/12 17:21:15 by erey-bet ### ########.fr #
|
||||
# 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/map.c games/player.c games/position.c games/quit.c games/render.c ${GNL}
|
||||
SRCS = games/init.c games/map.c games/player.c games/enemy.c games/position.c games/quit.c games/render.c ${GNL}
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
LIBS = libft/libft.a minilibx-linux/libmlx.a
|
||||
CC = clang
|
||||
|
|
|
@ -1,30 +1,78 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* enemy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 14:08:08 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/04 17:04:14 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
|
||||
void distance_player(char **map, int x, int y, int nbr)
|
||||
{
|
||||
map[x][y] = nbr + '0';
|
||||
if (map[x][y + 1] != '1' && map[x][y + 1] == '0')
|
||||
distance_player(map, x, y + 1, nbr + 1)
|
||||
distance_player(map, x, y + 1, nbr + 1);
|
||||
if (map[x + 1][y] != '1' && map[x + 1][y] == '0')
|
||||
distance_player(map, x + 1, y, nbr + 1)
|
||||
distance_player(map, x + 1, y, nbr + 1);
|
||||
if (map[x - 1][y] != '1' && map[x + 1][y] == '0')
|
||||
distance_player(map, x - 1, y, nbr + 1)
|
||||
distance_player(map, x - 1, y, nbr + 1);
|
||||
if (map[x][y - 1] != '1' && map[x][y - 1] == '0')
|
||||
distance_player(map, x, y - 1, nbr + 1)
|
||||
distance_player(map, x, y - 1, nbr + 1);
|
||||
}
|
||||
|
||||
t_xy path_finding(t_data *data, int x, int y)
|
||||
{
|
||||
t_xy new_pos;
|
||||
char **map_cpy;
|
||||
|
||||
if (cur.x == ply.x && cur.y == ply.y)
|
||||
return (0);
|
||||
map_cpy = ft_strdups(data->map);
|
||||
distance_player(map_cpy, x, y, 0);
|
||||
|
||||
int i;
|
||||
char **map;
|
||||
|
||||
new_pos.x = x;
|
||||
new_pos.y = y;
|
||||
map = ft_strdups(data->map);
|
||||
distance_player(map, x, y, 0);
|
||||
i = -1;
|
||||
if (map[x][y + 1] != '1')
|
||||
{
|
||||
i = map[x][y + 1];
|
||||
new_pos.y = y + 1;
|
||||
}
|
||||
if (map[x + 1][y] != '1')
|
||||
if (i == -1 || map[x + 1][y] < i)
|
||||
{
|
||||
i = map[x + 1][y];
|
||||
new_pos.x = x + 1;
|
||||
}
|
||||
if (map[x - 1][y] != '1' && map[x + 1][y] > '0')
|
||||
if (i == -1 || map[x - 1][y] < i)
|
||||
{
|
||||
i = map[x - 1][y];
|
||||
new_pos.x = x - 1;
|
||||
}
|
||||
if (map[x][y - 1] != '1' && map[x][y - 1] == '0')
|
||||
if (i == -1 || map[x][y - 1] < i)
|
||||
{
|
||||
i = map[x][y - 1];
|
||||
new_pos.y = y - 1;
|
||||
}
|
||||
i = 0;
|
||||
while (map[i])
|
||||
free(map[i++]);
|
||||
free(map);
|
||||
return (new_pos);
|
||||
}
|
||||
|
||||
void move_enemy(t_data *data)
|
||||
{
|
||||
|
||||
t_xy pos;
|
||||
|
||||
set_element(data, data->y_ene, data->x_ene, '0');
|
||||
pos = path_finding(data, data->x_ene, data->y_ene);
|
||||
set_element(data, pos.y, pos.x, 'e');
|
||||
data->x_ene = pos.x;
|
||||
data->y_ene = pos.y;
|
||||
}
|
||||
|
|
BIN
games/enemy.o
Normal file
BIN
games/enemy.o
Normal file
Binary file not shown.
13
games/init.c
13
games/init.c
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:18 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/02 16:28:52 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/01/04 17:07:05 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -76,13 +76,14 @@ int render(t_data *data)
|
|||
char *str_move;
|
||||
t_xy *pos;
|
||||
|
||||
/*if (data->tick >= 20 && data->x_ene != -1)
|
||||
if (data->tick >= 75000 && data->x_ene != -1 && data->y_ene != -1)
|
||||
{
|
||||
data->tick = 0;
|
||||
move_enemy(data);
|
||||
draw(data);
|
||||
}
|
||||
else if (data->x_ene != -1)
|
||||
data->tick++;*/
|
||||
else if (data->x_ene != -1 && data->y_ene != -1)
|
||||
data->tick++;
|
||||
if (data->update == 1)
|
||||
{
|
||||
if (data->x_ene != -1 && has_element(data->map, '3'))
|
||||
|
@ -91,8 +92,8 @@ int render(t_data *data)
|
|||
if (data->x_player != pos->x || data->y_player != pos->y)
|
||||
{
|
||||
set_element(data, pos->x, pos->y, 'e');
|
||||
data->x_ene = pos->x;
|
||||
data->y_ene = pos->y;
|
||||
data->x_ene = pos->y;
|
||||
data->y_ene = pos->x;
|
||||
}
|
||||
free(pos);
|
||||
}
|
||||
|
|
BIN
games/init.o
BIN
games/init.o
Binary file not shown.
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:42 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/02 16:24:06 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/01/04 16:47:26 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/10 17:59:18 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/12/14 16:12:41 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/01/04 14:06:35 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -73,6 +73,10 @@ void 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);
|
||||
|
||||
|
||||
// Position
|
||||
t_xy *get_position(char **map, char c);
|
||||
int has_element(char **map, char c);
|
||||
|
|
Loading…
Reference in a new issue