add basic movement

This commit is contained in:
2025-11-02 20:44:23 -05:00
parent 60cbab42d8
commit 4a098a128a
+25 -1
View File
@@ -1,10 +1,15 @@
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Window/Keyboard.hpp>
int main() int main()
{ {
auto window = sf::RenderWindow(sf::VideoMode({1920u, 1080u}), "CMake SFML Project"); auto window = sf::RenderWindow(sf::VideoMode({1920u, 1080u}), "Pacmen");
window.setFramerateLimit(144); window.setFramerateLimit(144);
sf::CircleShape pacman(25.0f);
pacman.setFillColor(sf::Color(255, 255, 0));
while (window.isOpen()) while (window.isOpen())
{ {
while (const std::optional event = window.pollEvent()) while (const std::optional event = window.pollEvent())
@@ -16,6 +21,25 @@ int main()
} }
window.clear(); window.clear();
window.draw(pacman);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
pacman.move({0, -5.0f});
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
pacman.move({-5.0f, 0});
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) {
pacman.move({0, 5.0f});
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
pacman.move({5.0f, 0});
}
window.display(); window.display();
} }
} }