-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit f9f3031.
- Loading branch information
Showing
3 changed files
with
25 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,31 @@ | ||
#include "score.h" | ||
|
||
Score::Score(sf::RenderWindow &window, Ball& ball): mWindow(window), mBall(ball) { | ||
Score::font.loadFromFile("content/font.ttf"); | ||
const_cast<sf::Texture&>(Score::font.getTexture(128)).setSmooth(false); | ||
Score::Score(sf::RenderWindow &window): mWindow(window), playerText(sf::Text()), enemyText(sf::Text()) { | ||
sf::Font arial; | ||
arial.loadFromFile("content/arial.ttf"); | ||
|
||
Score::playerText.setFont(arial); | ||
Score::enemyText.setFont(arial); | ||
|
||
Score::playerText.setCharacterSize(60); | ||
Score::enemyText.setCharacterSize(60); | ||
|
||
Score::playerText.setPosition(sf::Vector2f(0.0f, 0.0f)); | ||
Score::enemyText.setPosition(sf::Vector2f(0.0f, 0.0f)); | ||
|
||
Score::updateScore(0, 0); | ||
Score::Resize(); | ||
|
||
Score::mWindow.draw(Score::playerText); | ||
} | ||
|
||
void Score::updateScore(int player, int enemy) { | ||
Score::playerScore += player; | ||
Score::enemyScore += enemy; | ||
} | ||
|
||
void Score::Resize() { | ||
sf::Vector2f windowSize(this->mWindow.getView().getSize()); | ||
|
||
Score::playerPosition = sf::Vector2f(windowSize.x / 2 - 10.0f, 21.0f); | ||
Score::enemyPosition = sf::Vector2f(windowSize.x / 2 + 10.0f, 21.0f); | ||
|
||
Score::playerText.setString("00"); | ||
Score::enemyText.setString("00"); | ||
} | ||
|
||
void Score::draw(float deltaTime) { | ||
// Update scores | ||
sf::Vector2f windowSize(this->mWindow.getView().getSize()); | ||
sf::Vector2f ballPosition = Score::mBall.getPosition(); | ||
sf::Vector2f ballVelocity = Score::mBall.getVelocity(); | ||
if (canScore) { | ||
if (ballPosition.x <= 6 && ballVelocity.x < 0) { | ||
Score::updateScore(1, 0); | ||
canScore = 0; | ||
} else if (ballPosition.x >= windowSize.x - 6 && ballVelocity.x > 0) { | ||
Score::updateScore(0, 1); | ||
canScore = 0; | ||
} | ||
} else { | ||
float centre = windowSize.x / 2; | ||
if (ballPosition.x >= centre - 15.0f && ballPosition.x <= centre + 15.05) | ||
canScore = 1; | ||
} | ||
|
||
// Draw text | ||
std::string playerScore = std::to_string(this->playerScore); | ||
std::string enemyScore = std::to_string(this->enemyScore); | ||
|
||
sf::Text player(enemyScore, Score::font, 64); | ||
player.setOrigin(sf::Vector2f(player.getLocalBounds().width, 0)); | ||
player.setPosition(Score::playerPosition); | ||
Score::mWindow.draw(player); | ||
|
||
sf::Text enemy(playerScore, Score::font, 64); | ||
enemy.setPosition(Score::enemyPosition); | ||
Score::mWindow.draw(enemy); | ||
// Score::mWindow.draw(Score::enemyText); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters