summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-26 22:53:47 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-26 22:53:47 (EDT)
commitb5bc4b9fdfd72a3f35b78c138836b963b0883d06 (patch)
tree9886301ea2770eeb2e400a043ee1a7b72f07d9d9
parent17982c5f7b2cfa9b55bc2462ff815b3cb33460dc (diff)
downloaddodge-balls-b5bc4b9fdfd72a3f35b78c138836b963b0883d06.zip
dodge-balls-b5bc4b9fdfd72a3f35b78c138836b963b0883d06.tar.gz
dodge-balls-b5bc4b9fdfd72a3f35b78c138836b963b0883d06.tar.bz2
ball: Move spinning balls
-rw-r--r--src/ball.c17
-rw-r--r--src/ball.h1
-rw-r--r--src/level.c1
3 files changed, 19 insertions, 0 deletions
diff --git a/src/ball.c b/src/ball.c
index 862efc4..1386cfd 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -77,6 +77,23 @@ db_ball_new(int x, int y, int r, int a, int d, int sr, double s,
}
void
+db_balls_move(struct db_ball *ball)
+{
+ if (ball->sr == 0) {
+ } else {
+ ball->a += ball->d * ball->s;
+ ball->x = ball->cx + cos(ball->a * (M_PI / 180)) * ball->sr;
+ ball->y = ball->cy - sin(ball->a * (M_PI / 180)) * ball->sr;
+ db_dbg("Spinning ball angle %f (speed %f, direction %d)",
+ ball->a, ball->s, ball->d);
+ }
+
+ if (ball->next != NULL) {
+ db_balls_move(ball->next);
+ }
+}
+
+void
db_balls_collisions(struct db_ball *ball)
{
struct db_ball *other;
diff --git a/src/ball.h b/src/ball.h
index 45058bc..bcb75c4 100644
--- a/src/ball.h
+++ b/src/ball.h
@@ -26,6 +26,7 @@ struct db_ball;
struct db_ball *db_ball_new(int x, int y, int r, int a, int d, int sr, double s,
struct db_tileset *tilesets, int gid, struct db_ball *prev);
+void db_balls_move(struct db_ball *ball);
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)
diff --git a/src/level.c b/src/level.c
index 8c6a1bd..b8dc618 100644
--- a/src/level.c
+++ b/src/level.c
@@ -137,6 +137,7 @@ db_level_play(SDL_Renderer *renderer, struct db_level *level)
break;
}
}
+ db_balls_move(level->balls);
_db_level_render(renderer, level);
cur_ticks = SDL_GetTicks();
if ((Uint32) (1000 / fr) > (cur_ticks - prv_ticks)) {