feat: bridge

This commit is contained in:
mcolonna 2024-04-18 14:41:00 +02:00
parent 3ca6fb18b2
commit fb966caa48
23 changed files with 1189 additions and 728 deletions

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 16:27:06 by mcolonna #+# #+# */
/* Updated: 2024/04/17 17:50:28 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 13:57:37 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,12 +16,14 @@
* Path of each asset relative to assets/, without extension.
*/
const t_assetmeta g_assetsmap[NB_ASSETS] = {
{"floor/1", 50, 100, 50, 100, true},
{"floor/2", 50, 100, 50, 100, true},
{"floor/1", 50, 100, 50, 125, true},
{"floor/2", 50, 100, 50, 125, true},
// WALL
{"wall/border_top", 50, 100, 50, 100, true},
{"wall/border_top", 50, 100, 50, 125, true},
{"wall/border_bottom", 50, 100, 50, 100, true},
{"wall/inner", 50, 100, 30, 100, false},
// BRIDGE
{"wall/bridge", 50, 100, 50, 125, false},
// OBJECTS
// snas
{"object/snas/down", 50, 100, 30, 100, false},

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */
/* Updated: 2024/04/17 17:49:13 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 14:00:05 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,7 @@ const t_spritemeta g_spritesmap[NB_SPRITES] = {
{WALL_BORDER_BOTTOM, 50, 50, ANIMATION, 1, 1},
{FLOOR_1, 50, 50, ANIMATION, 1, 1},
{FLOOR_2, 50, 50, ANIMATION, 1, 1},
{BRIDGE, 50, 50, ANIMATION, 1, 1},
{OBJECT_SNAS, 50, 50, CHARACTER_STILL, 0, 0},
{OBJECT_SNAS_WALK_DOWN_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_SNAS_WALK_UP_1, 50, 50, ANIMATION, 4, 3},

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/11 13:55:04 by mcolonna #+# #+# */
/* Updated: 2024/04/17 16:19:43 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 13:51:12 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
static t_direction firsk_brain(t_point pos)
{
return (pathfinding(pos, room_find(snas_init)));
return (pathfinding(pos, room_find(snas_init), true));
}
static t_point firsk_loop(t_object *obj, t_point pos)

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/10 18:19:19 by mcolonna #+# #+# */
/* Updated: 2024/04/15 17:38:06 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 14:00:51 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -63,7 +63,7 @@ static t_direction pathfinding_checkdirections(
return (NO_DIRECTION);
}
t_direction pathfinding(t_point start, t_point finish)
t_direction pathfinding(t_point start, t_point finish, bool solid_bridge)
{
const t_pathfinding_env env = {
start: start,
@ -77,7 +77,7 @@ t_direction pathfinding(t_point start, t_point finish)
if (start.x == finish.x && start.y == finish.y)
return (NO_DIRECTION);
map = init_map(env.mc);
map = init_map(env.mc, solid_bridge);
tocheck = inittochecklist(env.mc, map.dim, start);
case_checking = start;
while (case_checking.x != -1 || case_checking.y != -1)

View file

@ -6,36 +6,43 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/15 17:35:13 by mcolonna #+# #+# */
/* Updated: 2024/04/15 17:37:46 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 14:03:03 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
#include "pathfinding_utils.h"
void path_map_case_init(t_point p, void **el, void *mc)
void path_map_case_init(t_point p, void **el, void *args_p)
{
const t_room room = g_env.room;
const t_object *obj = room.objects[p.y * room.width + p.x];
const t_path_map_case r = {
const t_path_map_case_init_args *args = (t_path_map_case_init_args *)args_p;
const t_room room = g_env.room;
const t_object *obj = room.objects[p.y * room.width + p.x];
const t_sprite *surface
= &room.surfaces[p.y * room.width + p.x];
const t_path_map_case r = {
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)
};
*el = mem_alloc(error_err, mc, sizeof(r));
*el = mem_alloc(error_err, args->mc, sizeof(r));
**(t_path_map_case **)el = r;
}
t_path_map init_map(t_memclass mc)
t_path_map init_map(t_memclass mc, bool solid_bridge)
{
t_path_map r;
t_path_map r;
t_path_map_case_init_args args;
r.dim.x = g_env.room.width;
r.dim.y = g_env.room.height;
r = map_init(mc, point_init(g_env.room.width, g_env.room.height));
map_foreach(&r, path_map_case_init, mc);
args.mc = mc;
args.solid_bridge = solid_bridge;
map_foreach(&r, path_map_case_init, &args);
return (r);
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/10 18:21:55 by mcolonna #+# #+# */
/* Updated: 2024/04/15 17:37:42 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 14:01:33 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,10 +34,16 @@ typedef struct s_path_map_case
t_point before;
} t_path_map_case;
typedef struct s_path_map_case_init_args
{
t_memclass *mc;
bool solid_bridge;
} 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);
t_path_map init_map(t_memclass mc, bool solid_bridge);
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);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:11:29 by mcolonna #+# #+# */
/* Updated: 2024/04/17 14:14:45 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 14:36:25 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,7 @@ static t_room room_fromfile3(t_const_string path, t_room *room)
{
int x;
int y;
int i;
room_checkwallsallaround(path, room);
x = -1;
@ -25,18 +26,17 @@ static t_room room_fromfile3(t_const_string path, t_room *room)
y = -1;
while (++y < room->height)
{
i = y * room->width + x;
if (y == 0 || y == room->height - 1)
{
room->surfaces[y * room->width + x]
= sprite_init(CASE_BORDER_BOTTOM);
room->surfaces[i] = sprite_init(CASE_BORDER_BOTTOM);
if (y == 0)
room->surfaces[y * room->width + x]
= sprite_init(CASE_BORDER_TOP);
room->objects[y * room->width + x] = NULL;
room->surfaces[i] = sprite_init(CASE_BORDER_TOP);
room->objects[i] = NULL;
}
else
room->surfaces[y * room->width + x] = sprite_init(
CASE_FLOOR_1 + (x + y) % 2);
if (room->surfaces[i].meta->first_frame == FLOOR_1)
room->surfaces[i] = sprite_init(CASE_FLOOR_1 + (x + y) % 2);
}
}
return (*room);
@ -57,14 +57,14 @@ static bool room_fromfile2(
while (*line && *line != '\n')
{
roomcase = getroomcase(path, *line);
room->objects[*i] = NULL;
if (roomcase->object)
{
room->objects[*i] = mem_alloc(error_err, room->mc,
sizeof(t_object));
*(room->objects[*i]) = roomcase->object(room->mc);
}
else
room->objects[*i] = NULL;
room->surfaces[*i] = sprite_init(roomcase->surface);
line++;
(*i)++;
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:23:43 by mcolonna #+# #+# */
/* Updated: 2024/04/15 18:49:56 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 13:34:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,7 @@ typedef struct s_roomcase
{
char c;
t_object_init object;
t_spritesmap_id surface;
} t_roomcase;
void room_getsize(t_memclass mc, t_room *r, t_const_string path);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:21:33 by mcolonna #+# #+# */
/* Updated: 2024/04/15 18:59:54 by mcolonna ### ########.fr */
/* Updated: 2024/04/18 13:51:46 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,12 +14,13 @@
#include "room_utils.h"
static t_roomcase g_roomcases[] = {
{c: '0', object: NULL},
{c: '1', object: wall_init},
{c: 'P', object: snas_init},
{c: 'C', object: ketchup_init},
{c: 'E', object: exit_init},
{c: 'F', object: firsk_init},
{c: '0', object: NULL, surface: CASE_FLOOR_1},
{c: '1', object: wall_init, surface: CASE_FLOOR_1},
{c: 'P', object: snas_init, surface: CASE_FLOOR_1},
{c: 'C', object: ketchup_init, surface: CASE_FLOOR_1},
{c: 'E', object: exit_init, surface: CASE_FLOOR_1},
{c: 'F', object: firsk_init, surface: CASE_FLOOR_1},
{c: 'B', object: NULL, surface: CASE_BRIDGE},
{c: '\0'}
};
@ -104,10 +105,10 @@ void room_checkaccessibilities(t_const_string path)
{
obj = g_env.room.objects[p.y * g_env.room.width + p.x];
if (obj && obj->type.init == ketchup_init)
if (pathfinding(snas_pos, p) == NO_DIRECTION)
if (pathfinding(snas_pos, p, false) == NO_DIRECTION)
error_str(path, "all collectibles must be accessible.");
}
}
if (pathfinding(snas_pos, room_find(exit_init)) == NO_DIRECTION)
if (pathfinding(snas_pos, room_find(exit_init), false) == NO_DIRECTION)
error_str(path, "the exit must be accessible.");
}