seminar13 - arkaniod splitted
parent
95f02e3ce0
commit
55990889cd
@ -0,0 +1,2 @@
|
|||||||
|
balls:
|
||||||
|
g++ ./balls.cpp -std=c++11 -o balls.exe -I../../../3rdparty/SFML-2.5.1/include -L ../../../3rdparty/SFML-2.5.1/lib/ -lsfml-graphics -lsfml-window -lsfml-system
|
Binary file not shown.
@ -0,0 +1,3 @@
|
|||||||
|
path = ../../../../3rdparty/SFML-2.5.1
|
||||||
|
arkanoid:
|
||||||
|
g++ -Wall -Wextra arkanoid.cpp -std=c++17 -o arkanoid.exe -I $(path)/include -L $(path)/lib/ -lsfml-graphics -lsfml-window -lsfml-system
|
@ -0,0 +1,20 @@
|
|||||||
|
class Bonus
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
inline static const float speed = 120;
|
||||||
|
inline static const float radius = 15;
|
||||||
|
|
||||||
|
sf::Vector2f m_position;
|
||||||
|
float m_time;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Bonus(sf::Vector2f position);
|
||||||
|
void update(float dt);
|
||||||
|
void draw(sf::RenderWindow& window) const;
|
||||||
|
void activate(Arkanoid& game);
|
||||||
|
|
||||||
|
bool isColiding(const Paddle& paddle) const;
|
||||||
|
// Класс Arkanoid должен быть дружественным, так как он может менять внутреннее объекта-бонуса
|
||||||
|
friend class Arkanoid;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,81 @@
|
|||||||
|
struct Brick
|
||||||
|
{
|
||||||
|
bool isActive;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BrickGrid
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
inline static const sf::Color color {100, 200, 250};
|
||||||
|
|
||||||
|
sf::FloatRect m_border;
|
||||||
|
int m_numBrickColumns;
|
||||||
|
int m_numBrickRows;
|
||||||
|
|
||||||
|
std::vector<Brick> m_bricks;
|
||||||
|
sf::RectangleShape m_brickShape;
|
||||||
|
|
||||||
|
int m_numActiveBricks;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BrickGrid() {}
|
||||||
|
BrickGrid(sf::FloatRect borders, int numBrickColumns, int numBrickRows) :
|
||||||
|
m_border(borders),
|
||||||
|
m_numBrickColumns(numBrickColumns),
|
||||||
|
m_numBrickRows(numBrickRows),
|
||||||
|
m_numActiveBricks(numBrickColumns * numBrickRows)
|
||||||
|
{
|
||||||
|
m_bricks.resize(m_numBrickColumns * m_numBrickRows, Brick{true});
|
||||||
|
m_brickShape.setSize(getBrickSizes());
|
||||||
|
m_brickShape.setOutlineColor(sf::Color::Black);
|
||||||
|
m_brickShape.setOutlineThickness(0.5);
|
||||||
|
m_brickShape.setFillColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::FloatRect getBorder() const
|
||||||
|
{
|
||||||
|
return m_border;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Vector2i getGridSizes() const
|
||||||
|
{
|
||||||
|
return {m_numBrickColumns, m_numBrickRows};
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Vector2f getBrickSizes() const
|
||||||
|
{
|
||||||
|
return {m_border.width / m_numBrickColumns, m_border.height / m_numBrickRows};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isBrickActive(std::pair<int, int> indexes) const
|
||||||
|
{
|
||||||
|
return m_bricks[indexes.first + indexes.second * m_numBrickColumns].isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deactivateBrick(std::pair<int, int> indexes)
|
||||||
|
{
|
||||||
|
m_bricks[indexes.first + indexes.second * m_numBrickColumns].isActive = false;
|
||||||
|
m_numActiveBricks--;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getNumActiveBricks() const
|
||||||
|
{
|
||||||
|
return m_numActiveBricks;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(sf::RenderWindow& window)
|
||||||
|
{
|
||||||
|
auto [brickWidth, brickHeight] = getBrickSizes();
|
||||||
|
|
||||||
|
for (int j = 0; j < m_numBrickRows; ++j)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_numBrickColumns; ++i)
|
||||||
|
{
|
||||||
|
if (!isBrickActive({i, j}))
|
||||||
|
continue;
|
||||||
|
m_brickShape.setPosition({m_border.left + i * brickWidth, m_border.top + j * brickHeight});
|
||||||
|
window.draw(m_brickShape);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Binary file not shown.
@ -0,0 +1,25 @@
|
|||||||
|
struct Paddle
|
||||||
|
{
|
||||||
|
inline static const sf::Color color {sf::Color::White};
|
||||||
|
sf::Vector2f position;
|
||||||
|
sf::Vector2f size;
|
||||||
|
|
||||||
|
Paddle() {}
|
||||||
|
Paddle(sf::Vector2f position, sf::Vector2f size) : position(position), size(size) {}
|
||||||
|
|
||||||
|
sf::FloatRect getBorder() const
|
||||||
|
{
|
||||||
|
return {position.x - size.x / 2.0f, position.y - size.y / 2.0f, size.x, size.y};
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(sf::RenderWindow& window)
|
||||||
|
{
|
||||||
|
static sf::RectangleShape shape{};
|
||||||
|
shape.setPosition(position - size / 2.0f);
|
||||||
|
shape.setSize(size);
|
||||||
|
shape.setFillColor(color);
|
||||||
|
window.draw(shape);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
Reference in New Issue