#ifndef GRAPHICS_H #define GRAPHICS_H #include "GameLogic.h" class Graphics { public: Graphics(int w, int h, float scale, std::string name) { window = new sf::RenderWindow(sf::VideoMode(w, h), name); this->scale = scale; } void Begin(float dt) { sf::Vector2f speed(0, 0); sf::Event event; sf::Event result; while (window->pollEvent(event)) { if (event.type == sf::Event::Closed) window->close(); if(event.type == sf::Event::KeyPressed) { if(event.key.code == sf::Keyboard::Escape) { window->close(); } if(event.key.code==sf::Keyboard::Left) speed.x = -100; if(event.key.code==sf::Keyboard::Up) speed.y = -100; if(event.key.code==sf::Keyboard::Down) speed.y = 100; if(event.key.code==sf::Keyboard::Right)speed.x = 100; result = event; } if (event.type == sf::Event::MouseMoved) // делать высвечивание клетки!! { if ((event.mouseMove.x==0)&&(event.mouseMove.y==0)) window->close(); } } sf::Vector2u size = window->getSize(); position+=speed*dt; window->setView(sf::View(position, sf::Vector2f(1.f*size.x/scale, 1.f*size.y/scale))); window->clear(sf::Color::White); } void End() { window->display(); } bool IsRunning() { return window->isOpen(); } void DrawScene(Scene* scene) { for(int i = 0; i < scene->cells.size(); i++) { DrawCell(scene->cells[i]); } } sf::Vector2f position; private: void DrawCell(Cell* cell) { shape.setFillColor(cell->color); shape.setRadius(cell->radius); shape.setOrigin(shape.getRadius(), shape.getRadius()); shape.setPosition(cell->position); window->draw(shape); } sf::RenderWindow* window; sf::CircleShape shape; float scale; }; #endif // GRAPHICS_H