diff options
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/entry.c | 38 |
1 files changed, 37 insertions, 1 deletions
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)); |
