Professional Documents
Culture Documents
Dodge
Dodge
#include <SFML/Graphics.hpp>
// main loop
while (window.isOpen()) {
// check all the window's events that were triggered since the last
iteration of the loop
sf::Event event;
while (window.pollEvent(event)) {
// "close requested" event: we close the window
if (event.type == sf::Event::Closed) {
window.close();
}
// "Escape key pressed" event: we close the window
if (event.type == sf::Event::KeyPressed && event.key.code ==
sf::Keyboard::Escape) {
window.close();
}
// Key pressed event
if (event.type == sf::Event::KeyPressed) {
sfClock.restart();
def_direction(direction, 1, event);
}
// Key released event
if (event.type == sf::Event::KeyReleased) {
def_direction(direction, 0, event);
}
}
if(std::find(std::begin(direction), std::end(direction), 1) !=
std::end(direction)) {
std::cout << direction[0] << direction[1] << direction[2] <<
direction[3] << std::endl;
std::cout << direction[3] - direction[2] << direction[1] - direction[0]
<< std::endl;
player.move(direction[3] - direction[2], direction[1] - direction[0],
sfClock);
}
return 0;
}