Skip to content

Commit ee48f84

Browse files
committed
impl coin collection detection
1 parent 8885d8e commit ee48f84

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_library(${PROJECT_NAME} SHARED
1616
src/MenuLayer.cpp
1717
src/PlayLayer.cpp
1818
src/PlayerObject.cpp
19+
src/EffectGameObject.cpp
1920
src/Manager.cpp
2021
src/Manager.hpp
2122
src/Settings.cpp

src/EffectGameObject.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <Geode/modify/EffectGameObject.hpp>
2+
#include "Manager.hpp"
3+
4+
using namespace geode::prelude;
5+
6+
class $modify(MyEffectGameObject, EffectGameObject) {
7+
void triggerObject(GJBaseGameLayer* gjbgl, int p1, gd::vector<int> const* p2) {
8+
EffectGameObject::triggerObject(gjbgl, p1, p2);
9+
if (this->m_objectType != GameObjectType::UserCoin && this->m_objectType != GameObjectType::SecretCoin) return;
10+
std::map<GameObject*, bool>& coinsMap = Manager::getSharedInstance()->coins;
11+
if (coinsMap.contains(this)) {
12+
coinsMap.at(this) = true;
13+
}
14+
}
15+
};

src/Manager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Manager {
3434

3535
float currentDeathPercentForQueueInMainLoader = -1.f;
3636

37+
std::map<GameObject*, bool> coins;
38+
3739
FMOD::Sound* sound;
3840
FMOD::Channel* channel;
3941
FMOD::System* system = FMODAudioEngine::sharedEngine()->m_system;

src/PlayLayer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class $modify(MyPlayLayer, PlayLayer) {
6969
void resetLevel() {
7070
PlayLayer::resetLevel();
7171
manager->addedNextKeyWhenLabel = false;
72+
for (auto [coin, collected] : manager->coins) {
73+
manager->coins.at(coin) = false;
74+
}
7275
if (!manager->channel) return;
7376
if (!getModBool("sisyphusStopSFXOnRespawn")) return;
7477
STOP_MANAGER_CHANNEL
@@ -77,6 +80,7 @@ class $modify(MyPlayLayer, PlayLayer) {
7780
PlayLayer::onQuit();
7881
manager->lastDeathPercent = -10.f;
7982
manager->currentDeathPercentForQueueInMainLoader = -1.f;
83+
manager->coins.clear();
8084
if (!manager->channel) return;
8185
STOP_MANAGER_CHANNEL
8286
}
@@ -89,16 +93,28 @@ class $modify(MyPlayLayer, PlayLayer) {
8993
void togglePracticeMode(bool practiceMode) {
9094
PlayLayer::togglePracticeMode(practiceMode);
9195
manager->lastDeathPercent = -10.f;
96+
for (auto [coin, collected] : manager->coins) {
97+
manager->coins.at(coin) = false;
98+
}
9299
if (!manager->channel) return;
93100
STOP_MANAGER_CHANNEL
94101
}
95102
void resetLevelFromStart() {
96103
PlayLayer::resetLevelFromStart();
97104
manager->lastDeathPercent = -10.f;
105+
for (auto [coin, collected] : manager->coins) {
106+
manager->coins.at(coin) = false;
107+
}
98108
if (!manager->channel) return;
99109
if (!getModBool("enabled") || !getModBool("sisyphusStopSFXOnRespawn")) return;
100110
STOP_MANAGER_CHANNEL
101111
}
112+
void addObject(GameObject* object) {
113+
PlayLayer::addObject(object);
114+
if (!m_level || m_level->isPlatformer() || m_isPlatformer) return;
115+
if (object->m_objectType != GameObjectType::UserCoin && object->m_objectType != GameObjectType::SecretCoin) return;
116+
manager->coins.insert({object, false});
117+
}
102118
void applyNodeTraitsCustomization(CCNode *newBestNodeProbably, bool hasDiamondsOrOrbs) {
103119
if (getModBool("xPosPercentEnable")) {
104120
const float cWidth = CCScene::get()->getContentWidth();

0 commit comments

Comments
 (0)