Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-velicu committed Nov 7, 2023
1 parent ae51c4c commit b2382ec
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 31 deletions.
15 changes: 15 additions & 0 deletions doodle_jump/game/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ class PowerDrawer {
gameObject = gameObject_;
}

void assignTexture(sf::Texture& texture) {
if (gameObject != nullptr)
gameObject->assignTexture(texture);
}

sf::Texture& getTexture() {
if (gameObject != nullptr)
return gameObject->getTexture();
}

sf::Sprite getSprite() {
if (gameObject != nullptr)
return gameObject->getSprite();
}

void draw(sf::RenderWindow& window, const sf::Sprite& sprite) {
std::cout << "PowerDrawer draw called\n";

Expand Down
9 changes: 7 additions & 2 deletions doodle_jump/game_object/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ GameObject::~GameObject() {
std::cout << "GameObject destructor called\n";
}

void GameObject::draw(sf::RenderWindow &window, const sf::Sprite& sprite) {
window.draw(sprite);
void GameObject::assignTexture(sf::Texture& texture_) {
texture = texture_;
sprite.setTexture(texture);
}

void GameObject::draw(sf::RenderWindow &window, const sf::Sprite& sprite_) {
window.draw(sprite_);
}
12 changes: 11 additions & 1 deletion doodle_jump/game_object/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,15 @@ class GameObject {
public:
GameObject();
virtual ~GameObject();
virtual void draw(sf::RenderWindow& window, const sf::Sprite& sprite);
virtual void assignTexture(sf::Texture& texture_);

virtual sf::Texture& getTexture() {
return texture;
}

virtual sf::Sprite getSprite() {
return sprite;
}

virtual void draw(sf::RenderWindow& window, const sf::Sprite& sprite_);
};
48 changes: 24 additions & 24 deletions doodle_jump/powerups/Powerups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ std::ostream& operator<<(std::ostream& out, const PowerupsType& powerupsType) {
return out;
}

void Powerups::setGameObject(GameObject *gameObject_) {
gameObject = gameObject_;
}
// void Powerups::setGameObject(GameObject *gameObject_) {
// gameObject = gameObject_;
// }

void Powerups::useGenerator(const sf::Vector2f& lastPlatformCoordinates) {
std::cout << "Powerups constructor called\n";
Expand Down Expand Up @@ -67,33 +67,33 @@ PowerupsType Powerups::getType() const {
return type;
}

sf::Sprite Powerups::getSprite() const {
return sprite;
}
// sf::Sprite Powerups::getSprite() const {
// return sprite;
// }

void Powerups::assignTexture(sf::Texture& texture_) {
texture = &texture_;
sprite.setTexture(*texture);
}
// void Powerups::assignTexture(sf::Texture& texture_) {
// texture = &texture_;
// sprite.setTexture(*texture);
// }

void Powerups::moveSprite(const sf::Vector2f& coordinates_) {
sprite.move(coordinates_);
}

void Powerups::animateMovement() {
updateCount++;
if (updateCount == 100) {
updateCount = 0;
}
sprite.move(0.0f, 1.0f);
}
// void Powerups::animateMovement() {
// updateCount++;
// if (updateCount == 100) {
// updateCount = 0;
// }
// sprite.move(0.0f, 1.0f);
// }

void Powerups::draw(sf::RenderWindow& window, const sf::Sprite& sprite_) {
// window.draw(sprite_);
if (gameObject != nullptr) {
gameObject->draw(window, sprite_);
}
else {
std::cout << "Powerups::draw() gameObject is nullptr\n";
}
window.draw(sprite_);
// if (gameObject != nullptr) {
// gameObject->draw(window, sprite_);
// }
// else {
// std::cout << "Powerups::draw() gameObject is nullptr\n";
// }
}
8 changes: 4 additions & 4 deletions doodle_jump/powerups/Powerups.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Powerups : public GameObject {
void useGenerator(const sf::Vector2f& lastPlatformCoordinates);
friend std::ostream& operator<<(std::ostream& os, const Powerups& powerups);
PowerupsType getType() const;
sf::Sprite getSprite() const;
void assignTexture(sf::Texture& texture_);
void setGameObject(GameObject* gameObject_);
// sf::Sprite getSprite() const;
// void assignTexture(sf::Texture& texture_);
// void setGameObject(GameObject* gameObject_);
void moveSprite(const sf::Vector2f& coordinates_);
void animateMovement();
// void animateMovement();
void draw(sf::RenderWindow& window, const sf::Sprite& sprite) override;
};

0 comments on commit b2382ec

Please sign in to comment.