aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-01-28 15:17:15 +1300
committerDavid Phillips <david@sighup.nz>2017-01-28 15:17:15 +1300
commit5abfed0347c799132e1045c0fc4724a283f6cc1d (patch)
treecfc4ee44e6dd25230ca17013222782630f1cb95f
parentdec7d61e23e0b3cbdf406f83eb9e46042ad9bc2f (diff)
downloadtetris-5abfed0347c799132e1045c0fc4724a283f6cc1d.tar.xz
Refactor border/gap code
-rw-r--r--plot.c34
-rw-r--r--plot.h2
-rw-r--r--tetris.c1
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++)