diff --git a/src/include/UIObjects/UIEnemyOverview.hpp b/src/include/UIObjects/UIEnemyOverview.hpp index 231e23a..62876d0 100644 --- a/src/include/UIObjects/UIEnemyOverview.hpp +++ b/src/include/UIObjects/UIEnemyOverview.hpp @@ -12,25 +12,25 @@ #include "Game.hpp" class UIEnemyOverview { - public: - UIEnemyOverview(Enemy enemy); - UIEnemyOverview(); - - Enemy creature; - UIColorPicker colorPicker = UIColorPicker("colorPIC_default.png", "color_picker_border.png"); - sf::Text pickedColorText; + public: + UIEnemyOverview(Enemy enemy); + UIEnemyOverview(); - void setEnemy(Enemy enemy); - void changeHealth(int value); - void updatePickedColorText(std::string newText, sf::Color pickedColor); - void draw(); + Enemy enemy; + UIColorPicker colorPicker = UIColorPicker("colorPIC_default.png", "color_picker_border.png"); + sf::Text pickedColorText; - private: - UIBox backgroundBox = UIBox(sf::Color(51, 25, 0, 150), "borders/metal_border_900x900.png"); - sf::Texture creatureBackgroundTX; - sf::Sprite creatureBackgroundSP; - UIStats statsComponent; - UIBorderedImage creatureFrame; + void initEnemy(Enemy enemy); + void changeHealth(int value); + void updatePickedColorText(std::string newText, sf::Color pickedColor); + void draw(); + + private: + UIBox box = UIBox(sf::Color(51, 25, 0, 150), "borders/metal_border_900x900.png"); + sf::Texture enemyIconBackgroundTX; + sf::Sprite enemyIconBackgroundSP; + UIStats enemyStats; + UIBorderedImage enemyBorderedImage; }; #endif \ No newline at end of file diff --git a/src/main/Activities/FightActivity.cpp b/src/main/Activities/FightActivity.cpp index a21f269..d34fded 100644 --- a/src/main/Activities/FightActivity.cpp +++ b/src/main/Activities/FightActivity.cpp @@ -3,7 +3,7 @@ FightActivity::FightActivity() : Activity(), fightEnv(), currentFightState(std::make_unique(fightEnv)) { Game& game = Game::getInstance(); - this->fightEnv.enemyOverview.setEnemy(initEnemy()); + this->fightEnv.enemyOverview = UIEnemyOverview(initEnemy()); this->fightEnv.backgroundTX.loadFromFile(RESOURCE_PATH "backgrounds/background_fight.png"); this->fightEnv.backgroundSP.setTexture(this->fightEnv.backgroundTX); diff --git a/src/main/FightEnv.cpp b/src/main/FightEnv.cpp index d5144f8..e8bb71f 100644 --- a/src/main/FightEnv.cpp +++ b/src/main/FightEnv.cpp @@ -1,4 +1,4 @@ #include "FightEnv.hpp" -FightEnv::FightEnv(): playerStatsBox(Game::getInstance().player), enemyOverview(), playerOverview() { +FightEnv::FightEnv(): playerStatsBox(Game::getInstance().player) { } diff --git a/src/main/FightStates/EnemiesTurn.cpp b/src/main/FightStates/EnemiesTurn.cpp index 62bd795..272c2b4 100644 --- a/src/main/FightStates/EnemiesTurn.cpp +++ b/src/main/FightStates/EnemiesTurn.cpp @@ -9,8 +9,8 @@ FightStateEnum EnemiesTurn::run(FightEnv &fightEnv) { if (!fightEnv.enemyDamageCalculated) { std::random_device randSeed; std::mt19937 gen(randSeed()); - int minDamage = int(0.75 * fightEnv.enemyOverview.creature.attackStrength); - int maxDamage = int(1.25 * fightEnv.enemyOverview.creature.attackStrength); + int minDamage = int(0.75 * fightEnv.enemyOverview.enemy.attackStrength); + int maxDamage = int(1.25 * fightEnv.enemyOverview.enemy.attackStrength); std::uniform_int_distribution dist(minDamage, maxDamage); int enemyDamage = dist(gen); int millSecToLive = 600; diff --git a/src/main/FightStates/PlayersTurn.cpp b/src/main/FightStates/PlayersTurn.cpp index e6739fa..a2160cb 100644 --- a/src/main/FightStates/PlayersTurn.cpp +++ b/src/main/FightStates/PlayersTurn.cpp @@ -85,15 +85,15 @@ float PlayersTurn::sameColorMetric(Color color, FightEnv &fightEnv) { switch (color) { case RED: pickedColorValue = fightEnv.pickedColor.r; - defenseColorValue = fightEnv.enemyOverview.creature.defense.red; + defenseColorValue = fightEnv.enemyOverview.enemy.defense.red; break; case GREEN: pickedColorValue = fightEnv.pickedColor.g; - defenseColorValue = fightEnv.enemyOverview.creature.defense.green; + defenseColorValue = fightEnv.enemyOverview.enemy.defense.green; break; case BLUE: pickedColorValue = fightEnv.pickedColor.b; - defenseColorValue = fightEnv.enemyOverview.creature.defense.blue; + defenseColorValue = fightEnv.enemyOverview.enemy.defense.blue; break; default: break; @@ -110,15 +110,15 @@ float PlayersTurn::counterColorMetric(Color color, FightEnv &fightEnv) { switch (color) { case RED: pickedColorValue = fightEnv.pickedColor.r; - weakDefenseColorValue = fightEnv.enemyOverview.creature.defense.green; + weakDefenseColorValue = fightEnv.enemyOverview.enemy.defense.green; break; case GREEN: pickedColorValue = fightEnv.pickedColor.g; - weakDefenseColorValue = fightEnv.enemyOverview.creature.defense.blue; + weakDefenseColorValue = fightEnv.enemyOverview.enemy.defense.blue; break; case BLUE: pickedColorValue = fightEnv.pickedColor.b; - weakDefenseColorValue = fightEnv.enemyOverview.creature.defense.red; + weakDefenseColorValue = fightEnv.enemyOverview.enemy.defense.red; break; default: break; @@ -136,18 +136,18 @@ float PlayersTurn::tugOfWarMetric(Color color, FightEnv &fightEnv) { switch (color) { case RED: pickedColorValue = fightEnv.pickedColor.r; - weakDefenseColorValue = fightEnv.enemyOverview.creature.defense.green; - counterDefenseColorValue = fightEnv.enemyOverview.creature.defense.blue; + weakDefenseColorValue = fightEnv.enemyOverview.enemy.defense.green; + counterDefenseColorValue = fightEnv.enemyOverview.enemy.defense.blue; break; case GREEN: pickedColorValue = fightEnv.pickedColor.g; - weakDefenseColorValue = fightEnv.enemyOverview.creature.defense.blue; - counterDefenseColorValue = fightEnv.enemyOverview.creature.defense.red; + weakDefenseColorValue = fightEnv.enemyOverview.enemy.defense.blue; + counterDefenseColorValue = fightEnv.enemyOverview.enemy.defense.red; break; case BLUE: pickedColorValue = fightEnv.pickedColor.b; - weakDefenseColorValue = fightEnv.enemyOverview.creature.defense.red; - counterDefenseColorValue = fightEnv.enemyOverview.creature.defense.green; + weakDefenseColorValue = fightEnv.enemyOverview.enemy.defense.red; + counterDefenseColorValue = fightEnv.enemyOverview.enemy.defense.green; break; default: break; diff --git a/src/main/UIElements/UIStats.cpp b/src/main/UIElements/UIStats.cpp index 13c7612..b7eb9d2 100644 --- a/src/main/UIElements/UIStats.cpp +++ b/src/main/UIElements/UIStats.cpp @@ -86,8 +86,10 @@ void UIStats::setPosition(float x, float y) { float statsOffsetY = actorStatsBoxSize.height * 0.3; float statsSeparationPaddingY = actorStatsBoxSize.height * 0.05; + std::string currentActor = this->actorName.getString(); + std::cout << currentActor << std::endl; sf::FloatRect actorNameRec = this->actorName.getGlobalBounds(); - this->actorName.setPosition(x + (actorStatsBoxSize.width - actorNameRec.width)/2, y + actorStatsBoxSize.height * 0.15); + this->actorName.setPosition(x + ((actorStatsBoxSize.width - actorNameRec.width)/2), y + actorStatsBoxSize.height * 0.15); this->actorHealthLabel.setPosition(statsLabelPosX, y + statsOffsetY); this->actorHealthValue.setPosition(statsValuePosX, y + statsOffsetY); this->actorAttackStrengthLabel.setPosition(statsLabelPosX, y + statsOffsetY + statsTextHeight + statsSeparationPaddingY); @@ -95,6 +97,7 @@ void UIStats::setPosition(float x, float y) { this->actorRGBDefenseLabel.setPosition(statsLabelPosX, y + statsOffsetY + (statsTextHeight + statsSeparationPaddingY)*2); this->actorRGBDefenseValues.setPosition(statsValuePosX, y + statsOffsetY + (statsTextHeight + statsSeparationPaddingY)*2); } + sf::FloatRect UIStats::getSize() { return this->actorStatsBox.getSize(); } diff --git a/src/main/UIObjects/UIEnemyOverview.cpp b/src/main/UIObjects/UIEnemyOverview.cpp index 0beed6f..5f5832d 100644 --- a/src/main/UIObjects/UIEnemyOverview.cpp +++ b/src/main/UIObjects/UIEnemyOverview.cpp @@ -1,37 +1,37 @@ #include "UIObjects/UIEnemyOverview.hpp" -UIEnemyOverview::UIEnemyOverview(): UIEnemyOverview(Enemy()) { +UIEnemyOverview::UIEnemyOverview() { } -UIEnemyOverview::UIEnemyOverview(Enemy enemy): statsComponent(enemy), creature(enemy), creatureFrame("monster_landscape_cut/" + enemy.picPath, "actor_borders/fight_border.png") { +UIEnemyOverview::UIEnemyOverview(Enemy enemy): enemyStats(enemy), enemy(enemy), enemyBorderedImage("monster_landscape_cut/" + enemy.picPath, "actor_borders/fight_border.png") { Game& game = Game::getInstance(); sf::Vector2u windowSize = game.gameWindow.getSize(); - sf::FloatRect boxRect = this->backgroundBox.getSize(); + sf::FloatRect boxRect = this->box.getSize(); sf::Vector2f overviewPos = sf::Vector2f(windowSize.x * 0.51, windowSize.y * 0.1); - this->backgroundBox.setPosition(overviewPos.x, overviewPos.y); + this->box.setPosition(overviewPos.x, overviewPos.y); float relativeOuterPaddingStatBoxes = 0.05; - sf::FloatRect statsBoxSize = this->statsComponent.getSize(); - this->statsComponent.setPosition(windowSize.x * (1.0 - relativeOuterPaddingStatBoxes) - statsBoxSize.width, windowSize.y * 0.35); + sf::FloatRect statsBoxSize = this->enemyStats.getSize(); + this->enemyStats.setPosition(windowSize.x * (1.0 - relativeOuterPaddingStatBoxes) - statsBoxSize.width, windowSize.y * 0.35); - sf::FloatRect creatureFrameRect = this->creatureFrame.getSize(); + sf::FloatRect creatureFrameRect = this->enemyBorderedImage.getSize(); float creatureBoxScale = (windowSize.x*0.22)/creatureFrameRect.width; - this->creatureFrame.scale(creatureBoxScale, creatureBoxScale); - creatureFrameRect = this->creatureFrame.getSize(); + this->enemyBorderedImage.scale(creatureBoxScale, creatureBoxScale); + creatureFrameRect = this->enemyBorderedImage.getSize(); float creatureFrameMargin = boxRect.width * 0.05; sf::Vector2f creatureFramePos = sf::Vector2f(overviewPos.x + creatureFrameMargin, overviewPos.y + creatureFrameMargin); - this->creatureFrame.setPosition(creatureFramePos.x, creatureFramePos.y); + this->enemyBorderedImage.setPosition(creatureFramePos.x, creatureFramePos.y); - this->creatureBackgroundTX.loadFromFile(RESOURCE_PATH "actor_landscape_backgrounds/forest.png"); - this->creatureBackgroundSP.setTexture(this->creatureBackgroundTX); - sf::FloatRect creatureBackgroundRect = this->creatureBackgroundSP.getGlobalBounds(); - this->creatureBackgroundSP.setOrigin(creatureBackgroundRect.width/2.f, creatureBackgroundRect.height/2.f); - this->creatureBackgroundSP.setPosition(creatureFramePos.x + creatureFrameRect.width/2.f, creatureFramePos.y + creatureFrameRect.height/2.f); - this->creatureBackgroundSP.scale(creatureBoxScale, creatureBoxScale); + this->enemyIconBackgroundTX.loadFromFile(RESOURCE_PATH "actor_landscape_backgrounds/forest.png"); + this->enemyIconBackgroundSP.setTexture(this->enemyIconBackgroundTX); + sf::FloatRect creatureBackgroundRect = this->enemyIconBackgroundSP.getGlobalBounds(); + this->enemyIconBackgroundSP.setOrigin(creatureBackgroundRect.width / 2.f, creatureBackgroundRect.height / 2.f); + this->enemyIconBackgroundSP.setPosition(creatureFramePos.x + creatureFrameRect.width / 2.f, creatureFramePos.y + creatureFrameRect.height / 2.f); + this->enemyIconBackgroundSP.scale(creatureBoxScale, creatureBoxScale); float colorPickerScale = creatureFrameRect.width / colorPicker.getSize().width; this->colorPicker.scale(colorPickerScale, colorPickerScale); - this->colorPicker.setColorBox(this->creature.colorPicPath, this->creature.colorPicBorderPath); + this->colorPicker.setColorBox(this->enemy.colorPicPath, this->enemy.colorPicBorderPath); sf::Vector2f colorPickerPos = sf::Vector2f(creatureFramePos.x, creatureFramePos.y + creatureFrameRect.height + boxRect.height * 0); this->colorPicker.setPosition(colorPickerPos.x, colorPickerPos.y); sf::FloatRect colorPickerSize = this->colorPicker.getSize(); @@ -45,27 +45,27 @@ UIEnemyOverview::UIEnemyOverview(Enemy enemy): statsComponent(enemy), creature(e this->pickedColorText.setPosition(colorPickerPos.x + colorPickerSize.width*0.5, colorPickerPos.y + colorPickerSize.height + windowSize.y*0.02); } -void UIEnemyOverview::setEnemy(Enemy enemy) { - this->creature = enemy; - this->statsComponent.setActor(enemy); - this->creatureFrame.setImage("monster_landscape_cut/" + enemy.picPath); +void UIEnemyOverview::initEnemy(Enemy enemy) { + this->enemy = enemy; + this->enemyStats.setActor(enemy); + this->enemyBorderedImage.setImage("monster_landscape_cut/" + enemy.picPath); this->colorPicker.setColorImage(enemy.colorPicPath); } void UIEnemyOverview::draw() { Game& game = Game::getInstance(); - this->backgroundBox.draw(); - this->statsComponent.draw(); + this->box.draw(); + this->enemyStats.draw(); this->colorPicker.draw(); game.gameWindow.draw(this->pickedColorText); - game.gameWindow.draw(this->creatureBackgroundSP); - this->creatureFrame.draw(); + game.gameWindow.draw(this->enemyIconBackgroundSP); + this->enemyBorderedImage.draw(); } void UIEnemyOverview::changeHealth(int value) { - int newHealth = std::max(this->creature.health - value, 0); - this->creature.health = newHealth; - this->statsComponent.updateHealth(newHealth); + int newHealth = std::max(this->enemy.health - value, 0); + this->enemy.health = newHealth; + this->enemyStats.updateHealth(newHealth); } void UIEnemyOverview::updatePickedColorText(std::string newText, sf::Color pickedColor) { diff --git a/src/main/UIObjects/UIPlayerOverview.cpp b/src/main/UIObjects/UIPlayerOverview.cpp index 87c0f10..d87a9b4 100644 --- a/src/main/UIObjects/UIPlayerOverview.cpp +++ b/src/main/UIObjects/UIPlayerOverview.cpp @@ -6,8 +6,6 @@ UIPlayerOverview::UIPlayerOverview(): statsComponent(Game::getInstance().player) sf::FloatRect boxRect = this->backgroundBox.getSize(); this->backgroundBox.setPosition((windowSize.x * 0.49) - boxRect.width, windowSize.y * 0.1); - float relativeOuterPaddingStatBoxes = 0.05; - sf::FloatRect statsBoxSize = this->statsComponent.getSize(); this->statsComponent.setPosition(windowSize.x * 0.08, windowSize.y * 0.35); sf::Vector2f statsPos = this->statsComponent.getPosition(); diff --git a/src/resources/actor_borders/fight_border.png b/src/resources/actor_borders/fight_border.png index 4364bec..68970bb 100644 Binary files a/src/resources/actor_borders/fight_border.png and b/src/resources/actor_borders/fight_border.png differ diff --git a/src/resources/actor_borders/fight_border_old.png b/src/resources/actor_borders/fight_border_old.png new file mode 100644 index 0000000..4364bec Binary files /dev/null and b/src/resources/actor_borders/fight_border_old.png differ