Professional Documents
Culture Documents
Lecture1 Notes
Lecture1 Notes
isOpen()) {
deltaTime = clock.restart().asSeconds();
sf::Event evnt;
while (window.pollEvent(evnt)) {
switch (evnt.type) {
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
movement.x = 0.0f;
movement.y = 0.0f;
currentPos = player.getBodyPosition();
/* player.getBodyPosition() points to this in Player
class:
sf::Vector2f Player::getBodyPosition() { return
body.getPosition(); }
*/
if (evnt.key.code == sf::Keyboard::W) {
movement.x -= speed * deltaTime;
}
if (evnt.key.code == sf::Keyboard::S) {
movement.x -= speed * deltaTime;
}
if (evnt.key.code == sf::Keyboard::A) {
if (currentPos.x > 0) movement.x -= speed * deltaTime;
}
if (evnt.key.code == sf::Keyboard::D) {
if (currentPos.x < 572) movement.x += speed * deltaTime;
}
break;
case sf::Event::KeyReleased:
movement.x = 0.0f;
movement.y = 0.0f;
}
}
window.draw(text);
window.draw(chrPos);
player.Draw(window);
window.display();