Skip to content

Commit

Permalink
feat: absolute resource path is not loaded at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipagaxi committed Jul 19, 2024
1 parent 794dc8f commit 6dcd3c9
Show file tree
Hide file tree
Showing 32 changed files with 1,054 additions and 1,034 deletions.
Binary file modified resources/color_textures/colorPIC_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 16 additions & 16 deletions src/Activities/CharacterActivity/CharacterActivity.cpp
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;
}
2 changes: 1 addition & 1 deletion src/Activities/CharacterActivity/CharacterActivity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CHARACTERACTIVITY_HPP

#include "Activities/Activity.hpp"
#include "config.hpp"
#include "Global/Utility.hpp"
#include "System/Game.hpp"

class CharacterActivity : public Activity {
Expand Down
286 changes: 143 additions & 143 deletions src/Activities/FightActivity/FightActivity.cpp
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;
}
1 change: 1 addition & 0 deletions src/Activities/FightActivity/FightActivity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "FightStates/TurnChangeState.hpp"
#include "FightStates/FightState.hpp"
#include "FightStateEnum.hpp"
#include "Global/Utility.hpp"

class FightActivity: public Activity {
public:
Expand Down
Loading

0 comments on commit 6dcd3c9

Please sign in to comment.