summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-25 19:09:02 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-25 19:09:02 (EDT)
commit3c71b27c5e1a74e75600efb730ab3252f9d468f6 (patch)
tree96464a857b8f377eae025a53d3e445542ddc2a07
parent0b3f4d7ab07dd9430bd34d423d73eada2d77b3dc (diff)
downloaddodge-balls-3c71b27c5e1a74e75600efb730ab3252f9d468f6.zip
dodge-balls-3c71b27c5e1a74e75600efb730ab3252f9d468f6.tar.gz
dodge-balls-3c71b27c5e1a74e75600efb730ab3252f9d468f6.tar.bz2
ball: Position spinning ball
-rw-r--r--src/ball.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/ball.c b/src/ball.c
index ce39c0a..862efc4 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -17,6 +17,7 @@
* along with Dodge Balls. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <math.h>
#include <stdlib.h>
#include "ball.h"
#include "collision.h"
@@ -24,6 +25,8 @@
#include "output.h"
struct db_ball {
+ int cx;
+ int cy;
double x;
double y;
int r;
@@ -49,8 +52,15 @@ db_ball_new(int x, int y, int r, int a, int d, int sr, double s,
}
db_dbg("Ball at (%d,%d)", x, y);
- ball->x = x;
- ball->y = y;
+ if (sr == 0) {
+ ball->x = x;
+ ball->y = y;
+ } else {
+ ball->cx = x;
+ ball->cy = y;
+ ball->x = x + cos(a * (M_PI / 180)) * sr;
+ ball->y = y - sin(a * (M_PI / 180)) * sr;
+ }
ball->r = r;
ball->a = a;
ball->d = d;