Skip to content
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

A fixes issue #16: Pointer to dealocated memory #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -28,4 +28,4 @@ class Player : public Entity {
int highscore = 0;
int timer = 0;
int dead = 0;
};
};
14 changes: 8 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SDL_Texture*> playerTex;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -243,4 +245,4 @@ int main(int argc, char* args[])
SDL_Quit();

return 0;
}
}
8 changes: 4 additions & 4 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down