summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--paddle.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/paddle.c b/paddle.c
index 18b9962..7dcb2f2 100644
--- a/paddle.c
+++ b/paddle.c
@@ -1,3 +1,5 @@
+#include <math.h>
+
#include "SDL.h"
#include "SDL_opengl.h"
@@ -74,6 +76,11 @@ GLPong_PaddleInit(Paddle_t * paddle, GLfloat z, GLuint texture) {
void
GLPong_PaddleMove(Paddle_t * paddle, GLfloat x, GLfloat y) {
+ GLfloat old_x = paddle->coord.x;
+ GLfloat old_y = paddle->coord.y;
+ GLfloat mouse_x;
+ GLfloat mouse_y;
+
/* clamp paddle to border */
if (x <= -1.5f + (paddle->w / 2.0f)) {
x = -1.5f + (paddle->w / 2.0f);
@@ -87,6 +94,31 @@ GLPong_PaddleMove(Paddle_t * paddle, GLfloat x, GLfloat y) {
y = 1.0f - (paddle->h / 2.0f);
}
- paddle->coord.x = x - (paddle->w / 2.0f);
- paddle->coord.y = -(y + (paddle->h / 2.0f));
+ mouse_x = x - (paddle->w / 2.0f);
+ mouse_y = -(y + (paddle->h / 2.0f));
+ printf("(mouse_x, mouse_y) = (%.3f, %.3f)\n", mouse_x, mouse_y);
+
+ printf("x diff is %f\n", fabs(mouse_x - old_x));
+
+ if (fabs(mouse_x - old_x) > 0.33f / 2.0f) {
+ if (mouse_x > old_x) {
+ paddle->coord.x += 0.33f / 2.0f;
+ } else {
+ paddle->coord.x -= 0.33f / 2.0f;
+ }
+ } else {
+ paddle->coord.x = mouse_x;
+ }
+
+ printf("y diff is %f\n", fabs(mouse_y - old_y));
+
+ if (fabs(mouse_y - old_y) > 0.25f / 2.0f) {
+ if (mouse_y > old_y) {
+ paddle->coord.y += 0.25f / 2.0f;
+ } else {
+ paddle->coord.y -= 0.25f / 2.0f;
+ }
+ } else {
+ paddle->coord.y = mouse_y;
+ }
}