diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-02 00:45:07 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-02 00:45:07 (EDT) |
commit | b7f5f6118812bfb6bf0815ab23f3399eec571068 (patch) | |
tree | 7a0a3804d937152a14f1df7b7e2eccf85d5894b2 | |
parent | 18ed76f4d68ff7b35954a9e4276c29e1ac9362f6 (diff) | |
download | mazefight-b7f5f6118812bfb6bf0815ab23f3399eec571068.zip mazefight-b7f5f6118812bfb6bf0815ab23f3399eec571068.tar.gz mazefight-b7f5f6118812bfb6bf0815ab23f3399eec571068.tar.bz2 |
maze: Render (untested)
TODO: Color
-rw-r--r-- | src/maze.c | 44 | ||||
-rw-r--r-- | src/maze.h | 5 |
2 files changed, 49 insertions, 0 deletions
@@ -17,6 +17,7 @@ * along with Maze Fight. If not, see <http://www.gnu.org/licenses/>. */ +#include <SDL.h> #include <stdlib.h> #include "maze.h" @@ -178,6 +179,49 @@ mf_maze_new(int s, int w, int h) return m; } +int +mf_maze_render(struct mf_maze *m, SDL_Renderer *renderer, int cw) +{ + int e; + int x; + int y; + + e = 0; + + for (y = 0; y < m->h; ++y) { + for (x = 0; x < m->w; ++x) { + if (y < m->h - 1 && mf_maze_is_wall(m, x, y, 0, 1)) { + /* Draw v line */ + if (SDL_RenderDrawLine(renderer, + (x+1) * cw, (y ) * cw, + (x+1) * cw, (y+1) * cw) + < 0) { + SDL_LogError( + SDL_LOG_CATEGORY_APPLICATION, + "Couldn't draw line: %s", + SDL_GetError()); + e = -1; + } + } + if (x < m->w - 1 && mf_maze_is_wall(m, x, y, 1, 0)) { + /* Draw h line */ + if (SDL_RenderDrawLine(renderer, + (x ) * cw, (y+1) * cw, + (x+1) * cw, (y+1) * cw) + < 0) { + SDL_LogError( + SDL_LOG_CATEGORY_APPLICATION, + "Couldn't draw line: %s", + SDL_GetError()); + e = -1; + } + } + } + } + + return e; +} + void mf_maze_destroy(struct mf_maze **m_p) { @@ -20,6 +20,8 @@ #ifndef MF_MAZE_H_ #define MF_MAZE_H_ +#include <SDL.h> + struct mf_maze; void @@ -32,6 +34,9 @@ mf_maze_is_wall(struct mf_maze *m, int x, int y, int dx, int dy) struct mf_maze * mf_maze_new(int s, int w, int h); +int +mf_maze_render(struct mf_maze *m, SDL_Renderer *renderer, int cw); + void mf_maze_destroy(struct mf_maze **m_p); |