summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-25 18:38:46 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-25 18:57:28 (EDT)
commitfed0f2cf2d47f55e1d6e16966e4983fe3c828745 (patch)
tree0221ece0c4fcf0c8cfde3dbd3066dcfb203f6ed0 /src
parent861c8d8d5dd5ff84cc359c3f41cadec4121cfdc7 (diff)
downloaddodge-balls-fed0f2cf2d47f55e1d6e16966e4983fe3c828745.zip
dodge-balls-fed0f2cf2d47f55e1d6e16966e4983fe3c828745.tar.gz
dodge-balls-fed0f2cf2d47f55e1d6e16966e4983fe3c828745.tar.bz2
ball: Render
Diffstat (limited to 'src')
-rw-r--r--src/ball.c19
-rw-r--r--src/ball.h1
-rw-r--r--src/level.c1
3 files changed, 21 insertions, 0 deletions
diff --git a/src/ball.c b/src/ball.c
index b8dd78b..ce39c0a 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -48,6 +48,7 @@ db_ball_new(int x, int y, int r, int a, int d, int sr, double s,
return NULL;
}
+ db_dbg("Ball at (%d,%d)", x, y);
ball->x = x;
ball->y = y;
ball->r = r;
@@ -101,3 +102,21 @@ db_balls_player_collisions(struct db_ball *ball,
return 0;
}
}
+
+void
+db_balls_render(struct db_ball *ball, SDL_Renderer *renderer)
+{
+ SDL_Rect dstrect;
+
+ dstrect.x = ball->x - ball->r;
+ dstrect.y = ball->y - ball->r;
+ dstrect.w = ball->r * 2;
+ dstrect.h = ball->r * 2;
+ db_dbg("Rendering ball (%dx%d) at (%d,%d)",
+ dstrect.w, dstrect.h, dstrect.x, dstrect.y);
+ db_tile_render(ball->tilesets, renderer, ball->gid, &dstrect);
+
+ if (ball->next != NULL) {
+ db_balls_render(ball->next, renderer);
+ }
+}
diff --git a/src/ball.h b/src/ball.h
index 8cb8e6b..45058bc 100644
--- a/src/ball.h
+++ b/src/ball.h
@@ -30,5 +30,6 @@ void db_balls_collisions(struct db_ball *ball_head);
int db_balls_player_collisions(struct db_ball *ball_head,
int player_x, int player_y, int player_r)
__attribute__((__pure__));
+void db_balls_render(struct db_ball *ball, SDL_Renderer *renderer);
#endif /* DB_BALL_H_ */
diff --git a/src/level.c b/src/level.c
index efa566c..9de9182 100644
--- a/src/level.c
+++ b/src/level.c
@@ -101,6 +101,7 @@ db_level_play(SDL_Renderer *renderer, struct db_level *level)
db_err("Failed to copy texture (%s)", SDL_GetError());
return -1;
}
+ db_balls_render(level->balls, renderer);
SDL_RenderPresent(renderer);
SDL_Delay(1000);