#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
int x = 200,y = 200;
int delta_x=0;
int delta_y=0;
bool grabbed=false;
RenderWindow window(VideoMode(800,800), "SFML works!");
RectangleShape okolo(Vector2f(200,200));
okolo.setFillColor(Color::Black);
okolo.setPosition(Vector2f(x,y));
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Left)
{
okolo.setPosition(Vector2f(x-200,y));
x-=200;
}
}
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Right)
{
okolo.setPosition(Vector2f(x+200,y));
x+=200;
}
}
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Up)
{
okolo.setPosition(Vector2f(x,y-200));
y-=200;
}
}
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Down)
{
okolo.setPosition(Vector2f(x,y+200));
y+=200;
}
}
if (Mouse::isButtonPressed(Mouse::Left))
{
if(okolo.getGlobalBounds().contains(Mouse::getPosition(window).x,Mouse::getPosition(window).y))
{
if (!grabbed)
{
delta_x=Mouse::getPosition(window).x-okolo.getPosition().x;
delta_y=Mouse::getPosition(window).y-okolo.getPosition().y;
}
grabbed=true;
}
if (grabbed)
{
okolo.setPosition(Vector2f(Mouse::getPosition(window).x-delta_x, Mouse::getPosition(window).y-delta_y));
x = Mouse::getPosition(window).x;
y = Mouse::getPosition(window).y;
}
}
else
{
grabbed=false;
}
}
if (event.type == Event::Closed)
window.close();
window.clear(Color::White);
window.draw(okolo);
window.display();
}
return 0;
}
if (Mouse::isButtonReleased(Mouse::Left))
else
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
int x = 200,y = 200;
bool grabbed=false;
RenderWindow window(VideoMode(800,800), "SFML works!");
RectangleShape okolo(Vector2f(200,200));
okolo.setFillColor(Color::Black);
okolo.setPosition(Vector2f(x,y));
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Left)
{
okolo.setPosition(Vector2f(x-200,y));
x-=200;
}
}
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Right)
{
okolo.setPosition(Vector2f(x+200,y));
x+=200;
}
}
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Up)
{
okolo.setPosition(Vector2f(x,y-200));
y-=200;
}
}
if(event.type == Event::KeyPressed)
{
if(event.key.code == Keyboard::Down)
{
okolo.setPosition(Vector2f(x,y+200));
y+=200;
}
}
if (Mouse::isButtonPressed(Mouse::Left))
{
if(okolo.getGlobalBounds().contains(Mouse::getPosition(window).x,Mouse::getPosition(window).y))
{
grabbed=true;
}
if (grabbed)
{
okolo.setPosition(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y));
x = Mouse::getPosition(window).x;
y = Mouse::getPosition(window).y;
}
}
if (Mouse::isButtonReleased(Mouse::Left))
{
grabbed=false;
}
}
if (event.type == Event::Closed)
window.close();
window.clear(Color::White);
window.draw(okolo);
window.display();
}
return 0;
}
if(okolo.getGlobalBounds().contains(Mouse::getPosition(window).x,Mouse::getPosition(window).y))
okolo.setPosition(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y));
okolo.setPosition(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y));
x = Mouse::getPosition(window).x;
y = Mouse::getPosition(window).y
okolo.setPosition(Vector2f(Mouse::getPosition(window).x-100, Mouse::getPosition(window).y-100));
x = Mouse::getPosition(window).x;
y = Mouse::getPosition(window).y