]> git.localhorst.tv Git - sdl-test8.git/blobdiff - src/pong/Ball.cpp
added collision engine, more or less stole gameplay from sdl-test7
[sdl-test8.git] / src / pong / Ball.cpp
diff --git a/src/pong/Ball.cpp b/src/pong/Ball.cpp
new file mode 100644 (file)
index 0000000..97248f3
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Ball.cpp
+ *
+ *  Created on: Apr 9, 2012
+ *      Author: holy
+ */
+
+#include "Ball.h"
+
+#include "Paddle.h"
+#include "../geometry/constants.h"
+
+#include <cmath>
+#include <SDL/SDL_gfxPrimitives.h>
+
+using game::Entity;
+using geometry::PI;
+
+
+namespace pong {
+
+Ball::Ball(Scalar r)
+: Entity(&shape, 4 * PI * r * r * r / 3)
+, shape(r) {
+
+}
+
+
+void Ball::Render(SDL_Surface *screen) const {
+       circleRGBA(screen, shape.Center().X(), shape.Center().Y(), shape.Radius(), 0xFF, 0xFF, 0xFF, 0xFF);
+       Vector angle(Vector(0, 1).Rotate(Angle()) * shape.Radius() + Origin());
+       lineRGBA(screen, shape.Center().X(), shape.Center().Y(), angle.X(), angle.Y(), 0xFF, 0xFF, 0xFF, 0xFF);
+}
+
+}