This repository has been archived on 2023-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_cpp/seminar13_polymorphism/arkanoid/ball.hpp

35 lines
875 B
C++
Raw Normal View History

2023-01-04 14:37:54 +03:00
#pragma once
2023-01-04 14:56:03 +03:00
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
class BrickGrid;
class Paddle;
2023-01-04 14:37:54 +03:00
2023-01-04 13:46:41 +03:00
struct Ball
{
inline static const float initialVelocity = 700;
inline static const sf::Color color {246, 213, 92};
float radius;
sf::Vector2f position;
sf::Vector2f velocity;
2023-01-06 00:44:44 +03:00
/* Every bit is responsible for ball being affected by some effect */
char affectedBy = 0;
2023-01-04 14:37:54 +03:00
Ball(float radius, sf::Vector2f position, sf::Vector2f velocity);
2023-01-04 13:46:41 +03:00
2023-01-04 14:37:54 +03:00
void update(float dt);
2023-01-04 13:46:41 +03:00
2023-01-04 14:37:54 +03:00
void draw(sf::RenderWindow& window);
2023-01-04 13:46:41 +03:00
2023-01-04 14:37:54 +03:00
std::pair<sf::Vector2f, bool> findClosestPoint(const sf::FloatRect& rect) const;
2023-01-04 13:46:41 +03:00
2023-01-04 14:37:54 +03:00
bool handleRectCollision(const sf::FloatRect& rect);
2023-01-04 13:46:41 +03:00
2023-01-04 14:37:54 +03:00
void handleWallsCollision(sf::FloatRect boundary);
2023-01-04 13:46:41 +03:00
2023-01-04 14:37:54 +03:00
std::pair<int, int> handleBrickGridCollision(const BrickGrid& brickGrid);
2023-01-04 13:46:41 +03:00
2023-01-04 14:37:54 +03:00
void handlePaddleCollision(const Paddle& paddle);
2023-01-04 13:46:41 +03:00
};