aboutsummaryrefslogtreecommitdiff
path: root/src/game/entry.c
diff options
context:
space:
mode:
authorSopár Adrián <adrian.sopar@protonmail.com>2024-06-23 16:58:54 +0200
committerSopár Adrián <adrian.sopar@protonmail.com>2024-06-23 16:58:54 +0200
commitdb00fd457bb6a6ce4eea57c9e46cc06867b1c5c6 (patch)
tree0badc0c9ca443ddd882dca3322c4ba3a82b7440b /src/game/entry.c
parent90f9e3942d5ff3bcb58470926f68391211bebbad (diff)
Make background configurable and also hide start and end point when it's not visible.
Diffstat (limited to 'src/game/entry.c')
-rw-r--r--src/game/entry.c80
1 files changed, 44 insertions, 36 deletions
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();