Skip to content

Commit

Permalink
Convert to level-based upgrade system and implement end-of-run scene
Browse files Browse the repository at this point in the history
  • Loading branch information
justindriggers committed Dec 31, 2023
1 parent cd2d6ec commit fe09d13
Show file tree
Hide file tree
Showing 28 changed files with 563 additions and 632 deletions.
5 changes: 0 additions & 5 deletions alfredo/src/platform/MacSaveManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class MacSaveManager : public SaveManager {
protected:
void load() override {
_points = 0;
_upgradeRanks[0] = 4;
_upgradeRanks[1] = 4;
_upgradeRanks[2] = 4;
_upgradeRanks[3] = 4;
_isNewPlayer = false;
}

void save() override {}
Expand Down
4 changes: 2 additions & 2 deletions linguine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_library(linguine
src/systems/GridPositionSystem.cpp
src/systems/HealthProgressSystem.cpp
src/systems/HudSystem.cpp
src/systems/LevelTrackingSystem.cpp
src/systems/LivenessSystem.cpp
src/systems/OrbitSystem.cpp
src/systems/ParticleSystem.cpp
Expand All @@ -52,8 +53,7 @@ add_library(linguine
src/systems/SelectionDestructionSystem.cpp
src/systems/ShakeSystem.cpp
src/systems/SpawnSystem.cpp
src/systems/shop/UpgradeSystem.cpp
src/systems/shop/WalletSystem.cpp
src/systems/ToastSystem.cpp
src/systems/TooltipSystem.cpp
src/systems/TransformationSystem.cpp
src/systems/TutorialSystem.cpp
Expand Down
20 changes: 1 addition & 19 deletions linguine/include/SaveManager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <cstdint>
#include <unordered_map>

namespace linguine {

Expand All @@ -12,7 +11,6 @@ class SaveManager {
virtual ~SaveManager() = default;

void addPoints(int32_t points) {
_isNewPlayer = false;
_points += points;
save();
}
Expand All @@ -22,37 +20,21 @@ class SaveManager {
save();
}

[[nodiscard]] uint8_t getRank(uint8_t upgradeId) const {
return _upgradeRanks.at(upgradeId);
}

void increaseRank(uint8_t upgradeId) {
_upgradeRanks[upgradeId]++;
save();
}

[[nodiscard]] int32_t getPoints() const {
return _points;
}

[[nodiscard]] bool isNewPlayer() const {
return _isNewPlayer;
return _points == 0;
}

void restart() {
_points = 0;
_upgradeRanks[0] = 0;
_upgradeRanks[1] = 0;
_upgradeRanks[2] = 0;
_upgradeRanks[3] = 0;
_isNewPlayer = true;
save();
}

protected:
int32_t _points{};
std::unordered_map<uint8_t, uint8_t> _upgradeRanks;
bool _isNewPlayer{};

virtual void load() = 0;

Expand Down
2 changes: 1 addition & 1 deletion linguine/include/renderer/features/ProgressFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ProgressFeature : public RenderFeature {
glm::vec4 backgroundColor = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
glm::vec3 color = glm::vec3(1.0f);
float progress = 1.0f;
MeshType meshType;
MeshType meshType = Quad;
};

} // namespace linguine
13 changes: 13 additions & 0 deletions linguine/src/components/Toast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <glm/vec3.hpp>

namespace linguine {

struct Toast {
glm::vec3 startPosition = glm::vec3(0.0f);
float duration = 1.0f;
float elapsed = 1.0f;
};

} // namespace linguine
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace linguine {

struct PurchaseButton {
uint8_t upgradeId{};
};
struct CurrentLevel {};

} // namespace linguine
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace linguine {

struct Wallet {};
struct CurrentXp {};

} // namespace linguine
18 changes: 18 additions & 0 deletions linguine/src/components/gameover/LevelTracker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <cstdint>

namespace linguine {

struct LevelTracker {
LevelTracker(int32_t startXp, int32_t endXp)
: startXp(startXp), endXp(endXp) {}

int32_t startXp;
int32_t endXp;

float duration = 1.0f;
float elapsed = 0.0f;
};

} // namespace linguine
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace linguine {

struct PlayButton {};
struct RequiredXp {};

} // namespace linguine
61 changes: 61 additions & 0 deletions linguine/src/data/upgrades/LevelCurve.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <array>

namespace linguine {

class LevelCurve {
public:
static constexpr uint8_t MaxLevel = 20;

static constexpr uint8_t getLevelForXp(int32_t xp) {
auto level = 0;
auto xpToLevel = 0;

for (auto xpIncreasePerLevel : _xpIncreasePerLevel) {
xpToLevel += xpIncreasePerLevel;

if (xp >= xpToLevel) {
xp -= xpToLevel;
++level;
} else {
break;
}
}

return level;
}

static constexpr int32_t getXpPerLevel(uint8_t level) {
auto result = std::array<int32_t, MaxLevel>();

auto xpRequired = 0;

for (auto i = 0; i < _xpIncreasePerLevel.size(); ++i) {
xpRequired += _xpIncreasePerLevel[i];
result[i] = xpRequired;
}

return result[level - 1];
}

static constexpr int32_t getXpForLevel(uint8_t level) {
auto xp = 0;

for (auto i = 1; i <= level; ++i) {
xp += getXpPerLevel(i);
}

return xp;
}

private:
static constexpr std::array<int32_t, MaxLevel> _xpIncreasePerLevel = {
0, 25, 25, 25, 50,
25, 25, 25, 25, 50,
25, 25, 25, 25, 50,
25, 25, 25, 25, 50
};
};

} // namespace linguine
2 changes: 1 addition & 1 deletion linguine/src/data/upgrades/Upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace linguine {
struct Upgrade {
std::string name;
std::string description;
std::vector<int16_t> rankCosts;
std::vector<uint8_t> rankLevels;
};

} // namespace linguine
40 changes: 34 additions & 6 deletions linguine/src/data/upgrades/UpgradeDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,48 @@ class UpgradeDatabase {
public:
UpgradeDatabase()
: _upgrades {
{ 0, { "Shield Generators", "Add additional defenses to your ship", { 25, 50, 100, 250, 500 } } },
{ 1, { "Generator Capacity", "Increase the strength of each shield", { 50, 100, 250, 500, 1000 } } },
{ 2, { "Base Speed", "Start each run with more speed", { 75, 150, 300, 750, 1500 } } },
{ 3, { "Ship Acceleration", "Pick up more speed over time", { 100, 250, 500, 1000, 2500 } } }
{ 0, { "Shield Generators", "+1 Shield", { 1, 2, 4, 8, 12 } } },
{ 1, { "Generator Capacity", "+1 Durability", { 3, 7, 11, 15, 18 } } },
{ 2, { "Base Speed", "+1 Speed", { 5, 9, 13, 16, 19 } } },
{ 3, { "Ship Acceleration", "+1 Acceleration", { 6, 10, 14, 17, 20 } } }
} {}

const std::map<uint8_t, Upgrade>& getUpgrades() const {
[[nodiscard]] const std::map<uint8_t, Upgrade>& getUpgrades() const {
return _upgrades;
}

const Upgrade& getById(uint8_t id) const {
[[nodiscard]] const Upgrade& getById(uint8_t id) const {
return _upgrades.at(id);
}

[[nodiscard]] uint8_t getRankByLevel(uint8_t id, uint8_t level) const {
auto& upgrade = getById(id);

auto rank = 0;

for (auto rankLevel : upgrade.rankLevels) {
if (rankLevel > level) {
break;
}

++rank;
}

return rank;
}

[[nodiscard]] const std::string& getDescriptionByLevel(uint8_t level) const {
for (auto& upgrade : _upgrades) {
for (auto rankLevel : upgrade.second.rankLevels) {
if (rankLevel == level) {
return upgrade.second.description;
}
}
}

throw std::runtime_error("No description found");
}

private:
std::map<uint8_t, Upgrade> _upgrades;
};
Expand Down

0 comments on commit fe09d13

Please sign in to comment.