54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
#include <iostream>
|
|
|
|
#include "SFML/Graphics.hpp"
|
|
|
|
int main()
|
|
{
|
|
std::cout << "Game started\n";
|
|
sf::RenderWindow window(sf::VideoMode(600, 800), "My window");
|
|
window.setVerticalSyncEnabled(true);
|
|
window.setFramerateLimit(60);
|
|
|
|
sf::RectangleShape rectangle(sf::Vector2f(120.0f, 50.0f));
|
|
float sizeIncrement = 1.0f;
|
|
|
|
while (window.isOpen()) {
|
|
window.clear();
|
|
|
|
if(rectangle.getSize().x > 5 && rectangle.getSize().y > 5 && rectangle.getSize().x < 300 && rectangle.getSize().y < 300) {
|
|
rectangle.setSize(rectangle.getSize() + sf::Vector2f(sizeIncrement, sizeIncrement));
|
|
rectangle.setPosition(
|
|
float(window.getSize().x) / 2 - rectangle.getSize().x / 2,
|
|
float(window.getSize().y) / 2 - rectangle.getSize().y / 2
|
|
);
|
|
} else {
|
|
rectangle.setSize(sf::Vector2f(120.0f, 50.0f));
|
|
rectangle.setPosition(
|
|
float(window.getSize().x) / 2 - rectangle.getSize().x / 2,
|
|
float(window.getSize().y) / 2 - rectangle.getSize().y / 2
|
|
);
|
|
}
|
|
|
|
|
|
// Tu są handlowane eventy
|
|
sf::Event event{};
|
|
while (window.pollEvent(event)) {
|
|
if(event.type == sf::Event::MouseWheelScrolled) {
|
|
if(event.mouseWheelScroll.delta > 0) {
|
|
sizeIncrement = 1.0f;
|
|
} else {
|
|
sizeIncrement = -1.0f;
|
|
}
|
|
}
|
|
|
|
if (event.type == sf::Event::Closed)
|
|
window.close();
|
|
}
|
|
|
|
window.draw(rectangle);
|
|
window.display();
|
|
}
|
|
|
|
return 0;
|
|
}
|