From 7b1e519db622aa8fed89dcfbcaa8bce5a46df699 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Fri, 19 Apr 2024 14:16:25 +0200 Subject: [PATCH] feat: multi level management * when called without arguments, use the default levels --- includes/main/env.h | 31 +++++++++++++++++-------------- includes/main/levels.h | 4 ++-- rooms/1.ber | 3 +++ rooms/2.ber | 3 +++ rooms/3.ber | 3 +++ src/main/env.c | 8 +++++++- src/main/levels1.c | 4 ++-- src/main/main.c | 11 +++++++---- 8 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 rooms/1.ber create mode 100644 rooms/2.ber create mode 100644 rooms/3.ber diff --git a/includes/main/env.h b/includes/main/env.h index cee21e2..740e575 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/19 14:03:49 by mcolonna ### ########.fr */ +/* Updated: 2024/04/19 14:14:09 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,31 +19,34 @@ # define FPS 20 # define TEXT_SPACE 9 +# define LEVEL_COUNT 3 +extern const t_const_string g_levels[LEVEL_COUNT]; + typedef struct s_env { // GLOBAL - t_memclass mc; + t_memclass mc; // IO // display - void *mlx; - void *win; + void *mlx; + void *win; // input - bool input[4]; - bool enter; + bool input[4]; + bool enter; // GAME // levels - t_const_string *levels; - int level_count; - int level_current; + const t_const_string *levels; + int level_count; + int level_current; // room - t_room room; - t_camera camera; - int ketchup; - int max_ketchup; + t_room room; + t_camera camera; + int ketchup; + int max_ketchup; // moves - int moves; + int moves; } t_env; extern t_env g_env; diff --git a/includes/main/levels.h b/includes/main/levels.h index acd6d4f..140a8f0 100644 --- a/includes/main/levels.h +++ b/includes/main/levels.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/18 17:45:16 by mcolonna #+# #+# */ -/* Updated: 2024/04/19 12:48:33 by mcolonna ### ########.fr */ +/* Updated: 2024/04/19 14:12:07 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ void init_level(void); void ask_retry(bool current); -void init_levels(int count, t_const_string *srcs); +void init_levels(int count, const t_const_string *srcs); void win(void); #endif diff --git a/rooms/1.ber b/rooms/1.ber new file mode 100644 index 0000000..d2ec825 --- /dev/null +++ b/rooms/1.ber @@ -0,0 +1,3 @@ +1111111 +1FBPCE1 +1111111 diff --git a/rooms/2.ber b/rooms/2.ber new file mode 100644 index 0000000..3b83470 --- /dev/null +++ b/rooms/2.ber @@ -0,0 +1,3 @@ +11111111 +1FBPCCE1 +11111111 diff --git a/rooms/3.ber b/rooms/3.ber new file mode 100644 index 0000000..2c41fa2 --- /dev/null +++ b/rooms/3.ber @@ -0,0 +1,3 @@ +111111111 +1FBPCCCE1 +111111111 diff --git a/src/main/env.c b/src/main/env.c index a232217..72a8243 100644 --- a/src/main/env.c +++ b/src/main/env.c @@ -6,10 +6,16 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/26 16:32:36 by mcolonna #+# #+# */ -/* Updated: 2024/04/02 14:41:12 by mcolonna ### ########.fr */ +/* Updated: 2024/04/19 14:12:41 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes.h" +const t_const_string g_levels[LEVEL_COUNT] = { +"rooms/1.ber", +"rooms/2.ber", +"rooms/3.ber", +}; + t_env g_env; diff --git a/src/main/levels1.c b/src/main/levels1.c index f4ed65e..6c4b077 100644 --- a/src/main/levels1.c +++ b/src/main/levels1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/18 17:49:39 by mcolonna #+# #+# */ -/* Updated: 2024/04/19 13:18:45 by mcolonna ### ########.fr */ +/* Updated: 2024/04/19 14:13:01 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ void ask_retry(bool current) } } -void init_levels(int count, t_const_string *srcs) +void init_levels(int count, const t_const_string *srcs) { g_env.moves = 0; g_env.levels = srcs; diff --git a/src/main/main.c b/src/main/main.c index 15ba784..60ccfe0 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/18 18:04:37 by mcolonna ### ########.fr */ +/* Updated: 2024/04/19 14:11:01 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,8 +43,8 @@ int loop_hook(void) int main(int argc, t_const_string *argv) { - if (argc != 2) - error_str("so_long", "takes 1 argument"); + if (argc > 2) + error_str("so_long", "takes max 1 argument"); g_env.mc = mem_newclass(error_err); g_env.mlx = mlx_init(); if (!g_env.mlx) @@ -55,7 +55,10 @@ int main(int argc, t_const_string *argv) WINDOW_TITLE); if (!g_env.win) error_err("mlx_new_window() failed"); - init_levels(1, &argv[1]); + if (argc == 2) + init_levels(1, &argv[1]); + else + init_levels(LEVEL_COUNT, g_levels); mlx_expose_hook(g_env.win, expose_hook, NULL); mlx_hook(g_env.win, DestroyNotify, StructureNotifyMask, close_hook, NULL); mlx_loop_hook(g_env.mlx, loop_hook, NULL);