mirror of
https://github.com/dylanbenzi/pacmen-sfml.git
synced 2026-11-27 08:26:59 +00:00
add basic movement
This commit is contained in:
+25
-1
@@ -1,10 +1,15 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
|
||||
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);
|
||||
|
||||
sf::CircleShape pacman(25.0f);
|
||||
pacman.setFillColor(sf::Color(255, 255, 0));
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
while (const std::optional event = window.pollEvent())
|
||||
@@ -16,6 +21,25 @@ int main()
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user