feat: multi level management *
when called without arguments, use the default levels
This commit is contained in:
parent
a9c292d72b
commit
7b1e519db6
8 changed files with 44 additions and 23 deletions
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/26 15:26:13 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 FPS 20
|
||||||
# define TEXT_SPACE 9
|
# define TEXT_SPACE 9
|
||||||
|
|
||||||
|
# define LEVEL_COUNT 3
|
||||||
|
extern const t_const_string g_levels[LEVEL_COUNT];
|
||||||
|
|
||||||
typedef struct s_env
|
typedef struct s_env
|
||||||
{
|
{
|
||||||
// GLOBAL
|
// GLOBAL
|
||||||
t_memclass mc;
|
t_memclass mc;
|
||||||
|
|
||||||
// IO
|
// IO
|
||||||
// display
|
// display
|
||||||
void *mlx;
|
void *mlx;
|
||||||
void *win;
|
void *win;
|
||||||
// input
|
// input
|
||||||
bool input[4];
|
bool input[4];
|
||||||
bool enter;
|
bool enter;
|
||||||
|
|
||||||
// GAME
|
// GAME
|
||||||
// levels
|
// levels
|
||||||
t_const_string *levels;
|
const t_const_string *levels;
|
||||||
int level_count;
|
int level_count;
|
||||||
int level_current;
|
int level_current;
|
||||||
// room
|
// room
|
||||||
t_room room;
|
t_room room;
|
||||||
t_camera camera;
|
t_camera camera;
|
||||||
int ketchup;
|
int ketchup;
|
||||||
int max_ketchup;
|
int max_ketchup;
|
||||||
// moves
|
// moves
|
||||||
int moves;
|
int moves;
|
||||||
} t_env;
|
} t_env;
|
||||||
|
|
||||||
extern t_env g_env;
|
extern t_env g_env;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/18 17:45:16 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 init_level(void);
|
||||||
void ask_retry(bool current);
|
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);
|
void win(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
3
rooms/1.ber
Normal file
3
rooms/1.ber
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
1111111
|
||||||
|
1FBPCE1
|
||||||
|
1111111
|
3
rooms/2.ber
Normal file
3
rooms/2.ber
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
11111111
|
||||||
|
1FBPCCE1
|
||||||
|
11111111
|
3
rooms/3.ber
Normal file
3
rooms/3.ber
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
111111111
|
||||||
|
1FBPCCCE1
|
||||||
|
111111111
|
|
@ -6,10 +6,16 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/26 16:32:36 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"
|
#include "includes.h"
|
||||||
|
|
||||||
|
const t_const_string g_levels[LEVEL_COUNT] = {
|
||||||
|
"rooms/1.ber",
|
||||||
|
"rooms/2.ber",
|
||||||
|
"rooms/3.ber",
|
||||||
|
};
|
||||||
|
|
||||||
t_env g_env;
|
t_env g_env;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/18 17:49:39 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.moves = 0;
|
||||||
g_env.levels = srcs;
|
g_env.levels = srcs;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/26 15:28:34 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)
|
int main(int argc, t_const_string *argv)
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc > 2)
|
||||||
error_str("so_long", "takes 1 argument");
|
error_str("so_long", "takes max 1 argument");
|
||||||
g_env.mc = mem_newclass(error_err);
|
g_env.mc = mem_newclass(error_err);
|
||||||
g_env.mlx = mlx_init();
|
g_env.mlx = mlx_init();
|
||||||
if (!g_env.mlx)
|
if (!g_env.mlx)
|
||||||
|
@ -55,7 +55,10 @@ int main(int argc, t_const_string *argv)
|
||||||
WINDOW_TITLE);
|
WINDOW_TITLE);
|
||||||
if (!g_env.win)
|
if (!g_env.win)
|
||||||
error_err("mlx_new_window() failed");
|
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_expose_hook(g_env.win, expose_hook, NULL);
|
||||||
mlx_hook(g_env.win, DestroyNotify, StructureNotifyMask, close_hook, NULL);
|
mlx_hook(g_env.win, DestroyNotify, StructureNotifyMask, close_hook, NULL);
|
||||||
mlx_loop_hook(g_env.mlx, loop_hook, NULL);
|
mlx_loop_hook(g_env.mlx, loop_hook, NULL);
|
||||||
|
|
Loading…
Add table
Reference in a new issue