summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;