diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.h | 1 | ||||
| -rw-r--r-- | src/defaults.h | 1 | ||||
| -rw-r--r-- | src/game/entry.c | 80 |
3 files changed, 46 insertions, 36 deletions
diff --git a/src/config.h b/src/config.h index 780d051..ae7d5ac 100644 --- a/src/config.h +++ b/src/config.h @@ -22,6 +22,7 @@ struct block struct game_blocks { + struct block background; struct block hidden; struct block wall; struct block road; diff --git a/src/defaults.h b/src/defaults.h index f4914ec..0719656 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->background = get_block('?', false, get_color_code(COLOR_WHITE, COLOR_BLACK)); 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)); diff --git a/src/game/entry.c b/src/game/entry.c index 067cc6c..e4eb033 100644 --- a/src/game/entry.c +++ b/src/game/entry.c @@ -45,34 +45,34 @@ static void mv_draw_block(int y, int x, struct block *block) } } -bool visible(struct maze* maze, struct point player, int x, int y) +bool visible(struct maze* maze, struct point player, struct point cell) { - if (player.x == x && player.y == y) + if (player.x == cell.x && player.y == cell.y) return true; - else if (player.x == x) + else if (player.x == cell.x) { - int step = player.y - y >= 0 ? -1 : 1; - for (int i = player.y + step; i != y; i += step) - if (maze->map[x][i]) + int step = player.y - cell.y >= 0 ? -1 : 1; + for (int i = player.y + step; i != cell.y; i += step) + if (maze->map[cell.x][i]) return false; return true; } - else if (player.y == y) + else if (player.y == cell.y) { - int step = player.x - x >= 0 ? -1 : 1; - for (int i = player.x + step; i != x; i += step) - if (maze->map[i][y]) + int step = player.x - cell.x >= 0 ? -1 : 1; + for (int i = player.x + step; i != cell.x; i += step) + if (maze->map[i][cell.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); + else if (player.y == cell.y - 1) + return visible(maze, player, relative_point(cell, 0, -1)); + else if (player.y == cell.y + 1) + return visible(maze, player, relative_point(cell, 0, +1)); + else if (player.x == cell.x - 1) + return visible(maze, player, relative_point(cell, -1, 0)); + else if (player.x == cell.x + 1) + return visible(maze, player, relative_point(cell, +1, 0)); return false; } @@ -81,30 +81,31 @@ void draw_maze(struct maze_display *maze_draw, struct game_blocks *blocks) int width = getmaxx(stdscr); int height = getmaxy(stdscr) - 1; enum signs path_sign; - for (int y = 0; y < maze_draw->maze->height; y++) + struct point cell;// A cell of the maze + for (cell.y = 0; cell.y < maze_draw->maze->height; cell.y++) { - int real_y = maze_draw->maze_pos.y + y; + int real_y = maze_draw->maze_pos.y + cell.y; if (real_y >= 0 && real_y < height) { if (maze_draw->maze_pos.x >= 0) move(real_y, maze_draw->maze_pos.x); - for (int x = 0; x < maze_draw->maze->width && y < width; x++) + for (cell.x = 0; cell.x < maze_draw->maze->width && cell.y < width; cell.x++) { - int real_x = maze_draw->maze_pos.x + x; - if (real_x == 0 && x > 0) + int real_x = maze_draw->maze_pos.x + cell.x; + if (real_x == 0 && cell.x > 0) { move(real_y, 0); } if (real_x >= 0 && real_x < width) { - path_sign = maze_draw->signs[x][y]; - if (!visible(maze_draw->maze, maze_draw->player_pos, x, y)) + path_sign = maze_draw->signs[cell.x][cell.y]; + if (!visible(maze_draw->maze, maze_draw->player_pos, cell)) { 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]) + if (maze_draw->maze->map[cell.x][cell.y]) darw_block(&(blocks->wall)); else darw_block(&(blocks->road)); @@ -124,22 +125,29 @@ 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)); - 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)); - mv_draw_block( - maze_draw->maze_pos.y + maze_draw->maze->end_point.y, - maze_draw->maze_pos.x + maze_draw->maze->end_point.x, &(blocks->target)); + if (visible(maze_draw->maze, maze_draw->player_pos, maze_draw->maze->starting_point)) + { + 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)) + { + mv_draw_block( + maze_draw->maze_pos.y + maze_draw->maze->end_point.y, + maze_draw->maze_pos.x + maze_draw->maze->end_point.x, &(blocks->target)); + } } -static void own_clear() +static void own_clear(struct block* block) { - attron(COLOR_PAIR(CI_DEFAULT)); + attron(COLOR_PAIR(block->color)); + //attron(COLOR_PAIR(CI_DEFAULT)); int width = getmaxx(stdscr); int height = getmaxy(stdscr) - 1; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) - mvaddch(y, x, ' '); + mvaddch(y, x, block->chr); } enum game_res game(struct app *app) @@ -163,7 +171,7 @@ enum game_res game(struct app *app) } state->display->maze_pos = state->new_maze_pos; //Draw! - own_clear(); + own_clear(&(app->conf->blocks.background)); draw_maze(state->display, &(app->conf->blocks)); if (state->win) draw_line_win(); |
