diff --git a/Makefile b/Makefile index 43b666a..f382b12 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ CODE = $(addprefix main/, \ ) \ $(addprefix room/, \ visual room1 room2 room_utils1 room_utils2 \ - object_character object_snas object_wall object_ketchup \ + object_character object_snas object_wall object_ketchup object_exit \ ) \ utils/point LIBRARIES = mlx libtf diff --git a/includes/display/data_sprites.h b/includes/display/data_sprites.h index f39e8a2..ab23768 100644 --- a/includes/display/data_sprites.h +++ b/includes/display/data_sprites.h @@ -6,14 +6,14 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */ -/* Updated: 2024/04/05 18:01:55 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:30:53 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef DATA_SPRITES_H # define DATA_SPRITES_H -# define NB_SPRITES 11 +# define NB_SPRITES 14 typedef enum e_spritetype { @@ -47,6 +47,9 @@ typedef enum e_spritesmap_id SPR_WALL, SPR_KETCHUP, SPR_KETCHUP_FADE, + SPR_EXIT_INACTIVE, + SPR_EXIT_ACTIVE, + SPR_EXIT_USING, } t_spritesmap_id; #endif diff --git a/includes/main/env.h b/includes/main/env.h index cb9ce50..1e86233 100644 --- a/includes/main/env.h +++ b/includes/main/env.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */ -/* Updated: 2024/04/05 16:31:40 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:17:26 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ typedef struct s_env t_room room; bool input[4]; int ketchup; + int max_ketchup; } t_env; extern t_env g_env; diff --git a/includes/room/object.h b/includes/room/object.h index a28ae43..08f326a 100644 --- a/includes/room/object.h +++ b/includes/room/object.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 16:11:55 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:35:33 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ typedef struct s_objecttype // Called when a character want to walk through this object. // Returns false to block the character. If true, it will pass. // If walk_through is NULL, the character is blocked. - bool (*walk_through)(t_character *, t_point pos); + bool (*walk_through)(t_object *, t_character *, t_point pos); } t_objecttype; typedef struct s_object diff --git a/includes/room/objects.h b/includes/room/objects.h index 39e8881..71c4a7d 100644 --- a/includes/room/objects.h +++ b/includes/room/objects.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/02 17:47:01 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 15:25:31 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:22:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,4 +37,13 @@ typedef struct s_ketchup_data t_object ketchup_init(t_memclass mc); +// EXIT +typedef struct s_exit_data +{ + t_sprite spr; + bool active; +} t_exit_data; + +t_object exit_init(t_memclass mc); + #endif diff --git a/includes/room/room.h b/includes/room/room.h index 27c9a6d..c70a0ad 100644 --- a/includes/room/room.h +++ b/includes/room/room.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 15:32:23 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:17:12 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/room/room.ber b/room/room.ber index 5f1c4fe..18360ec 100644 --- a/room/room.ber +++ b/room/room.ber @@ -4,5 +4,5 @@ 1000011111001 100001P0000K1 1KKK111111111 -1000000000001 +10000000000E1 1111111111111 diff --git a/src/display/data_sprites.c b/src/display/data_sprites.c index 904aad6..2b19033 100644 --- a/src/display/data_sprites.c +++ b/src/display/data_sprites.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */ -/* Updated: 2024/04/05 18:45:02 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:33:56 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,4 +24,7 @@ const t_spritemeta g_spritesmap[NB_SPRITES] = { {WALL_INNER, 50, 50, ANIMATION, 1, 1}, {OBJECT_KETCHUP_STILL_1, 50, 50, ANIMATION, 4, 4}, {OBJECT_KETCHUP_FADE_1, 50, 50, ANIMATION_ONCE, 3, 1}, +{OBJECT_EXIT_INACTIVE_1, 50, 50, ANIMATION, 2, 4}, +{OBJECT_EXIT_ACTIVE_1, 50, 50, ANIMATION, 4, 2}, +{OBJECT_EXIT_USING1_1, 50, 50, ANIMATION_ONCE, 11, 1}, }; diff --git a/src/main/main.c b/src/main/main.c index 0db0d7c..01509b5 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 16:08:07 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:16:57 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,6 +42,7 @@ int loop_hook(void) int main(void) { + g_env.max_ketchup = 0; g_env.mc = mem_newclass(error_err); g_env.mlx = mlx_init(); if (!g_env.mlx) diff --git a/src/room/object_exit.c b/src/room/object_exit.c new file mode 100644 index 0000000..8c6ae34 --- /dev/null +++ b/src/room/object_exit.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* object_exit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/08 15:01:16 by mcolonna #+# #+# */ +/* Updated: 2024/04/08 15:36:22 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "includes.h" + +static t_point exit_loop(t_object *obj, t_point pos) +{ + t_exit_data *const data = (t_exit_data *)(obj->data); + + (void)pos; + if (!data->active && g_env.ketchup == g_env.max_ketchup) + { + data->active = true; + data->spr = sprite_init(SPR_EXIT_ACTIVE); + } + return (point_init(0, 0)); +} + +static void exit_draw(t_object *obj, int x, int y) +{ + t_exit_data *const data = (t_exit_data *)(obj->data); + + sprite_draw(x, y, &data->spr); +} + +static bool exit_walk_through( + t_object *obj, t_character *character, t_point pos) +{ + t_exit_data *const data = (t_exit_data *)(obj->data); + + (void)character; + if (!data->active) + return (false); + visual_addtoroom(SPR_EXIT_USING, pos); + return (true); +} + +t_object exit_init(t_memclass mc) +{ + static const t_objecttype type + = {loop: exit_loop, draw: exit_draw, walk_through: exit_walk_through}; + t_object r; + t_exit_data *data; + + r.type = type; + data = mem_alloc(error_err, mc, sizeof(t_exit_data)); + data->spr = sprite_init(SPR_EXIT_INACTIVE); + data->active = false; + r.data = data; + return (r); +} diff --git a/src/room/object_ketchup.c b/src/room/object_ketchup.c index 50ce1eb..f287478 100644 --- a/src/room/object_ketchup.c +++ b/src/room/object_ketchup.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 16:10:39 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:36:10 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,11 +24,12 @@ static void ketchup_draw(t_object *obj, int x, int y) sprite_draw(x, y, &((t_wall_data *)obj->data)->spr); } -static bool ketchup_walk_through(t_character *character, t_point pos) +static bool ketchup_walk_through( + t_object *obj, t_character *character, t_point pos) { + (void)obj; (void)character; g_env.ketchup++; - tf_printf("Ketchup level: %i\n", g_env.ketchup); visual_addtoroom(SPR_KETCHUP_FADE, pos); return (true); } @@ -45,5 +46,6 @@ t_object ketchup_init(t_memclass mc) data = mem_alloc(error_err, mc, sizeof(t_wall_data)); data->spr = sprite_init(SPR_KETCHUP); r.data = data; + g_env.max_ketchup++; return (r); } diff --git a/src/room/room1.c b/src/room/room1.c index 4be7708..05c4d69 100644 --- a/src/room/room1.c +++ b/src/room/room1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 15:43:44 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:13:16 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,7 @@ t_room room_fromfile(t_const_string path) while (room_fromfile2(fd, path, &i, &r)) ; mem_freeall(mc); - room_patch(&r); + room_fromfile3(&r); return (r); } diff --git a/src/room/room2.c b/src/room/room2.c index 0bc6ccd..1a836b1 100644 --- a/src/room/room2.c +++ b/src/room/room2.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 16:10:23 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:36:42 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ bool room_canwalk(t_room room, t_character *character, t_point pos) obj = room_getobjectfaced(room, character, pos); r = (!obj || ( obj->type.walk_through - && obj->type.walk_through(character, after))); + && obj->type.walk_through(obj, character, after))); if (r) mem_free(obj); return (r); diff --git a/src/room/room_utils.h b/src/room/room_utils.h index effd5f3..ba71e5e 100644 --- a/src/room/room_utils.h +++ b/src/room/room_utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/13 16:34:01 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 17:51:05 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:13:43 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,6 @@ void room_getsize(t_memclass mc, t_room *r, t_const_string path); t_roomcase *getroomcase(t_const_string path, char c); void moveobject(t_room room, t_point start, t_point move); bool isinlist(void *addr, t_list list); -void room_patch(t_room *room); +void room_fromfile3(t_room *room); #endif diff --git a/src/room/room_utils1.c b/src/room/room_utils1.c index c085353..f51ca12 100644 --- a/src/room/room_utils1.c +++ b/src/room/room_utils1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/13 16:26:28 by mcolonna #+# #+# */ -/* Updated: 2024/04/03 13:35:35 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:07:16 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ static t_roomcase g_roomcases[] = { {c: '1', object: wall_init}, {c: 'P', object: snas_init}, {c: 'K', object: ketchup_init}, +{c: 'E', object: exit_init}, {c: '\0'} }; diff --git a/src/room/room_utils2.c b/src/room/room_utils2.c index 14d7a20..d553cff 100644 --- a/src/room/room_utils2.c +++ b/src/room/room_utils2.c @@ -6,14 +6,14 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/02 12:33:48 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 17:52:14 by mcolonna ### ########.fr */ +/* Updated: 2024/04/08 15:16:01 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes.h" #include "room_utils.h" -void room_patch(t_room *room) +void room_fromfile3(t_room *room) { int x; int y;