fix: can't open room if exit "blocked" by ketchup
This commit is contained in:
parent
fb966caa48
commit
0e745f82b3
11 changed files with 39 additions and 29 deletions
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/15 17:42:06 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 15:56:04 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -21,7 +21,8 @@ typedef t_object (*t_object_init)(t_memclass);
|
|||
typedef struct s_objecttype
|
||||
{
|
||||
t_object_init init;
|
||||
bool solid;
|
||||
bool solid_snas;
|
||||
bool solid_firsk;
|
||||
t_point (*loop)(t_object *, t_point pos);
|
||||
void (*draw)(t_object *, t_point p);
|
||||
// Called when a character want to walk through this object.
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/10 18:13:05 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 13:50:36 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 16:03:39 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -15,6 +15,6 @@
|
|||
|
||||
# include "includes.h"
|
||||
|
||||
t_direction pathfinding(t_point start, t_point finish, bool solid_bridge);
|
||||
t_direction pathfinding(t_point start, t_point finish, bool for_firsk);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
1111111111
|
||||
1PB0000FC1
|
||||
10B0000001
|
||||
10B0000C01
|
||||
10B00000C1
|
||||
10B0000001
|
||||
10B0000C01
|
||||
10B00000C1
|
||||
10B0000001
|
||||
10B0000C01
|
||||
10B00000C1
|
||||
10B0000001
|
||||
10B0000C01
|
||||
11111111B1
|
||||
1E00000001
|
||||
1111111111
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/08 15:01:16 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/15 17:43:20 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 15:56:50 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -47,7 +47,8 @@ static bool exit_walk_through(
|
|||
t_object exit_init(t_memclass mc)
|
||||
{
|
||||
static const t_objecttype type
|
||||
= {solid: true, init: exit_init, loop: exit_loop, draw: exit_draw,
|
||||
= {solid_firsk: true, solid_snas: true,
|
||||
init: exit_init, loop: exit_loop, draw: exit_draw,
|
||||
walk_through: exit_walk_through};
|
||||
t_object r;
|
||||
t_exit_data *data;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/11 13:55:04 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 13:51:12 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 15:57:21 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -36,7 +36,8 @@ static void firsk_draw(t_object *obj, t_point p)
|
|||
t_object firsk_init(t_memclass mc)
|
||||
{
|
||||
static const t_objecttype type
|
||||
= {init: firsk_init, loop: firsk_loop, draw: firsk_draw,
|
||||
= {solid_firsk: false, solid_snas: false,
|
||||
init: firsk_init, loop: firsk_loop, draw: firsk_draw,
|
||||
walk_through: NULL};
|
||||
static const t_character_sprites sprites = {
|
||||
still: SPR_FIRSK,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/15 19:53:54 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 15:57:45 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -38,7 +38,8 @@ t_object ketchup_init(t_memclass mc)
|
|||
{
|
||||
static const t_objecttype type
|
||||
= {
|
||||
solid: true,
|
||||
solid_firsk: true,
|
||||
solid_snas: false,
|
||||
init: ketchup_init,
|
||||
loop: ketchup_loop,
|
||||
draw: ketchup_draw,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/17 16:20:51 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 15:58:11 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -54,7 +54,8 @@ static void snas_draw(t_object *obj, t_point p)
|
|||
t_object snas_init(t_memclass mc)
|
||||
{
|
||||
static const t_objecttype type
|
||||
= {solid: false, init: snas_init, loop: snas_loop, draw: snas_draw,
|
||||
= {solid_firsk: false, solid_snas: false,
|
||||
init: snas_init, loop: snas_loop, draw: snas_draw,
|
||||
walk_through: snas_walk_through};
|
||||
static const t_character_sprites sprites = {
|
||||
still: SPR_SNAS,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/15 17:44:49 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 15:58:27 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -27,7 +27,8 @@ static void wall_draw(t_object *obj, t_point p)
|
|||
t_object wall_init(t_memclass mc)
|
||||
{
|
||||
static const t_objecttype type
|
||||
= {solid: true, init: wall_init, loop: wall_loop, draw: wall_draw,
|
||||
= {solid_firsk: true, solid_snas: true,
|
||||
init: wall_init, loop: wall_loop, draw: wall_draw,
|
||||
walk_through: NULL};
|
||||
t_object r;
|
||||
t_wall_data *data;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/10 18:19:19 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 14:00:51 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 16:03:05 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -63,7 +63,7 @@ static t_direction pathfinding_checkdirections(
|
|||
return (NO_DIRECTION);
|
||||
}
|
||||
|
||||
t_direction pathfinding(t_point start, t_point finish, bool solid_bridge)
|
||||
t_direction pathfinding(t_point start, t_point finish, bool for_firsk)
|
||||
{
|
||||
const t_pathfinding_env env = {
|
||||
start: start,
|
||||
|
@ -77,7 +77,7 @@ t_direction pathfinding(t_point start, t_point finish, bool solid_bridge)
|
|||
|
||||
if (start.x == finish.x && start.y == finish.y)
|
||||
return (NO_DIRECTION);
|
||||
map = init_map(env.mc, solid_bridge);
|
||||
map = init_map(env.mc, for_firsk);
|
||||
tocheck = inittochecklist(env.mc, map.dim, start);
|
||||
case_checking = start;
|
||||
while (case_checking.x != -1 || case_checking.y != -1)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/15 17:35:13 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 14:03:03 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 16:05:23 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -24,15 +24,19 @@ void path_map_case_init(t_point p, void **el, void *args_p)
|
|||
to_check: false,
|
||||
before: point_init(-1, -1),
|
||||
solid: p.x == 0 || p.x == room.width - 1 || p.y == 0
|
||||
|| p.y == room.height - 1 || (obj && obj->type.solid)
|
||||
|| (surface->meta->first_frame == BRIDGE && args->solid_bridge)
|
||||
|| p.y == room.height - 1 || (
|
||||
obj && (
|
||||
(args->for_firsk && obj->type.solid_firsk)
|
||||
|| (!args->for_firsk && obj->type.solid_snas)
|
||||
))
|
||||
|| (args->for_firsk && surface->meta->first_frame == BRIDGE)
|
||||
};
|
||||
|
||||
*el = mem_alloc(error_err, args->mc, sizeof(r));
|
||||
**(t_path_map_case **)el = r;
|
||||
}
|
||||
|
||||
t_path_map init_map(t_memclass mc, bool solid_bridge)
|
||||
t_path_map init_map(t_memclass mc, bool for_firsk)
|
||||
{
|
||||
t_path_map r;
|
||||
t_path_map_case_init_args args;
|
||||
|
@ -41,7 +45,7 @@ t_path_map init_map(t_memclass mc, bool solid_bridge)
|
|||
r.dim.y = g_env.room.height;
|
||||
r = map_init(mc, point_init(g_env.room.width, g_env.room.height));
|
||||
args.mc = mc;
|
||||
args.solid_bridge = solid_bridge;
|
||||
args.for_firsk = for_firsk;
|
||||
map_foreach(&r, path_map_case_init, &args);
|
||||
return (r);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/10 18:21:55 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 14:01:33 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 16:03:22 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -37,13 +37,13 @@ typedef struct s_path_map_case
|
|||
typedef struct s_path_map_case_init_args
|
||||
{
|
||||
t_memclass *mc;
|
||||
bool solid_bridge;
|
||||
bool for_firsk;
|
||||
} t_path_map_case_init_args;
|
||||
|
||||
typedef t_map t_path_map;
|
||||
|
||||
void path_map_case_init(t_point p, void **el, void *mc);
|
||||
t_path_map init_map(t_memclass mc, bool solid_bridge);
|
||||
t_path_map init_map(t_memclass mc, bool for_firsk);
|
||||
t_tochecklist inittochecklist(t_memclass mc, t_point dim, t_point first);
|
||||
void addtocheck(t_tochecklist *tocheck, t_point p);
|
||||
t_point nexttocheck(t_tochecklist *tocheck);
|
||||
|
|
Loading…
Add table
Reference in a new issue