aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.h3
-rw-r--r--src/defaults.h3
-rw-r--r--src/game/entry.c38
3 files changed, 41 insertions, 3 deletions
diff --git a/src/config.h b/src/config.h
index 6ee5a47..780d051 100644
--- a/src/config.h
+++ b/src/config.h
@@ -22,6 +22,7 @@ struct block
struct game_blocks
{
+ struct block hidden;
struct block wall;
struct block road;
struct block path;
@@ -51,4 +52,4 @@ struct conf *load_default_conf();
void destroy_conf(struct conf *);
-#endif \ No newline at end of file
+#endif
diff --git a/src/defaults.h b/src/defaults.h
index d4fdc1b..f4914ec 100644
--- a/src/defaults.h
+++ b/src/defaults.h
@@ -8,6 +8,7 @@
static inline void set_blocks(struct game_blocks *game_blocks)
{
+ game_blocks->hidden = get_block('?', false, get_color_code(COLOR_WHITE, COLOR_BLACK));
game_blocks->wall = get_block(' ', false, get_color_code(COLOR_BLACK, COLOR_WHITE));
game_blocks->road = get_block(' ', false, get_color_code(COLOR_WHITE, COLOR_BLACK));
game_blocks->path = get_block(0x2022, false, get_color_code(COLOR_YELLOW, COLOR_BLACK));
@@ -45,4 +46,4 @@ static inline void set_blocks(struct game_blocks *game_blocks)
{':', "", start_command_prompt, ':'}, \
}
-#endif \ No newline at end of file
+#endif
diff --git a/src/game/entry.c b/src/game/entry.c
index 50cf78c..067cc6c 100644
--- a/src/game/entry.c
+++ b/src/game/entry.c
@@ -1,6 +1,7 @@
#include "entry.h"
#include "game.h"
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <ncurses.h>
#include "utilities.h"
@@ -44,6 +45,37 @@ static void mv_draw_block(int y, int x, struct block *block)
}
}
+bool visible(struct maze* maze, struct point player, int x, int y)
+{
+ if (player.x == x && player.y == y)
+ return true;
+ else if (player.x == x)
+ {
+ int step = player.y - y >= 0 ? -1 : 1;
+ for (int i = player.y + step; i != y; i += step)
+ if (maze->map[x][i])
+ return false;
+ return true;
+ }
+ else if (player.y == y)
+ {
+ int step = player.x - x >= 0 ? -1 : 1;
+ for (int i = player.x + step; i != x; i += step)
+ if (maze->map[i][y])
+ return false;
+ return true;
+ }
+ else if (player.y == y - 1)
+ return visible(maze, player, x, y - 1);
+ else if (player.y == y + 1)
+ return visible(maze, player, x, y + 1);
+ else if (player.x == x - 1)
+ return visible(maze, player, x - 1, y);
+ else if (player.x == x + 1)
+ return visible(maze, player, x + 1, y);
+ return false;
+}
+
void draw_maze(struct maze_display *maze_draw, struct game_blocks *blocks)
{
int width = getmaxx(stdscr);
@@ -66,7 +98,11 @@ void draw_maze(struct maze_display *maze_draw, struct game_blocks *blocks)
if (real_x >= 0 && real_x < width)
{
path_sign = maze_draw->signs[x][y];
- if (path_sign == RS_NONE || (path_sign == RS_PATH && !maze_draw->display_player_path)) //Maze
+ if (!visible(maze_draw->maze, maze_draw->player_pos, x, y))
+ {
+ darw_block(&(blocks->hidden));
+ }
+ else if (path_sign == RS_NONE || (path_sign == RS_PATH && !maze_draw->display_player_path)) //Maze
{
if (maze_draw->maze->map[x][y])
darw_block(&(blocks->wall));