summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2022-01-26 17:00:00 (EST)
committer P. J. McDermott <pj@pehjota.net>2022-01-26 17:00:00 (EST)
commit95ce2c5f032e740ea2e3c44f8055cb3c1f1ce8c5 (patch)
tree8b32a58fddaa5992996681745087c14a11e52d52 /src
parent8f4be98e2a8abb6c33788538d408ea98f3f6eb82 (diff)
downloadmazefight-95ce2c5f032e740ea2e3c44f8055cb3c1f1ce8c5.zip
mazefight-95ce2c5f032e740ea2e3c44f8055cb3c1f1ce8c5.tar.gz
mazefight-95ce2c5f032e740ea2e3c44f8055cb3c1f1ce8c5.tar.bz2
maze: Factor out wall line drawing
Diffstat (limited to 'src')
-rw-r--r--src/maze.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/maze.c b/src/maze.c
index 4655405..05703a7 100644
--- a/src/maze.c
+++ b/src/maze.c
@@ -233,6 +233,24 @@ mf_maze_new(int s, int w, int h, int show_all)
return m;
}
+static int
+_mf_maze_render_line(SDL_Renderer *renderer, int x, int y, int w, int h, int cw)
+{
+ SDL_Rect rect;
+
+ rect.x = x * cw - 1;
+ rect.y = y * cw - 1;
+ rect.w = w * cw + 2;
+ rect.h = h * cw + 2;
+ if (SDL_RenderFillRect(renderer, &rect) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't draw line: %s", SDL_GetError());
+ return -1;
+ }
+
+ return 0;
+}
+
int
mf_maze_render(struct mf_maze *m, SDL_Renderer *renderer, SDL_Color *color,
int cw)
@@ -268,36 +286,16 @@ mf_maze_render(struct mf_maze *m, SDL_Renderer *renderer, SDL_Color *color,
if (y < m->h - 1 && mf_maze_is_wall(m, x, y, 0, 1) &&
_mf_maze_revealed_wall(m, x, y, 0, 1)) {
/* Draw h line */
- if (SDL_RenderDrawLine(renderer,
- (x ) * cw - 1, (y+1) * cw - 1,
- (x+1) * cw , (y+1) * cw - 1)
- < 0 ||
- SDL_RenderDrawLine(renderer,
- (x ) * cw - 1, (y+1) * cw ,
- (x+1) * cw , (y+1) * cw )
- < 0) {
- SDL_LogError(
- SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't draw line: %s",
- SDL_GetError());
+ if (_mf_maze_render_line(renderer, x , y+1,
+ 1, 0, cw) < 0) {
e = -1;
}
}
if (x < m->w - 1 && mf_maze_is_wall(m, x, y, 1, 0) &&
_mf_maze_revealed_wall(m, x, y, 1, 0)) {
/* Draw v line */
- if (SDL_RenderDrawLine(renderer,
- (x+1) * cw - 1, (y ) * cw - 1,
- (x+1) * cw - 1, (y+1) * cw )
- < 0 ||
- SDL_RenderDrawLine(renderer,
- (x+1) * cw , (y ) * cw - 1,
- (x+1) * cw , (y+1) * cw )
- < 0) {
- SDL_LogError(
- SDL_LOG_CATEGORY_APPLICATION,
- "Couldn't draw line: %s",
- SDL_GetError());
+ if (_mf_maze_render_line(renderer, x+1, y ,
+ 0, 1, cw) < 0) {
e = -1;
}
}