47 lines
929 B
C++
47 lines
929 B
C++
#include "SFML/Graphics.hpp"
|
|
|
|
using namespace sf;
|
|
|
|
int main()
|
|
{
|
|
RenderWindow window(VideoMode({ 640, 480 }), "Hello World Example");
|
|
|
|
CircleShape circle(100.0f);
|
|
circle.setFillColor(Color(200, 0, 0));
|
|
|
|
Texture texture("assets/card_clubs_02.png");
|
|
Sprite sprite(texture);
|
|
|
|
while (window.isOpen())
|
|
{
|
|
while (const std::optional event = window.pollEvent())
|
|
{
|
|
if (event->is<Event::Closed>())
|
|
{
|
|
window.close();
|
|
}
|
|
//else if (event->is<Event::KeyPressed>())
|
|
else if (const Event::KeyPressed* keyPressed = event->getIf<Event::KeyPressed>())
|
|
{
|
|
if (keyPressed->scancode == Keyboard::Scancode::Escape) {
|
|
window.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
// move circle
|
|
if (Keyboard::isKeyPressed(Keyboard::Scancode::Right))
|
|
{
|
|
circle.move(Vector2f(1, 0));
|
|
}
|
|
|
|
// clear window to start every from scratch
|
|
window.clear();
|
|
|
|
window.draw(circle);
|
|
window.draw(sprite);
|
|
window.display();
|
|
}
|
|
|
|
return 0;
|
|
} |