-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: absolute resource path is not loaded at runtime
- Loading branch information
Showing
32 changed files
with
1,054 additions
and
1,034 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
#include "CharacterActivity.hpp" | ||
|
||
CharacterActivity::CharacterActivity(): Activity() { | ||
this->backgroundTX.loadFromFile(RESOURCE_PATH "backgrounds/backgroundMenu.png"); | ||
this->backgroundSP.setTexture(this->backgroundTX); | ||
} | ||
|
||
ActivityEnum CharacterActivity::executeActivity() { | ||
Game& game = Game::getInstance(); | ||
ActivityEnum currentActivity = ActivityEnum::Character; | ||
game.gameWindow.draw(this->backgroundSP); | ||
this->exitButton.draw(); | ||
if (this->exitButton.clickListener()) { | ||
currentActivity = ActivityEnum::Menu; | ||
} | ||
return currentActivity; | ||
#include "CharacterActivity.hpp" | ||
|
||
CharacterActivity::CharacterActivity(): Activity() { | ||
this->backgroundTX.loadFromFile(RESOURCES + "backgrounds/backgroundMenu.png"); | ||
this->backgroundSP.setTexture(this->backgroundTX); | ||
} | ||
|
||
ActivityEnum CharacterActivity::executeActivity() { | ||
Game& game = Game::getInstance(); | ||
ActivityEnum currentActivity = ActivityEnum::Character; | ||
game.gameWindow.draw(this->backgroundSP); | ||
this->exitButton.draw(); | ||
if (this->exitButton.clickListener()) { | ||
currentActivity = ActivityEnum::Menu; | ||
} | ||
return currentActivity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,144 +1,144 @@ | ||
#include "Activities/FightActivity/FightActivity.hpp" | ||
|
||
|
||
FightActivity::FightActivity() : Activity(), fightEnv(), currentFightState(std::make_unique<TurnChangeState>(fightEnv)) { | ||
Game& game = Game::getInstance(); | ||
this->enemy = std::make_shared<Enemy>(this->initEnemy()); | ||
this->fightEnv.enemyOverview = std::make_unique<UIEnemyOverview>(this->enemy); | ||
this->fightEnv.playerOverview = std::make_unique<UIPlayerOverview>(Game::getInstance().player); | ||
|
||
this->fightEnv.backgroundTX.loadFromFile(RESOURCE_PATH "backgrounds/background_fight.png"); | ||
this->fightEnv.backgroundSP.setTexture(this->fightEnv.backgroundTX); | ||
|
||
this->fightEnv.backgroundMusic.openFromFile(RESOURCE_PATH "music/fight_background_music.wav"); | ||
this->fightEnv.backgroundMusic.setLoop(true); | ||
this->fightEnv.backgroundMusic.play(); | ||
|
||
sf::Vector2f windowSize = static_cast<sf::Vector2f>(game.gameWindow.getSize()); | ||
sf::Vector2f backgroundSize = static_cast<sf::Vector2f>(this->fightEnv.backgroundTX.getSize()); | ||
|
||
sf::Vector2f backgroundScale = sf::Vector2f(windowSize.x / backgroundSize.x, windowSize.y / backgroundSize.y); | ||
this->fightEnv.backgroundSP.scale(backgroundScale); | ||
|
||
std::random_device randSeed; | ||
std::mt19937 gen(randSeed()); | ||
std::uniform_int_distribution<int> dist(0, 1); | ||
this->fightEnv.isPlayersTurn = dist(gen); | ||
|
||
this->fightEnv.playersTurnTX.loadFromFile(RESOURCE_PATH "combat/turn_status_player.png"); | ||
this->fightEnv.enemiesTurnTX.loadFromFile(RESOURCE_PATH "combat/turn_status_enemy.png"); | ||
|
||
if (this->fightEnv.isPlayersTurn) { | ||
this->fightEnv.turnSP.setTexture(this->fightEnv.playersTurnTX); | ||
} else { | ||
this->fightEnv.turnSP.setTexture(this->fightEnv.enemiesTurnTX); | ||
} | ||
sf::FloatRect turnStateSignSize = this->fightEnv.turnSP.getGlobalBounds(); | ||
this->fightEnv.turnSP.setPosition((windowSize.x - turnStateSignSize.width) * 0.5 , -2.0); | ||
this->currentFightStateEnum = FightStateEnum::TURN_CHANGE; | ||
} | ||
|
||
FightActivity::~FightActivity() { | ||
this->fightEnv.backgroundMusic.stop(); | ||
} | ||
|
||
void FightActivity::runCurrentState(Game &game) { | ||
FightStateEnum newStateFightEnum = this->currentFightState->run(this->fightEnv); | ||
if (newStateFightEnum != this->currentFightStateEnum) { | ||
switch (newStateFightEnum) { | ||
case FightStateEnum::PLAYER_STATE: | ||
this->currentFightState = std::move(std::make_unique<PlayersTurn>(this->fightEnv)); | ||
break; | ||
case FightStateEnum::ENEMY_STATE: | ||
this->currentFightState = std::move(std::make_unique<EnemiesTurn>()); | ||
break; | ||
case FightStateEnum::TURN_CHANGE: | ||
this->currentFightState = std::move(std::make_unique<TurnChangeState>(this->fightEnv)); | ||
break; | ||
default: | ||
break; | ||
} | ||
this->currentFightStateEnum = newStateFightEnum; | ||
} | ||
} | ||
|
||
ActivityEnum FightActivity::executeActivity() { | ||
Game& game = Game::getInstance(); | ||
ActivityEnum currentActivity = ActivityEnum::Fight; | ||
|
||
game.gameWindow.draw(this->fightEnv.turnSP); | ||
game.gameWindow.draw(this->fightEnv.backgroundSP); | ||
this->fightEnv.playerOverview->draw(); | ||
this->fightEnv.enemyOverview->draw(); | ||
this->exitButton.draw(); | ||
this->fightEnv.textFadingManager.run(); | ||
|
||
this->runCurrentState(game); | ||
|
||
if (this->exitButton.clickListener()) { | ||
|
||
currentActivity = ActivityEnum::Menu; | ||
} | ||
return currentActivity; | ||
} | ||
|
||
Enemy FightActivity::initEnemy() { | ||
std::vector<std::string> enemyNames = {"Zucchini?!?", "Assel", "Hamster", "Mantis Warrior", "Flesh-Fungus"}; | ||
Enemy randomEnemy; | ||
|
||
std::srand(std::time(nullptr)); | ||
int randomNum = std::rand() % NUM_ENEMY; | ||
|
||
|
||
switch (randomNum) { | ||
case 0: | ||
// Zucchini | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 5) + 8; | ||
randomEnemy.health = (std::rand() % 30) + 50; | ||
randomEnemy.defense = {std::rand() % 150, (std::rand() % 50) + 120, std::rand() % 100}; | ||
randomEnemy.picPath = "zucchini_demon_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 1: | ||
// Assel | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 3) + 3; | ||
randomEnemy.health = (std::rand() % 20) + 110; | ||
randomEnemy.defense = {(std::rand() % 255), std::rand() % 255, std::rand() % 255}; | ||
randomEnemy.picPath = "assel_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 2: | ||
// Hamster | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 2) + 1; | ||
randomEnemy.health = (std::rand() % 15) + 20; | ||
randomEnemy.defense = {(std::rand() % 100) + 100, (std::rand() % 50) + 40, (std::rand() % 100) + 100}; | ||
randomEnemy.picPath = "hamster_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 3: | ||
// Mantis Warrior | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 6) + 11; | ||
randomEnemy.health = (std::rand() % 15) + 90; | ||
randomEnemy.defense = {std::rand() % 255, std::rand() % 255, std::rand() % 255}; | ||
randomEnemy.picPath = "mantis_warrior_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 4: | ||
// Flesh-Fungus | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 10) + 7; | ||
randomEnemy.health = (std::rand() % 2) + 20; | ||
randomEnemy.defense = {std::rand() % 80, std::rand() % 250, std::rand() % 150}; | ||
randomEnemy.picPath = "hamster_fungus_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
return randomEnemy; | ||
#include "Activities/FightActivity/FightActivity.hpp" | ||
|
||
|
||
FightActivity::FightActivity() : Activity(), fightEnv(), currentFightState(std::make_unique<TurnChangeState>(fightEnv)) { | ||
Game& game = Game::getInstance(); | ||
this->enemy = std::make_shared<Enemy>(this->initEnemy()); | ||
this->fightEnv.enemyOverview = std::make_unique<UIEnemyOverview>(this->enemy); | ||
this->fightEnv.playerOverview = std::make_unique<UIPlayerOverview>(Game::getInstance().player); | ||
|
||
this->fightEnv.backgroundTX.loadFromFile(RESOURCES + "backgrounds/background_fight.png"); | ||
this->fightEnv.backgroundSP.setTexture(this->fightEnv.backgroundTX); | ||
|
||
this->fightEnv.backgroundMusic.openFromFile(RESOURCES + "music/fight_background_music.wav"); | ||
this->fightEnv.backgroundMusic.setLoop(true); | ||
this->fightEnv.backgroundMusic.play(); | ||
|
||
sf::Vector2f windowSize = static_cast<sf::Vector2f>(game.gameWindow.getSize()); | ||
sf::Vector2f backgroundSize = static_cast<sf::Vector2f>(this->fightEnv.backgroundTX.getSize()); | ||
|
||
sf::Vector2f backgroundScale = sf::Vector2f(windowSize.x / backgroundSize.x, windowSize.y / backgroundSize.y); | ||
this->fightEnv.backgroundSP.scale(backgroundScale); | ||
|
||
std::random_device randSeed; | ||
std::mt19937 gen(randSeed()); | ||
std::uniform_int_distribution<int> dist(0, 1); | ||
this->fightEnv.isPlayersTurn = dist(gen); | ||
|
||
this->fightEnv.playersTurnTX.loadFromFile(RESOURCES + "combat/turn_status_player.png"); | ||
this->fightEnv.enemiesTurnTX.loadFromFile(RESOURCES + "combat/turn_status_enemy.png"); | ||
|
||
if (this->fightEnv.isPlayersTurn) { | ||
this->fightEnv.turnSP.setTexture(this->fightEnv.playersTurnTX); | ||
} else { | ||
this->fightEnv.turnSP.setTexture(this->fightEnv.enemiesTurnTX); | ||
} | ||
sf::FloatRect turnStateSignSize = this->fightEnv.turnSP.getGlobalBounds(); | ||
this->fightEnv.turnSP.setPosition((windowSize.x - turnStateSignSize.width) * 0.5 , -2.0); | ||
this->currentFightStateEnum = FightStateEnum::TURN_CHANGE; | ||
} | ||
|
||
FightActivity::~FightActivity() { | ||
this->fightEnv.backgroundMusic.stop(); | ||
} | ||
|
||
void FightActivity::runCurrentState(Game &game) { | ||
FightStateEnum newStateFightEnum = this->currentFightState->run(this->fightEnv); | ||
if (newStateFightEnum != this->currentFightStateEnum) { | ||
switch (newStateFightEnum) { | ||
case FightStateEnum::PLAYER_STATE: | ||
this->currentFightState = std::move(std::make_unique<PlayersTurn>(this->fightEnv)); | ||
break; | ||
case FightStateEnum::ENEMY_STATE: | ||
this->currentFightState = std::move(std::make_unique<EnemiesTurn>()); | ||
break; | ||
case FightStateEnum::TURN_CHANGE: | ||
this->currentFightState = std::move(std::make_unique<TurnChangeState>(this->fightEnv)); | ||
break; | ||
default: | ||
break; | ||
} | ||
this->currentFightStateEnum = newStateFightEnum; | ||
} | ||
} | ||
|
||
ActivityEnum FightActivity::executeActivity() { | ||
Game& game = Game::getInstance(); | ||
ActivityEnum currentActivity = ActivityEnum::Fight; | ||
|
||
game.gameWindow.draw(this->fightEnv.turnSP); | ||
game.gameWindow.draw(this->fightEnv.backgroundSP); | ||
this->fightEnv.playerOverview->draw(); | ||
this->fightEnv.enemyOverview->draw(); | ||
this->exitButton.draw(); | ||
this->fightEnv.textFadingManager.run(); | ||
|
||
this->runCurrentState(game); | ||
|
||
if (this->exitButton.clickListener()) { | ||
|
||
currentActivity = ActivityEnum::Menu; | ||
} | ||
return currentActivity; | ||
} | ||
|
||
Enemy FightActivity::initEnemy() { | ||
std::vector<std::string> enemyNames = {"Zucchini?!?", "Assel", "Hamster", "Mantis Warrior", "Flesh-Fungus"}; | ||
Enemy randomEnemy; | ||
|
||
std::srand(std::time(nullptr)); | ||
int randomNum = std::rand() % NUM_ENEMY; | ||
|
||
|
||
switch (randomNum) { | ||
case 0: | ||
// Zucchini | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 5) + 8; | ||
randomEnemy.health = (std::rand() % 30) + 50; | ||
randomEnemy.defense = {std::rand() % 150, (std::rand() % 50) + 120, std::rand() % 100}; | ||
randomEnemy.picPath = "zucchini_demon_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 1: | ||
// Assel | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 3) + 3; | ||
randomEnemy.health = (std::rand() % 20) + 110; | ||
randomEnemy.defense = {(std::rand() % 255), std::rand() % 255, std::rand() % 255}; | ||
randomEnemy.picPath = "assel_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 2: | ||
// Hamster | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 2) + 1; | ||
randomEnemy.health = (std::rand() % 15) + 20; | ||
randomEnemy.defense = {(std::rand() % 100) + 100, (std::rand() % 50) + 40, (std::rand() % 100) + 100}; | ||
randomEnemy.picPath = "hamster_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 3: | ||
// Mantis Warrior | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 6) + 11; | ||
randomEnemy.health = (std::rand() % 15) + 90; | ||
randomEnemy.defense = {std::rand() % 255, std::rand() % 255, std::rand() % 255}; | ||
randomEnemy.picPath = "mantis_warrior_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
case 4: | ||
// Flesh-Fungus | ||
randomEnemy.name = enemyNames[randomNum]; | ||
randomEnemy.attackStrength = (std::rand() % 10) + 7; | ||
randomEnemy.health = (std::rand() % 2) + 20; | ||
randomEnemy.defense = {std::rand() % 80, std::rand() % 250, std::rand() % 150}; | ||
randomEnemy.picPath = "hamster_fungus_quer.png"; | ||
randomEnemy.colorPicPath = "colorPIC_" + std::to_string(randomNum) + ".png"; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
return randomEnemy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.