From b0a83a90ef837095e92852f57741798a19f642ad Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Sun, 9 Jul 2023 13:10:18 +0200 Subject: [PATCH] Fixed collectable sizes --- src/config.h | 1 + src/game/collectables/collectable.cpp | 13 +++++++++---- src/game/collectables/collectable.hpp | 4 ++++ src/game/physics/holes/collectable_simulation.cpp | 5 +---- src/sprites/masked_sprite.cpp | 7 ++++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/config.h b/src/config.h index 50ce32a..fc6abee 100644 --- a/src/config.h +++ b/src/config.h @@ -33,6 +33,7 @@ #define WORLD_TO_ISO_SCALE 50.0f // 50.f, don't change. Rather adjust the zoom of the camera #define MASKED_HOLE_BORDER_TRANSITION_SIZE 0.2f #define MASKED_HOLE_DARKNESS_LIMIT 0.5f +#define COLLECTABLE_SCALE 5.f // Tracking view defaults #define DEF_TV_IS_ABSOLUTE_FREE_MOVE_THRESHOLD false diff --git a/src/game/collectables/collectable.cpp b/src/game/collectables/collectable.cpp index d87c374..6152fd6 100644 --- a/src/game/collectables/collectable.cpp +++ b/src/game/collectables/collectable.cpp @@ -24,11 +24,16 @@ float Collectable::getDepth() const void Collectable::setSprite(const std::string &spriteName) { // Create versatile sprite - float sizeWidth = 1.f * WORLD_TO_ISO_SCALE; - auto size = sf::Vector2f{sizeWidth, sizeWidth}; - auto sprite = std::make_shared(spriteName, size); + auto sprite = std::make_shared(spriteName); + size = sprite->getSize() * COLLECTABLE_SCALE; + sprite->setSize(size); addChildScreenOffset(sprite, IsometricCoordinates(-size / 2.f)); // Set half size offset of coordinates - coordinates->move(IsometricCoordinates(0, -sizeWidth / 2.f, 0)); + coordinates->move(IsometricCoordinates(0, -size.x / 2.f, 0)); +} + +sf::Vector2f Collectable::getSize() const +{ + return size / WORLD_TO_ISO_SCALE; } diff --git a/src/game/collectables/collectable.hpp b/src/game/collectables/collectable.hpp index e2931ab..70251d2 100644 --- a/src/game/collectables/collectable.hpp +++ b/src/game/collectables/collectable.hpp @@ -14,6 +14,8 @@ public: void setRotation(float angle); + sf::Vector2f getSize() const; + float getDepth() const; int getId() const @@ -25,6 +27,8 @@ private: int collectableId = 0; static inline int collectableCount = 0; + sf::Vector2f size; + std::shared_ptr consumedBy = nullptr; }; diff --git a/src/game/physics/holes/collectable_simulation.cpp b/src/game/physics/holes/collectable_simulation.cpp index f412320..e960909 100644 --- a/src/game/physics/holes/collectable_simulation.cpp +++ b/src/game/physics/holes/collectable_simulation.cpp @@ -18,10 +18,7 @@ CollectableSimulation::CollectableSimulation(const std::shared_ptr // Create body collectableBody = std::make_shared(world); auto coordinates = collectable->coordinates->diagonalWorld(); - -// todo: scale collectable and HOLE WIDTH SIZE based on factor - auto size = sf::Vector2f(1, 1); - collectableBody->createSquare(b2_dynamicBody, {coordinates.horizontal, coordinates.vertical}, size); + collectableBody->createSquare(b2_dynamicBody, {coordinates.horizontal, coordinates.vertical}, collectable->getSize()); } void CollectableSimulation::physicsUpdate() diff --git a/src/sprites/masked_sprite.cpp b/src/sprites/masked_sprite.cpp index 13e74fa..d47ba7a 100644 --- a/src/sprites/masked_sprite.cpp +++ b/src/sprites/masked_sprite.cpp @@ -135,11 +135,16 @@ sf::Color MaskedSprite::calculateNewPixelColor(sf::Color currentColor, sf::Vecto currentColor.b *= remainigBrightnessFactor; // Cut off pixels that are hidden in the ground, beyond the hole + auto players = PlayerCollection::getInstance()->getPlayers(); + if (players.empty()) + { + return currentColor; + } + float depth = coordinates->diagonalWorld().depth; auto pixelCoordinates = TranslatedCoordinates(DiagonalWorldCoordinates(position.x, position.y, depth)); std::vector holeAlphaFactors{}; - auto players = PlayerCollection::getInstance()->getPlayers(); for (auto &player: players) { auto holeMask = MaskedSpriteHole(player);