Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Rpg/dialogueSystem/DialogueActionExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void DialogueActionExecutor::executeAction(const DialogueAction& action) {
if (itemId != -1)
mInventory.removeItemById(itemId, action.value);
} else if (action.type == "change_crystals") {
mRpgEngine.changeCrystals(action.value);
mRpgEngine.addCrystals(action.value);
} else if (action.type == "set_chapter") {
mStoryManager.setChapter(action.value);
} else {
Expand Down
202 changes: 112 additions & 90 deletions src/Rpg/gamengine/RPGEngine.cpp

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/Rpg/gamengine/RPGEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "../menues/ShopMenu.h"
#include "../menues/AnalyzeMenu.h"
#include "../menues/ChestMenu.h"
#include "../../TowerDefense/menues/LevelCompleteMenu.h"
#include "../map/entities/DrawableEntity.h"
#include "../map/buildings/MCHouse.h"
#include "../map/buildings/MCHouseInt.h"
Expand Down Expand Up @@ -59,8 +60,10 @@ class RPGEngine {
void newGame();
void setSaveNumber(int saveNumber);
void setFlag(std::string name, bool value);
void changeCrystals(int value);
void addCrystals(int value);
void setCrystals(int crystals);
void addXp(int xp);
void advanceTowerDefenseLevel();

void initialize();
void uninitialize();
Expand Down Expand Up @@ -96,7 +99,7 @@ class RPGEngine {

GameManager* mGameManager;
int mCrystals;
int mCurrentLevel;
int mCurrentTowerDefenseLevel;
std::vector<int> mAvailableTowers;
int mChapter;

Expand All @@ -118,6 +121,7 @@ class RPGEngine {
BankMenu mBankMenu;
AnalyzeMenu mAnalyzeMenu;
ChestMenu mChestMenu;
LevelCompleteMenu mLevelCompleteMenu;

NPC* mCurrentInteractingNPC;
TimeSystem mTimeSystem;
Expand Down
60 changes: 60 additions & 0 deletions src/Rpg/mainCharacter/LevelSystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "LevelSystem.h"
#include <iostream>
#include "../inventory/items/TowerBlueprintEpic.h"


LevelSystem::LevelSystem(Inventory* inventory, LevelCompleteMenu* levelCompleteMenu, int maxLevel)
: mInventory(inventory), mLevelCompleteMenu(levelCompleteMenu), mCurrentXp(0),
mCurrentLevel(1), mMaxLevel(maxLevel) {

}

void LevelSystem::addXp(int xp) {
if (mCurrentLevel < mMaxLevel) {
mCurrentXp += xp;
checkLevelUp();
}
}

void LevelSystem::checkLevelUp() {
while (mCurrentLevel < mMaxLevel && mCurrentXp >= getXpForNextLevel()) {
mCurrentXp -= getXpForNextLevel();
mCurrentLevel++;

grantRewards(mCurrentLevel);
}
}

void LevelSystem::grantRewards(int level) {
mLevelCompleteMenu->setLevel(level);
mLevelCompleteMenu->refresh();
mLevelCompleteMenu->setActive(true);
}

int LevelSystem::getCurrentXp() const {
return mCurrentXp;
}

int LevelSystem::getLevel() const {
return mCurrentLevel;
}

void LevelSystem::setLevel(int level) {
mCurrentLevel = level;
}

int LevelSystem::getXpForNextLevel() const {
return static_cast<float>(50.f * std::pow(mCurrentLevel, 1.3f));
}

float LevelSystem::getXpPercentage() const {
if (mCurrentLevel >= mMaxLevel)
return 1.f;

return static_cast<float>(mCurrentXp) / static_cast<float>(getXpForNextLevel());
}

void LevelSystem::setXp(int xp) {
mCurrentXp = xp;
}

32 changes: 32 additions & 0 deletions src/Rpg/mainCharacter/LevelSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#include <functional>
#include <math.h>
#include "../inventory/Inventory.h"
#include "../../TowerDefense/menues/LevelCompleteMenu.h"

class LevelSystem {
public:
LevelSystem(Inventory* inventory, LevelCompleteMenu* levelCompleteMenu, int maxLevel = 50);

void addXp(int xp);

int getLevel() const;
void setLevel(int level);

int getCurrentXp() const;
int getXpForNextLevel() const;
float getXpPercentage() const;
void setXp(int xp);

void grantRewards(int level);

private:
void checkLevelUp();

int mCurrentLevel;
int mCurrentXp;
int mMaxLevel;

Inventory* mInventory;
LevelCompleteMenu* mLevelCompleteMenu;
};
29 changes: 27 additions & 2 deletions src/Rpg/mainCharacter/MainCharacter.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "MainCharacter.h"
#include "LevelSystem.h"
#include <iostream>
#include <math.h>

MainCharacter::MainCharacter(const sf::Vector2f& position)
: mPosition(position), mSpeed(142.0f), mPriority(0) {
MainCharacter::MainCharacter(const sf::Vector2f& position, Inventory* inventory, LevelCompleteMenu* levelCompleteMenu)
: mPosition(position), mSpeed(142.0f), mPriority(0), mLevelSystem(inventory, levelCompleteMenu) {
mCollisionZone.setSize(sf::Vector2f(24.f, 16.f));
mCollisionZone.setPosition(sf::Vector2f(mPosition.x + 21.f, mPosition.y + 47.f));
mCollisionZone.setFillColor(sf::Color::Red);
Expand Down Expand Up @@ -164,3 +165,27 @@ int MainCharacter::getAnimation() {
return 0;
}

LevelSystem& MainCharacter::getLevelSystem() {
return mLevelSystem;
}

int MainCharacter::getLevel() const {
return mLevelSystem.getLevel();
}

void MainCharacter::setLevel(int level) {
mLevelSystem.setLevel(level);
}

int MainCharacter::getXp() const {
return mLevelSystem.getCurrentXp();
}

int MainCharacter::getXpForNextLevel() const {
return mLevelSystem.getXpForNextLevel();
}

void MainCharacter::setXp(int xp) {
mLevelSystem.setXp(xp);
}

15 changes: 14 additions & 1 deletion src/Rpg/mainCharacter/MainCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#include <SFML/Graphics.hpp>
#include "../../Animation.h"
#include "../map/entities/DrawableEntity.h"
#include "../inventory/Inventory.h"
#include "LevelSystem.h"
#include "../../TowerDefense/menues/LevelCompleteMenu.h"

class MainCharacter : public DrawableEntity {
public:
MainCharacter(const sf::Vector2f& position);
MainCharacter(const sf::Vector2f& position, Inventory* inventory, LevelCompleteMenu* levelCompleteMenu);

void update(float dt, bool inDialogue);
void render(sf::RenderWindow& window) override;
Expand All @@ -23,6 +26,14 @@ class MainCharacter : public DrawableEntity {
void setAnimation(int animation);
int getAnimation();

LevelSystem& getLevelSystem();
int getLevel() const;
void setLevel(int level);

int getXp() const;
int getXpForNextLevel() const;
void setXp(int xp);

private:
enum class AnimationIndex {
IdleUp,
Expand All @@ -39,6 +50,8 @@ class MainCharacter : public DrawableEntity {
float mSpeed;
int mPriority;

LevelSystem mLevelSystem;

sf::Keyboard::Key mLastDirection = sf::Keyboard::A;
sf::Sprite mSprite;
Animation mAnimations[int(AnimationIndex::Count)];
Expand Down
6 changes: 3 additions & 3 deletions src/Rpg/menues/ShopMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ void ShopMenu::updateTooltip(int slot, int id) {
std::string tooltipText;
if (id == 1) tooltipText = "Cost: 5\nWood\nA piece of wood, useful for crafting.";
else if (id == 2) tooltipText = "Cost: 50\nTower Blueprint\nCan be used to unlock towers!";
else if (id == 3) tooltipText = "Cost: 100\nTower Blueprint Rare\nCan be used to unlock rare towers!";
else if (id == 4) tooltipText = "Cost: 150\nTower Blueprint Epic\nCan be used to unlock epic towers!";
else if (id == 5) tooltipText = "Cost: 250\nTower Blueprint Mythic\nCan be used to unlock mythic towers!";
else if (id == 3) tooltipText = "Cost: 100\nRare Tower Blueprint\nCan be used to unlock rare towers!";
else if (id == 4) tooltipText = "Cost: 150\nEpic Tower Blueprint\nCan be used to unlock epic towers!";
else if (id == 5) tooltipText = "Cost: 250\nMythic Tower Blueprint\nCan be used to unlock mythic towers!";
else tooltipText = "Nothing here!";

mTooltipText.setString(tooltipText);
Expand Down
Loading
Loading