diff --git a/include/player.h b/include/player.h index 6c07ecc..b23d1bb 100644 --- a/include/player.h +++ b/include/player.h @@ -14,8 +14,8 @@ class Player : public Entity { float distanceFromCursor(); bool jump(); void update(Ground& ground); - const char* getScore(); - const char* getHighscore(); + std::string getScore(); + std::string getHighscore(); int getScoreInt(); int isDead(); void reset(); @@ -28,4 +28,4 @@ class Player : public Entity { int highscore = 0; int timer = 0; int dead = 0; -}; \ No newline at end of file +}; diff --git a/src/main.cpp b/src/main.cpp index 6ef4c7f..35e3429 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,8 +26,6 @@ const int ALIVE = 0; const int CURSOR_DEATH = 1; const int HOLE_DEATH = 2; -const Uint8 *keyState; - RenderWindow window; std::vector playerTex; @@ -199,11 +197,15 @@ void gameLoop() { window.render(ground.getTile(i)); } + + std::string playerScore = player.getScore(); + std::string playerHighScore = player.getHighscore(); + window.render(25, 30, arrow); - window.render(62, 20, player.getScore(), font32_outline, black); - window.render(65, 23, player.getScore(), font32, white); + window.render(62, 20, playerScore.c_str(), font32_outline, black); + window.render(65, 23, playerScore.c_str(), font32, white); window.render(0, 65, highscoreBox); - window.render(65, 64, player.getHighscore(), font16, white); + window.render(65, 64, playerHighScore.c_str(), font16, white); if (player.isDead() != ALIVE) { @@ -243,4 +245,4 @@ int main(int argc, char* args[]) SDL_Quit(); return 0; -} \ No newline at end of file +} diff --git a/src/player.cpp b/src/player.cpp index e4c316e..b4f5f4d 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -138,18 +138,18 @@ void Player::update(Ground& ground) } -const char* Player::getScore() +std::string Player::getScore() { std::string s = std::to_string(score); s = "DISTANCE: " + s; - return s.c_str(); + return s; } -const char* Player::getHighscore() +std::string Player::getHighscore() { std::string s = std::to_string(highscore); s = "BEST: " + s; - return s.c_str(); + return s; } int Player::getScoreInt()