Skip to content

Conversation

@EwanFoley
Copy link

added mouse input for the paddle
added fade out effect on bricks once hit

Comment on lines +40 to +46
/*if (position < screen.width/2) {
_sprite.move(sf::Vector2f(-dt * PADDLE_SPEED, 0));
}
if (position > screen.width/2) {
_sprite.move(sf::Vector2f(dt * PADDLE_SPEED, 0));*/
//}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to include old code commented out—version control handles that


void Paddle::moveMouse(float dt) {
sf::VideoMode screen = sf::VideoMode::getDesktopMode();
float position = sf::Mouse::getPosition().x;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to assign this value to a variable as the variable is only ever used once elsewhere in this scope; might as well just write sf::Mouse::getPosition().x instead of position.

if (position > screen.width/2) {
_sprite.move(sf::Vector2f(dt * PADDLE_SPEED, 0));*/
//}
_sprite.setPosition(sf::Vector2f(position, _sprite.getPosition().y));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous code would effectively clamp the x position of the paddle so that it could never go off screen, but this implementation causes the paddle to go off screen any time the mouse goes near the edges of the window. Must add position clamping checks such as those in the old code.

}
}

void Paddle::moveMouse(float dt) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't make use of delta time as it snaps directly to the mouse pointer without lerping or anything similar. Must remove dt parameter from function signature.

Comment on lines +81 to +82
/*if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) _paddle->moveRight(dt);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) _paddle->moveLeft(dt);*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant code entirely, can be restored via version control


private:
sf::RectangleShape _shape;
sf::Uint8 alpha = 255;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sf::Uint8 is deprecated and not really necessary anymore, can just use std::uint8_t from stdint.h for compatibility

sf::FloatRect getBounds() const;
void setDestroyed(bool destroyed) { _isDestroyed = destroyed; }
bool getDestroyed() { return _isDestroyed; }
sf::Uint8 getAlpha() { return alpha; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a const function, e.g.:

sf::Uint8 getAlpha() const { return alpha; }

Additionally, could be tagged with [[nodiscard]] to prevent misuse

[[nodiscard]] sf::Uint8 getAlpha() const { return alpha; }

void render(sf::RenderWindow& window);
sf::FloatRect getBounds() const;
void setDestroyed(bool destroyed) { _isDestroyed = destroyed; }
bool getDestroyed() { return _isDestroyed; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be const function

Comment on lines +22 to +23
alpha -= 5;
if (alpha <= 0) alpha = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code can be compressed:

alpha = std::max(0, alpha - 5);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants