From 2fd912ad83dc15f588b3fce8635b8365233fee82 Mon Sep 17 00:00:00 2001 From: Sopár Adrián Date: Fri, 28 Jun 2024 22:23:33 +0200 Subject: Let the user switch between map and real life mode. --- src/defaults.h | 1 + src/game/entry.c | 6 +++--- src/game/game.c | 1 + src/game/game.h | 3 ++- src/game/operations.c | 8 +++++++- src/game/operations.h | 4 +++- 6 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/defaults.h b/src/defaults.h index 0719656..f224da3 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -39,6 +39,7 @@ static inline void set_blocks(struct game_blocks *game_blocks) {0, "^L", move_maze, MOVE_RIGHT}, \ {'0', "", move_maze, MOVE_BEGINNING}, \ {'p', "", turn_display_switch, DISP_PATH}, \ + {'v', "", turn_visible, 0}, \ {'q', "", quit, GR_QUIT}, \ {'r', "", new_random, 0}, \ {'c', "", center, 0}, \ diff --git a/src/game/entry.c b/src/game/entry.c index e4eb033..82ef465 100644 --- a/src/game/entry.c +++ b/src/game/entry.c @@ -99,7 +99,7 @@ void draw_maze(struct maze_display *maze_draw, struct game_blocks *blocks) if (real_x >= 0 && real_x < width) { path_sign = maze_draw->signs[cell.x][cell.y]; - if (!visible(maze_draw->maze, maze_draw->player_pos, cell)) + if (!visible(maze_draw->maze, maze_draw->player_pos, cell) && !(maze_draw->visible)) { darw_block(&(blocks->hidden)); } @@ -125,13 +125,13 @@ void draw_maze(struct maze_display *maze_draw, struct game_blocks *blocks) mv_draw_block( maze_draw->maze_pos.y + maze_draw->player_pos.y, maze_draw->maze_pos.x + maze_draw->player_pos.x, &(blocks->player)); - if (visible(maze_draw->maze, maze_draw->player_pos, maze_draw->maze->starting_point)) + if (visible(maze_draw->maze, maze_draw->player_pos, maze_draw->maze->starting_point) && maze_draw->visible) { mv_draw_block( maze_draw->maze_pos.y + maze_draw->maze->starting_point.y, maze_draw->maze_pos.x + maze_draw->maze->starting_point.x, &(blocks->start)); } - if (visible(maze_draw->maze, maze_draw->player_pos, maze_draw->maze->end_point)) + if (visible(maze_draw->maze, maze_draw->player_pos, maze_draw->maze->end_point) && maze_draw->visible) { mv_draw_block( maze_draw->maze_pos.y + maze_draw->maze->end_point.y, diff --git a/src/game/game.c b/src/game/game.c index a9ac239..a5f4ce0 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -83,6 +83,7 @@ struct game_state *create_game_state(struct maze *maze) display->maze = maze; display->player_pos = maze->starting_point; display->display_player_path = true; + display->visible = false; //Signs int signs_length = sizeof_2d(maze->width, maze->height, sizeof(int)); display->signs = malloc(signs_length); diff --git a/src/game/game.h b/src/game/game.h index 4b0de07..d00aaff 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -26,6 +26,7 @@ struct maze_display struct maze *maze; enum signs **signs; bool display_player_path; + bool visible; }; struct game_state @@ -64,4 +65,4 @@ static inline struct point get_player_center(struct point player_pos) return maze_pos; } -#endif \ No newline at end of file +#endif diff --git a/src/game/operations.c b/src/game/operations.c index aa9424f..7ba3319 100644 --- a/src/game/operations.c +++ b/src/game/operations.c @@ -75,6 +75,12 @@ enum op_res turn_display_switch(struct game_state *state, int data) return OPR_NONE; } +enum op_res turn_visible(struct game_state *state, int data) +{ + state->display->visible = !state->display->visible; + return OPR_NONE; +} + enum op_res new_random(struct game_state *state, int data) { struct maze_display *display = state->display; @@ -141,4 +147,4 @@ enum op_res start_command_prompt(struct game_state *state, int data) } } return OPR_NONE; -} \ No newline at end of file +} diff --git a/src/game/operations.h b/src/game/operations.h index 2f2af47..36327ad 100644 --- a/src/game/operations.h +++ b/src/game/operations.h @@ -31,6 +31,8 @@ enum op_res quit(struct game_state *state, int data); enum op_res turn_display_switch(struct game_state *state, int data); +enum op_res turn_visible(struct game_state *state, int data); + enum op_res new_random(struct game_state *state, int data); enum op_res center(struct game_state *state, int data); @@ -41,4 +43,4 @@ enum op_res solve(struct game_state *state, int data); enum op_res start_command_prompt(struct game_state *state, int data); -#endif \ No newline at end of file +#endif -- cgit v1.2.3