7Ball::Ball(
int x,
int y,
int radius,
const SDL_Color &color,
const std::string&
id)
13void Ball::render(std::shared_ptr<SDL_Renderer> renderer, SDL_Color color1,SDL_Color color2) {
14 collider->render(renderer,color1,color2);
33 float len = std::sqrt(dx * dx + dy * dy);
47 auto normalized = [] (
point v){
48 float len = std::sqrt(std::pow(v.x, 2) + std::pow(v.y, 2));
50 return point{v.
x/len, v.y/len};
55 return v1.
x*v2.x+v1.
y*v2.y;
58 point vectNorm = normalized(vectDir);
void move() override
Moves the ball according to its velocity.
void render(std::shared_ptr< SDL_Renderer > renderer, SDL_Color color1, SDL_Color color2) override
Renders the ball on the screen.
Ball(int x, int y, int radius, const SDL_Color &color, const std::string &id)
Constructs a new Ball object.
void handleCollision(point vect)
Handles collision with a single object.
void setVelocity(float dx, float dy)
Sets the velocity of the ball.
void handleCollisions(point collision) override
Handles collisions with other objects.
std::shared_ptr< Collider > collider
The collider associated with the object.
The MovingObject class represents a moving colliding object.
The point struct represents a point in 2D space.
float y
The y-coordinate of the point.
float x
The x-coordinate of the point.