]> git.localhorst.tv Git - sdl-test8.git/blob - src/pong/Ball.cpp
added collision engine, more or less stole gameplay from sdl-test7
[sdl-test8.git] / src / pong / Ball.cpp
1 /*
2  * Ball.cpp
3  *
4  *  Created on: Apr 9, 2012
5  *      Author: holy
6  */
7
8 #include "Ball.h"
9
10 #include "Paddle.h"
11 #include "../geometry/constants.h"
12
13 #include <cmath>
14 #include <SDL/SDL_gfxPrimitives.h>
15
16 using game::Entity;
17 using geometry::PI;
18
19
20 namespace pong {
21
22 Ball::Ball(Scalar r)
23 : Entity(&shape, 4 * PI * r * r * r / 3)
24 , shape(r) {
25
26 }
27
28
29 void Ball::Render(SDL_Surface *screen) const {
30         circleRGBA(screen, shape.Center().X(), shape.Center().Y(), shape.Radius(), 0xFF, 0xFF, 0xFF, 0xFF);
31         Vector angle(Vector(0, 1).Rotate(Angle()) * shape.Radius() + Origin());
32         lineRGBA(screen, shape.Center().X(), shape.Center().Y(), angle.X(), angle.Y(), 0xFF, 0xFF, 0xFF, 0xFF);
33 }
34
35 }