From d93e71e71608ae2ef38bd8fa37d5857f7cf99387 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Tue, 19 May 2026 17:19:54 +0200 Subject: [PATCH] 1 --- include/game/gamemanager.hpp | 4 ++++ src/game/agame/background.cpp | 17 +++++++++++++++++ src/game/agame/player.cpp | 3 +++ src/game/gamemanager.cpp | 1 + 4 files changed, 25 insertions(+) diff --git a/include/game/gamemanager.hpp b/include/game/gamemanager.hpp index e12f438..f9c7793 100644 --- a/include/game/gamemanager.hpp +++ b/include/game/gamemanager.hpp @@ -58,6 +58,9 @@ namespace Game { static void destroyEntity(T* entity); static void processPendingEntityRemovals(); + static void pushPlayerPosition(Object::Transform transform) { mPlayerTransformHistory.push_back(transform); } + static void getPlayerPositionHistory(std::vector& outHistory) { outHistory = mPlayerTransformHistory; } + private: int mTargetUpdatesPerSecond = TARGET_UPDATE_RATE; clock::time_point mLastUpdate; @@ -65,6 +68,7 @@ namespace Game { static std::unordered_map mSharedInts; static std::unordered_map mSharedFloats; static std::unordered_map mSharedBools; + static std::vector mPlayerTransformHistory; static GameStateEnum mCurrentGameState; float mLastDelta = 0.f; }; diff --git a/src/game/agame/background.cpp b/src/game/agame/background.cpp index 08e209d..6c09060 100644 --- a/src/game/agame/background.cpp +++ b/src/game/agame/background.cpp @@ -35,6 +35,23 @@ namespace { file << "Igralec: " << playerName << "\n"; file << "Točke: " << score << "\n"; file << "Datum: " << std::put_time(&localTime, "%Y-%m-%d %H:%M:%S") << "\n"; + + // Replay system + std::vector playerHistory; + Game::GameManager::getPlayerPositionHistory(playerHistory); + std::ofstream replayFile("replay.txt", std::ios::trunc); + if (!replayFile.is_open()) { + WARN("Neuspešno odpiranje replay.txt za pisanje"); + return; + } + + for (const auto& transform : playerHistory) { + replayFile << transform.x << " " << transform.y << " " << transform.rotation << " " << transform.scaleX << " " << transform.scaleY << "\n"; + } + + LOG("Zapis končne statistike in replaya igre dokončan"); + replayFile.close(); + file.close(); } } diff --git a/src/game/agame/player.cpp b/src/game/agame/player.cpp index 46e0130..ec112ac 100644 --- a/src/game/agame/player.cpp +++ b/src/game/agame/player.cpp @@ -161,6 +161,9 @@ namespace Game::AGame { } else if (!mIsShipMode && mGroundTex) { setTexture(mGroundTex); } + + // Push replay + GameManager::pushPlayerPosition(mTransform); } void Player::onCollisionEnter(Object::Entity* other) { diff --git a/src/game/gamemanager.cpp b/src/game/gamemanager.cpp index e4b0a5d..18da05f 100644 --- a/src/game/gamemanager.cpp +++ b/src/game/gamemanager.cpp @@ -67,6 +67,7 @@ namespace Game { std::unordered_map GameManager::mSharedInts; std::unordered_map GameManager::mSharedFloats; std::unordered_map GameManager::mSharedBools; + std::vector GameManager::mPlayerTransformHistory; void GameManager::removeSharedData(const std::string& key, SharedDataType type) { if (type == SharedDataType::STRING) {