You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

74 lines
2.2 KiB
C++

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <utility>
#include <list>
#include <cmath>
#include <cstdlib>
#include <ctime>
// Описываем все классы, которые мы будем использовать в программе
// Это нужно сделать так как даже определение одного класса может зависеть от другого
// Например, класс Bonus зависит от класса Arkanoid и наоборот
struct Ball;
struct Brick;
struct Paddle;
class Bonus;
class BrickGrid;
class Arkanoid;
#include "paddle.hpp"
#include "brick_grid.hpp"
#include "ball.hpp"
#include "bonus.hpp"
#include "arkanoid.hpp"
int main ()
{
srand(time(0));
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(1000, 800, 32), "Arkanoid", sf::Style::Default, settings);
window.setFramerateLimit(120);
sf::Clock clock;
sf::Font font;
if (!font.loadFromFile("consola.ttf"))
{
std::cout << "Can't load font consola.ttf" << std::endl;
std::exit(1);
}
Arkanoid game({0, 0, 1000, 800}, font);
while (window.isOpen())
{
float dt = clock.restart().asSeconds();
//std::cout << "FPS=" << static_cast<int>(1.0 / dt) << "\n";
// Обработка событий
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape))
{
window.close();
}
if (event.type == sf::Event::MouseButtonPressed)
{
game.onMousePressed(event);
}
}
window.clear(sf::Color(0, 0, 0));
// Расчитываем новые координаты и новую скорость шарика
game.update(window, dt);
game.draw(window);
// Отображам всё нарисованное на временном "холсте" на экран
window.display();
}
return EXIT_SUCCESS;
}