-
Notifications
You must be signed in to change notification settings - Fork 115
Patch 5a: Code test #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| /*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));*/ | ||
| //} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
| /*if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) _paddle->moveRight(dt); | ||
| if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) _paddle->moveLeft(dt);*/ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be const function
| alpha -= 5; | ||
| if (alpha <= 0) alpha = 0; |
There was a problem hiding this comment.
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);
added mouse input for the paddle
added fade out effect on bricks once hit