Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-velicu committed Oct 29, 2023
1 parent 8bdb788 commit 322b227
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
61 changes: 50 additions & 11 deletions doodle_jump/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,45 @@ Game::~Game() {
delete scoreText;
}

Game::Game(const Game& game) {
std::cout << "Game copy constructor called\n";
currentScreen = game.currentScreen;

if (window.isOpen())
window.close();
window.create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), windowTitle, sf::Style::Default);
window.setFramerateLimit(120);

font = game.font;
score = game.score;
maxScore = game.maxScore;
scoreText = game.scoreText;
player = game.player;
platforms = game.platforms;
lastPlatform = game.lastPlatform;
}

Game& Game::operator=(const Game& game) {
std::cout << "Game copy assignment operator called\n";
if (this != &game) {
currentScreen = game.currentScreen;

if (window.isOpen())
window.close();
window.create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), windowTitle, sf::Style::Default);
window.setFramerateLimit(120);

font = game.font;
score = game.score;
maxScore = game.maxScore;
scoreText = game.scoreText;
player = game.player;
platforms = game.platforms;
lastPlatform = game.lastPlatform;
}
return *this;
}

std::ostream& operator<<(std::ostream& out, const Game& game) {
out << "Game object\n"
<< "Current screen: " << game.currentScreen << '\n'
Expand Down Expand Up @@ -182,17 +221,17 @@ void Game::checkCollision() {
}
}

void Game::displayDebugInfo() {
sf::Text debugText = sf::Text();
debugText.setFont(font);
sf::Vector2f velocity = player->getVelocity();
debugText.setString("xVelocity: " + std::to_string(velocity.x) + "\nyVelocity: " + std::to_string(velocity.y));
debugText.setCharacterSize(36);
debugText.setFillColor(sf::Color::Black);
debugText.setPosition(60, 60);
// void Game::displayDebugInfo() {
// sf::Text debugText = sf::Text();
// debugText.setFont(font);
// sf::Vector2f velocity = player->getVelocity();
// debugText.setString("xVelocity: " + std::to_string(velocity.x) + "\nyVelocity: " + std::to_string(velocity.y));
// debugText.setCharacterSize(36);
// debugText.setFillColor(sf::Color::Black);
// debugText.setPosition(60, 60);

window.draw(debugText);
}
// window.draw(debugText);
// }

void Game::play() {
player->update();
Expand Down Expand Up @@ -225,7 +264,7 @@ void Game::play() {
window.draw(platform->getSprite());
}
displayScore();
displayDebugInfo();
// displayDebugInfo();

window.display();
}
Expand Down
4 changes: 3 additions & 1 deletion doodle_jump/game/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class Game {
public:
Game();
~Game();
Game(const Game& game); // for cppcheck
Game& operator=(const Game& game); // for cppcheck
friend std::ostream& operator<<(std::ostream& out, const Game& game);
void run();
void changeScreen(ScreenType screenType);
void play();
void reset();
void displayDebugInfo();
// void displayDebugInfo();
void displayScore();
void checkCollision();
};
4 changes: 1 addition & 3 deletions doodle_jump/platform/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ Platform::~Platform() {
std::cout << "Platform destructor called\n";
}

Platform::Platform(const Platform& platform) {
Platform::Platform(const Platform& platform) : texture(platform.texture), sprite(platform.sprite) {
std::cout << "Platform copy constructor called\n";
type = platform.type;
texture = platform.texture;
sprite = platform.sprite;
updateCount = platform.updateCount;
}

Expand Down

0 comments on commit 322b227

Please sign in to comment.