Skip to content

Commit

Permalink
removed PlatformGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-velicu committed Oct 29, 2023
1 parent 076925f commit 8bdb788
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 80 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ endif()
###############################################################################

# NOTE: update executable name in .github/workflows/cmake.yml:25 when changing name here
add_executable(${PROJECT_NAME} main.cpp doodle_jump/game/Game.cpp doodle_jump/platform/Platform.cpp doodle_jump/platform/PlatformGenerator.cpp doodle_jump/player/Player.cpp doodle_jump/screen/GameScreen.cpp doodle_jump/screen/MainMenu.cpp doodle_jump/screen/PlayScreen.cpp doodle_jump/screen/GameOver.cpp)
add_executable(${PROJECT_NAME} main.cpp doodle_jump/game/Game.cpp doodle_jump/platform/Platform.cpp doodle_jump/player/Player.cpp doodle_jump/screen/GameScreen.cpp doodle_jump/screen/MainMenu.cpp doodle_jump/screen/PlayScreen.cpp doodle_jump/screen/GameOver.cpp)

###############################################################################

Expand Down
30 changes: 12 additions & 18 deletions doodle_jump/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "./../screen/GameOver.h"
#include <iostream>
#include <string>
#include "./../platform/PlatformGenerator.h"

const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
Expand All @@ -16,11 +15,12 @@ Game::Game() {
maxScore = 0;
player = new Player();
platforms = std::vector<Platform*>();
lastPlatform = new Platform();

for (int i = 0; i < 15; i++) {
auto platform = new Platform();
platform->useGenerator(platformGenerator.getLastPlatformCoordinates());
platformGenerator.setLastPlatform(platform);
platform->useGenerator(lastPlatform->getSprite().getPosition());
lastPlatform = platform;
platforms.push_back(platform);
}

Expand All @@ -44,6 +44,8 @@ Game::~Game() {
for (auto& platform : platforms) {
delete platform;
}
delete lastPlatform;
delete scoreText;
}

std::ostream& operator<<(std::ostream& out, const Game& game) {
Expand All @@ -61,12 +63,12 @@ void Game::reset() {
}
platforms.clear();

platformGenerator.setLastPlatform(new Platform());
lastPlatform = new Platform();

for (int i = 0; i < 15; i++) {
auto platform = new Platform();
platform->useGenerator(platformGenerator.getLastPlatformCoordinates());
platformGenerator.setLastPlatform(platform);
platform->useGenerator(lastPlatform->getSprite().getPosition());
lastPlatform = platform;
platforms.push_back(platform);
}
score = 0;
Expand Down Expand Up @@ -162,8 +164,8 @@ void Game::checkCollision() {
if (platform->getType() == PlatformType::BREAKABLE) {
delete platform;
auto plat = new Platform();
plat->useGenerator(platformGenerator.getLastPlatformCoordinates());
platformGenerator.setLastPlatform(plat);
plat->useGenerator(lastPlatform->getSprite().getPosition());
lastPlatform = plat;
platform = plat;
}
else if (platform->getType() == PlatformType::BOOST) {
Expand Down Expand Up @@ -202,8 +204,8 @@ void Game::play() {
if (platform->getSprite().getPosition().y > 750.0f) {
delete platform;
auto plat = new Platform();
plat->useGenerator(platformGenerator.getLastPlatformCoordinates());
platformGenerator.setLastPlatform(plat);
plat->useGenerator(lastPlatform->getSprite().getPosition());
lastPlatform = plat;
platform = plat;
}

Expand Down Expand Up @@ -237,14 +239,6 @@ void Game::displayScore() {
window.draw(*scoreText);
}

// int Game::getScore() const {
// return score;
// }

// void Game::setScore(int score_) {
// score = score_;
// }

void Game::changeScreen(ScreenType screenType) {
currentScreen = screenType;
}
7 changes: 1 addition & 6 deletions doodle_jump/game/Game.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "./../platform/Platform.h"
#include "./../platform/PlatformGenerator.h"
#include "./../player/Player.h"
#include "./../screen/GameScreen.h"

Expand All @@ -18,16 +17,12 @@ class Game {
sf::Text *scoreText;
Player *player;
std::vector<Platform*> platforms;
PlatformGenerator platformGenerator = PlatformGenerator();
Platform* lastPlatform;
public:
Game();
~Game();
Game& operator=(const Game& game_);
Game(const Game& game_);
friend std::ostream& operator<<(std::ostream& out, const Game& game);
void run();
// int getScore() const;
// void setScore(int score);
void changeScreen(ScreenType screenType);
void play();
void reset();
Expand Down
23 changes: 23 additions & 0 deletions doodle_jump/platform/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ Platform::Platform() {
sprite.setPosition((float)x, (float)y);
}

Platform::~Platform() {
std::cout << "Platform destructor called\n";
}

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

Platform& Platform::operator=(const Platform& platform) {
std::cout << "Platform copy assignment operator called\n";
if (this != &platform) {
type = platform.type;
texture = platform.texture;
sprite = platform.sprite;
updateCount = platform.updateCount;
}
return *this;
}

void Platform::useGenerator(const sf::Vector2f& lastPlatformCoordinates) {
std::cout << "Platform constructor called\n";

Expand Down
3 changes: 3 additions & 0 deletions doodle_jump/platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Platform {
int updateCount;
public:
Platform();
~Platform();
Platform(const Platform& platform);
Platform& operator=(const Platform& platform);
void useGenerator(const sf::Vector2f& lastPlatformCoordinates);
friend std::ostream& operator<<(std::ostream& os, const Platform& platform);
PlatformType getType() const;
Expand Down
38 changes: 0 additions & 38 deletions doodle_jump/platform/PlatformGenerator.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions doodle_jump/platform/PlatformGenerator.h

This file was deleted.

0 comments on commit 8bdb788

Please sign in to comment.