Skip to content

Commit 1a11a8e

Browse files
committed
ads!!! mathquiz barely, and more tweaks
1 parent 7615e30 commit 1a11a8e

11 files changed

Lines changed: 208 additions & 121 deletions

File tree

mod.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111
"version": "v1.0.0",
1212
"developer": "ArcticWoof",
1313
"description": "Horrible Geode Mod Ideas",
14-
"settings": {
15-
"safe-mode": {
16-
"type": "bool",
17-
"name": "Safe Mode",
18-
"description": "Prevent any progression made in the level. <cr>Highly recommended that this is kept enabled!</cr>",
19-
"default": true
20-
}
14+
"links": {
15+
"source": "https://github.com/DumbCaveSpider/HorribleIdeas",
16+
"community": "https://discord.gg/gXcppxTNxC",
17+
"homepage": "https://arcticwoof.com.au"
18+
},
19+
"issues": {
20+
"info": "If something isn't turning out to be as funny as we thought, please report it to the repository!",
21+
"url": "https://github.com/DumbCaveSpider/HorribleIdeas/issues"
2122
},
22-
"tags": [
23-
"joke",
24-
"offline",
25-
"universal"
26-
],
2723
"dependencies": {
2824
"geode.node-ids": {
2925
"importance": "required",
@@ -39,13 +35,17 @@
3935
]
4036
}
4137
},
42-
"links": {
43-
"source": "https://github.com/DumbCaveSpider/HorribleIdeas",
44-
"community": "https://discord.gg/gXcppxTNxC",
45-
"homepage": "https://arcticwoof.com.au"
46-
},
47-
"issues": {
48-
"info": "If something isn't turning out to be as funny as we thought, please report it to the repository!",
49-
"url": "https://github.com/DumbCaveSpider/HorribleIdeas/issues"
38+
"tags": [
39+
"joke",
40+
"offline",
41+
"universal"
42+
],
43+
"settings": {
44+
"safe-mode": {
45+
"type": "bool",
46+
"name": "Safe Mode",
47+
"description": "Prevent any progression made in the level. <cr>Highly recommended that this is kept enabled!</cr>",
48+
"default": true
49+
}
5050
}
5151
}

src/layers/MathQuiz.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
#include "MathQuiz.hpp"
22

3+
#include "../RandomSeeder.hpp"
4+
35
#include <Geode/Geode.hpp>
46

57
using namespace geode::prelude;
68

9+
static RandomSeeder _randomSeeder;
10+
711
bool MathQuiz::init() {
8-
if (!CCLayer::init()) return false;
12+
if (!CCBlockLayer::init()) return false;
913

1014
setID("math-quiz"_spr);
1115
setKeypadEnabled(true);
1216

17+
m_numFirst = rand() % 10;
18+
m_numSecond = rand() % 10; // make a different seed somehow
19+
1320
// blue gradient background layer
1421
auto background = createLayerBG();
1522
background->setID("background");
@@ -93,16 +100,6 @@ void MathQuiz::infoPopup(CCObject*) {
93100
->show();
94101
};
95102

96-
// go back to the previous layer
97-
void MathQuiz::onGoBack(CCObject*) {
98-
CCDirector::get()->replaceScene(CCTransitionFade::create(0.5, MenuLayer::scene(false)));
99-
};
100-
101-
// same thing as onGoBack but when escape key is pressed
102-
void MathQuiz::keyBackClicked() {
103-
onGoBack(nullptr);
104-
};
105-
106103
// create a new instance of the Layer
107104
MathQuiz* MathQuiz::create() {
108105
auto ret = new MathQuiz();
@@ -114,11 +111,4 @@ MathQuiz* MathQuiz::create() {
114111

115112
CC_SAFE_DELETE(ret);
116113
return nullptr;
117-
};
118-
119-
// create a new scene with the Layer
120-
MathQuiz* MathQuiz::scene() {
121-
auto layer = MathQuiz::create();
122-
switchToScene(layer);
123-
return layer;
124114
};

src/layers/MathQuiz.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44

55
using namespace geode::prelude;
66

7-
class MathQuiz : public CCLayer {
7+
class MathQuiz : public CCBlockLayer, public FLAlertLayerProtocol {
88
protected:
9-
TextInput* m_answerInput = nullptr; // Answer gets typed out here
9+
int m_numFirst = 1; // First number in the equation
10+
int m_numSecond = 1; // Second number in the equation
1011

11-
bool init() override;
12+
int m_answer = 1; // The calculated answer to the equation
1213

13-
void keyBackClicked() override;
14-
void onGoBack(CCObject*);
14+
TextInput* m_answerInput = nullptr; // Answer gets typed out here
1515

1616
void infoPopup(CCObject*);
1717

18+
bool init() override;
19+
1820
public:
1921
static MathQuiz* create();
20-
static MathQuiz* scene();
2122
};

src/main.cpp

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
#include "popups/HorribleMenuPopup.hpp"
1+
#include "RandomSeeder.hpp"
22

3-
#include <ctime>
4-
#include <cstdlib>
3+
#include "popups/HorribleMenuPopup.hpp"
54

65
#include <fmt/core.h>
76

87
#include <Geode/Geode.hpp>
98

109
#include <Geode/modify/MenuLayer.hpp>
10+
#include <Geode/modify/PauseLayer.hpp>
1111
#include <Geode/modify/CCScene.hpp>
1212
#include <Geode/modify/CCMenuItem.hpp>
1313

1414
#include <Geode/binding/FMODAudioEngine.hpp>
1515

16-
struct RandomSeeder {
17-
RandomSeeder() { srand(time(0)); }
18-
};
1916
static RandomSeeder _randomSeeder;
2017

2118
using namespace geode::prelude;
@@ -28,18 +25,17 @@ bool isFlipped = false;
2825

2926
class $modify(HorribleCCScene, CCScene) {
3027
bool init() override {
31-
if (!CCScene::init())
32-
return false;
28+
if (!CCScene::init()) return false;
3329

34-
if (typeinfo_cast<CCTransitionFade*>(this)) {
30+
if (dynamic_cast<CCTransitionFade*>(this)) {
3531
log::debug("scene is a CCTransitionFade");
3632
return true;
37-
}
33+
};
3834

3935
log::debug("scene init called");
4036

4137
return true;
42-
}
38+
};
4339
};
4440

4541
// modify CCMenuItem so it plays the sound whenever a button is clicked regardless of the layer
@@ -81,13 +77,15 @@ class $modify(HorribleMenuLayer, MenuLayer) {
8177
"GJ_moonsIcon_001.png",
8278
0.875f,
8379
CircleBaseColor::Green,
84-
CircleBaseSize::MediumAlt);
80+
CircleBaseSize::MediumAlt
81+
);
8582

8683
auto btn = CCMenuItemSpriteExtra::create(
8784
btnSprite,
8885
this,
89-
menu_selector(HorribleMenuLayer::onHorribleButton));
90-
btn->setID("horribleBtn");
86+
menu_selector(HorribleMenuLayer::onHorribleButton)
87+
);
88+
btn->setID("menu-btn"_spr);
9189

