summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-05-21 18:57:11 (EDT)
committer P. J. McDermott <pjm@nac.net>2013-05-21 18:57:11 (EDT)
commita4d2b83d29a78d171deb2c6447369d94e752f2cb (patch)
treec92db91f7d00ec33fe8cab03462cdf5b7d0cf78b
parent40a64ca7bf3fcae470f3af16f21597e80e23fbe3 (diff)
downloadcursespong-a4d2b83d29a78d171deb2c6447369d94e752f2cb.zip
cursespong-a4d2b83d29a78d171deb2c6447369d94e752f2cb.tar.gz
cursespong-a4d2b83d29a78d171deb2c6447369d94e752f2cb.tar.bz2
Make balls move.
-rw-r--r--Makefile.am2
-rw-r--r--src/ball.c8
-rw-r--r--src/ball.h4
-rw-r--r--src/game.c2
4 files changed, 11 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index efe5a40..93192a9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,4 +7,4 @@ cursespong_SOURCES = \
cursespong_CFLAGS = \
$(GCC_CFLAGS)
cursespong_LDADD = \
- -lcurses
+ -lm -lcurses
diff --git a/src/ball.c b/src/ball.c
index 91c2995..3515b68 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -1,10 +1,11 @@
#include <stdlib.h>
+#include <math.h>
#include <curses.h>
#include "ball.h"
struct ball *
-new_ball(float x, float y)
+new_ball(float x, float y, float speed, float dir)
{
struct ball *b;
@@ -15,6 +16,8 @@ new_ball(float x, float y)
b->x = x;
b->y = y;
+ b->speed = speed;
+ b->dir = dir;
return b;
}
@@ -34,7 +37,8 @@ clear_ball(struct ball *b)
void
update_ball(struct ball *b)
{
- ++b;
+ b->x += cosf(b->dir) * b->speed;
+ b->y += sinf(b->dir) * b->speed;
}
void
diff --git a/src/ball.h b/src/ball.h
index 232d2e3..bf96d3a 100644
--- a/src/ball.h
+++ b/src/ball.h
@@ -9,10 +9,12 @@ static const float BALL_START_Y_NORMAL = 12;
struct ball {
float x;
float y;
+ float speed;
+ float dir;
struct ball *next;
};
-struct ball *new_ball(float x, float y);
+struct ball *new_ball(float x, float y, float speed, float dir);
void free_ball(struct ball *b);
void clear_ball(struct ball *b);
void update_ball(struct ball *b);
diff --git a/src/game.c b/src/game.c
index 7169fc3..013c0a4 100644
--- a/src/game.c
+++ b/src/game.c
@@ -122,7 +122,7 @@ update_game(struct game *g)
}
while (g->cur_balls < g->min_balls) {
- b = new_ball(BALL_START_X_NORMAL, BALL_START_Y_NORMAL);
+ b = new_ball(BALL_START_X_NORMAL, BALL_START_Y_NORMAL, 1, 0.f);
b->next = g->balls_head;
g->balls_head = b;
++g->cur_balls;