61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#include <SFML/Graphics.hpp>
|
|
#include <iostream>
|
|
|
|
#define DELAY 30000
|
|
|
|
int main(int argc, char** argv) {
|
|
int x = 0, y = 0;
|
|
int max_x = 800, max_y = 600;
|
|
int direction = 0;
|
|
|
|
sf::RenderWindow window(sf::VideoMode(max_x, max_y), "SFML Window");
|
|
|
|
sf::Font font;
|
|
if (!font.loadFromFile("cascaydia.otf")) {
|
|
std::cerr << "Failed to load font" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
sf::Text text("o", font, 24);
|
|
text.setFillColor(sf::Color::White);
|
|
|
|
while (window.isOpen()) {
|
|
sf::Event event;
|
|
while (window.pollEvent(event)) {
|
|
if (event.type == sf::Event::Closed) {
|
|
window.close();
|
|
}
|
|
}
|
|
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && y > 0) {
|
|
y--;
|
|
}
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && y < max_y - 1) {
|
|
y++;
|
|
}
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && x > 0) {
|
|
x--;
|
|
}
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && x < max_x - 1) {
|
|
x++;
|
|
}
|
|
|
|
// Clear the window
|
|
window.clear();
|
|
|
|
// Set the position of the text
|
|
text.setPosition(x, y);
|
|
|
|
// Draw the text on the window
|
|
window.draw(text);
|
|
|
|
// Display everything that was drawn
|
|
window.display();
|
|
|
|
sf::sleep(sf::microseconds(DELAY));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|