5 #include <SFML/Graphics.hpp> 12 PlayerSFML::PlayerSFML(
double x,
double y, sf::RenderWindow &window,
double speed,
const string &textureFile) :
13 screenOrigin(x, y), windowSFML(window), transformation(
Transformation::getInstance()), Player(0, 0, speed) {
16 if(!texture.loadFromFile(textureFile)) {
17 throw runtime_error(
"Couldn't load player texture image: " + textureFile);
19 texture.setSmooth(
true);
20 sprite.setTexture(texture);
23 sprite.setPosition(x, y);
27 sf::FloatRect rect = sprite.getLocalBounds();
39 speed = originalSpeed;
46 if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right) && !sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left) && sprite.getPosition().x < windowSFML.getSize().x - 33 - sprite.getLocalBounds().width) {
48 }
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left) && !sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right) && sprite.getPosition().x > 33) {
55 sprite.move(velocity.
x, velocity.
y);
59 if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space)) {
66 windowSFML.draw(sprite);
70 sprite.setPosition(screenOrigin.
x, screenOrigin.
y);
void setSize(pair< double, double > newSize)
int speedUpDuration
In frames.
All the game gui elements of the Arkanoid game.
double y
The 'y' component of the Vector2D.
double x
The 'x' component of the Vector2D.
void setPosition(double x, double y)