From 5abfed0347c799132e1045c0fc4724a283f6cc1d Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 28 Jan 2017 15:17:15 +1300 Subject: Refactor border/gap code --- plot.c | 34 +++++----------------------------- plot.h | 2 +- tetris.c | 1 + 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/plot.c b/plot.c index 6a579d6..419513e 100644 --- a/plot.c +++ b/plot.c @@ -36,33 +36,13 @@ void plot_cell(unsigned int x, unsigned int y, struct colour *c) ); } -void plot_cell_borders() +void plot_clear() { - int i, j; - - struct colour col = {.r = 0, .g = 0, .b = 0}; - - for (i = 1; i < WIDTH_CELLS; i++) - { - j = i*CELL_SIZE + (i-1)*BORDER_THICKNESS; - plot_rect( - j, 0, - BORDER_THICKNESS, HEIGHT_PIXELS, - &col); - } - - for (i = 1; i < HEIGHT_CELLS; i++) - { - j = i*CELL_SIZE + (i-1)*BORDER_THICKNESS; - plot_rect( - 0, j, - WIDTH_PIXELS, BORDER_THICKNESS, - &col); - } - + /* blank out the background with black */ + SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); + SDL_RenderFillRect(renderer, NULL); } - int plot_init() { if (SDL_Init(SDL_INIT_VIDEO) < 0) @@ -93,11 +73,7 @@ int plot_init() return 1; } - /* blank out the background with gray */ - SDL_SetRenderDrawColor(renderer, 0x33, 0x33, 0x33, 0xFF); - SDL_RenderFillRect(renderer, NULL); - - plot_cell_borders(); + plot_clear(); return 0; } diff --git a/plot.h b/plot.h index 836c377..e73c481 100644 --- a/plot.h +++ b/plot.h @@ -1,6 +1,6 @@ void plot_rect(unsigned int x, unsigned int y, unsigned int width, unsigned int height, struct colour *c); void plot_cell(unsigned int x, unsigned int y, struct colour *c); -void plot_cell_borders(); +void plot_clear(); int plot_init(); void plot_update(); diff --git a/tetris.c b/tetris.c index c94420f..ce60f21 100644 --- a/tetris.c +++ b/tetris.c @@ -27,6 +27,7 @@ struct colour palette[] = { void draw_board(struct colour* (*board)[WIDTH_CELLS][HEIGHT_CELLS]) { unsigned int x,y; + plot_clear(); for (y = 0; y < HEIGHT_CELLS; y++) { for (x = 0; x < WIDTH_CELLS; x++) -- cgit v1.1