9290
if (auto menu = typeinfo_cast<CCMenu*>(bottomMenu)) {
9391
menu->addChild(btn);
@@ -184,4 +182,32 @@ class $modify(HorribleMenuLayer, MenuLayer) {
184182
void onHorribleButton(CCObject*) {
185183
if (auto popup = HorribleMenuPopup::create()) popup->show();
186184
};
185+
};
186+
187+
class $modify(HorriblePauseLayer, PauseLayer) {
188+
void customSetup() {
189+
PauseLayer::customSetup();
190+
191+
if (auto rightMenu = getChildByID("right-button-menu")) {
192+
auto btnSprite = CircleButtonSprite::createWithSpriteFrameName(
193+
"GJ_moonsIcon_001.png",
194+
0.875f,
195+
CircleBaseColor::Green,
196+
CircleBaseSize::MediumAlt
197+
);
198+
btnSprite->setScale(0.6f);
199+
200+
auto btn = CCMenuItemSpriteExtra::create(
201+
btnSprite,
202+
this,
203+
menu_selector(HorribleMenuLayer::onHorribleButton)
204+
);
205+
btn->setID("menu-btn"_spr);
206+
207+
if (auto menu = typeinfo_cast<CCMenu*>(rightMenu)) {
208+
menu->addChild(btn);
209+
menu->updateLayout(true);
210+
};
211+
};
212+
};
187213
};

src/modified/GJBaseGameLayer.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "../RandomSeeder.hpp"
22

3+
#include "../layers/MathQuiz.hpp"
4+
#include "../popups/RandomAdPopup.hpp"
5+
36
#include <Geode/Geode.hpp>
47

58
#include <Geode/utils/terminate.hpp>
@@ -11,6 +14,13 @@ using namespace geode::prelude;
1114
static RandomSeeder _randomSeeder;
1215

1316
class $modify(HorribleGJBaseGameLayer, GJBaseGameLayer) {
17+
struct Fields {
18+
MathQuiz* m_currentQuiz = nullptr;
19+
RandomAdPopup* m_currentAd = nullptr;
20+
21+
float m_adCooldown = 0.f;
22+
};
23+
1424
void handleButton(bool down, int button, bool isPlayer1) {
1525
auto horribleMod = getMod();
1626

@@ -28,4 +38,51 @@ class $modify(HorribleGJBaseGameLayer, GJBaseGameLayer) {
2838
GJBaseGameLayer::handleButton(down, button, isPlayer1);
2939
};
3040
};
41+
42+
void update(float p0) {
43+
auto horribleMod = getMod();
44+
45+
auto rnd = rand() % 101;
46+
log::debug("gjbasegamelayer update chance {}", rnd);
47+
48+
if (horribleMod->getSavedValue<bool>("math-quiz", false)) {
49+
if (rnd <= 1) {
50+
log::warn("richard was here");
51+
52+
if (m_isPracticeMode && !m_fields->m_currentQuiz) {
53+
if (auto quiz = MathQuiz::create()) {
54+
m_fields->m_currentQuiz = quiz;
55+
m_fields->m_currentQuiz->customSetup();
56+
57+
CCScene::get()->addChild(m_fields->m_currentQuiz);
58+
};
59+
};
60+
};
61+
};
62+
63+
if (horribleMod->getSavedValue<bool>("ads", false)) {
64+
m_fields->m_adCooldown += p0; // continue til it hits 10 sec cooldown
65+
if (m_fields->m_adCooldown >= 10.f) m_fields->m_adCooldown = 0.f;
66+
67+
if (rnd <= 1) {
68+
log::warn("ad time!");
69+
70+
if (!m_isPracticeMode && !m_fields->m_currentAd && m_fields->m_adCooldown < 10.f) {
71+
if (auto popup = RandomAdPopup::create()) {
72+
m_fields->m_currentAd = popup;
73+
m_fields->m_currentAd->show();
74+
};
75+
};
76+
77+
// if there's already an ad muahahahaha
78+
if (auto alreadyPopup = CCScene::get()->getChildByID("ad"_spr)) {
79+
log::debug("there's already an ad!");
80+
} else {
81+
m_fields->m_currentAd = nullptr;
82+
};
83+
};
84+
};
85+
86+
GJBaseGameLayer::update(p0);
87+
};
3188
};

0 commit comments

Comments
 (0)