Skip to content

Commit 49c6ead

Browse files
health added
1 parent 8bd4e9f commit 49c6ead

4 files changed

Lines changed: 146 additions & 20 deletions

File tree

src/modified/GJBaseGameLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class $modify(HorribleGJBaseGameLayer, GJBaseGameLayer) {
1010
void handleButton(bool down, int button, bool isPlayer1) {
1111
auto horribleMod = getMod();
1212

13-
if (horribleMod->getSavedValue<bool>("no-jump", false)) {
13+
if (horribleMod->getSavedValue<bool>("no-jump", false) && !m_isPlatformer) {
1414
if (button == 1) {
1515
if ((rand() % 11) == 0) {
1616
log::error("skipped dat jump");

src/modified/PlayLayer.cpp

Lines changed: 136 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ class $modify(HorriblePlayLayer, PlayLayer)
3131

3232
RandomAdPopup *m_currentAd = nullptr;
3333

34+
CCLabelBMFont *m_healthLabel = nullptr;
3435
CCLabelBMFont *m_oxygenLabel = nullptr;
3536

37+
float m_health = 100.f;
3638
float m_oxygenLevel = 100.f;
3739
bool m_oxygenActive = false;
3840

3941
Ref<CCSprite> m_oxygenBar;
4042
CCSprite *m_oxygenBarFill;
43+
44+
Ref<CCSprite> m_healthBar;
45+
CCSprite *m_healthBarFill;
4146
};
4247

4348
bool init(GJGameLevel *level, bool useReplay, bool dontCreateObjects)
@@ -46,6 +51,8 @@ class $modify(HorriblePlayLayer, PlayLayer)
4651
int rnd = rand() % 101;
4752
log::info("playlayer init called {}", rnd);
4853

54+
auto winSize = CCDirector::sharedDirector()->getWinSize();
55+
4956
if (!PlayLayer::init(level, useReplay, dontCreateObjects))
5057
return false;
5158

@@ -72,6 +79,51 @@ class $modify(HorriblePlayLayer, PlayLayer)
7279
}
7380
}
7481

82+
if (horribleMod->getSavedValue<bool>("health", false))
83+
{
84+
m_fields->m_health = 100.f;
85+
std::string hp = fmt::format("HP\n{}%", static_cast<int>(m_fields->m_health));
86+
87+
if (!m_fields->m_healthBar) {
88+
m_fields->m_healthBar = CCSprite::create("slidergroove2.png");
89+
m_fields->m_healthBar->setID("health"_spr);
90+
m_fields->m_healthBar->setPosition({10.f, getScaledContentHeight() / 2.f});
91+
m_fields->m_healthBar->setRotation(90.f);
92+
m_fields->m_healthBar->setZOrder(101);
93+
94+
m_fields->m_healthBarFill = CCSprite::create("sliderBar2.png");
95+
m_fields->m_healthBarFill->setID("health-fill"_spr);
96+
m_fields->m_healthBarFill->setZOrder(-1);
97+
m_fields->m_healthBarFill->setRotation(-180.f);
98+
m_fields->m_healthBarFill->setColor({255, 0, 0});
99+
m_fields->m_healthBarFill->setPosition({m_fields->m_healthBar->getScaledContentWidth() - 2.f, 4.f});
100+
m_fields->m_healthBarFill->setAnchorPoint({0, 1});
101+
102+
auto fullHealth = m_fields->m_healthBar->getScaledContentWidth() - 4.f;
103+
104+
m_fields->m_healthBarFill->setTextureRect({0, 0, fullHealth, 8});
105+
106+
m_fields->m_healthBar->addChild(m_fields->m_healthBarFill);
107+
108+
addChild(m_fields->m_healthBar);
109+
}
110+
111+
if (!m_fields->m_healthLabel)
112+
{
113+
m_fields->m_healthLabel = CCLabelBMFont::create(hp.c_str(), "bigFont.fnt");
114+
m_fields->m_healthLabel->setColor({255, 0, 0});
115+
m_fields->m_healthLabel->setAnchorPoint({0.f, 1.0f});
116+
m_fields->m_healthLabel->setPosition({2.f, (getScaledContentHeight() / 2.f) - (m_fields->m_healthBar->getScaledContentWidth() / 2.f) - 1.25f});
117+
m_fields->m_healthLabel->setScale(0.25f);
118+
119+
addChild(m_fields->m_healthLabel, 100);
120+
}
121+
else
122+
{
123+
m_fields->m_healthLabel->setString(hp.c_str());
124+
};
125+
};
126+
75127
if (horribleMod->getSavedValue<bool>("oxygen", false))
76128
{
77129
m_fields->m_oxygenActive = true;
@@ -104,22 +156,39 @@ class $modify(HorriblePlayLayer, PlayLayer)
104156
addChild(m_fields->m_oxygenBar);
105157
};
106158

107-
std::string buf = fmt::format("o2: {}%", static_cast<int>(m_fields->m_oxygenLevel));
159+
if (m_fields->m_healthBar)
160+
{
161+
m_fields->m_oxygenBar->setPosition({m_fields->m_healthBar->getPositionX() + 20.f, m_fields->m_healthBar->getPositionY()});
162+
}
163+
else
164+
{
165+
m_fields->m_oxygenBar->setPosition({10.f, getScaledContentHeight() / 2.f});
166+
};
167+
168+
std::string buf = fmt::format("o2\n{}%", static_cast<int>(m_fields->m_oxygenLevel));
108169

109170
if (!m_fields->m_oxygenLabel)
110171
{
111172
m_fields->m_oxygenLabel = CCLabelBMFont::create(buf.c_str(), "bigFont.fnt");
112173
m_fields->m_oxygenLabel->setColor({0, 175, 255});
113174
m_fields->m_oxygenLabel->setAnchorPoint({0.f, 1.0f});
114175
m_fields->m_oxygenLabel->setPosition({2.f, (getScaledContentHeight() / 2.f) - (m_fields->m_oxygenBar->getScaledContentWidth() / 2.f) - 1.25f});
115-
m_fields->m_oxygenLabel->setScale(0.375f);
176+
m_fields->m_oxygenLabel->setScale(0.25f);
116177

117178
addChild(m_fields->m_oxygenLabel, 100);
118179
}
119180
else
120181
{
121182
m_fields->m_oxygenLabel->setString(buf.c_str());
122183
};
184+
185+
if (m_fields->m_healthLabel) {
186+
m_fields->m_oxygenLabel->setPosition({m_fields->m_oxygenLabel->getPositionX() + 20.f, m_fields->m_oxygenLabel->getPositionY()});
187+
}
188+
else
189+
{
190+
m_fields->m_oxygenLabel->setPosition({2.f, (getScaledContentHeight() / 2.f) - (m_fields->m_oxygenBar->getScaledContentWidth() / 2.f) - 1.25f});
191+
}
123192
}
124193
else
125194
{
@@ -343,7 +412,7 @@ class $modify(HorriblePlayLayer, PlayLayer)
343412
if (m_fields->m_oxygenLevel < 0.f)
344413
m_fields->m_oxygenLevel = 0.f;
345414

346-
std::string buf = fmt::format("o2: {}%", static_cast<int>(m_fields->m_oxygenLevel));
415+
std::string buf = fmt::format("o2\n{}%", static_cast<int>(m_fields->m_oxygenLevel));
347416
m_fields->m_oxygenLabel->setString(buf.c_str());
348417

349418
float maxWidth = m_fields->m_oxygenBar->getContentWidth() - 4.f;
@@ -362,14 +431,32 @@ class $modify(HorriblePlayLayer, PlayLayer)
362431

363432
if (m_fields->m_oxygenLabel)
364433
{
365-
std::string buf = fmt::format("o2: {}%", static_cast<int>(m_fields->m_oxygenLevel));
434+
std::string buf = fmt::format("o2\n{}%", static_cast<int>(m_fields->m_oxygenLevel));
366435
m_fields->m_oxygenLabel->setString(buf.c_str());
367436
};
368437
};
369438

439+
void resetHealth()
440+
{
441+
m_fields->m_health = 100.f;
442+
443+
if (m_fields->m_healthLabel)
444+
{
445+
std::string hp = fmt::format("HP\n{}%", static_cast<int>(m_fields->m_health));
446+
m_fields->m_healthLabel->setString(hp.c_str());
447+
}
448+
449+
if (m_fields->m_healthBar)
450+
{
451+
float maxWidth = m_fields->m_healthBar->getContentWidth() - 4.f;
452+
m_fields->m_healthBarFill->setTextureRect({0, 0, maxWidth, 8});
453+
}
454+
}
455+
370456
void resetLevel()
371457
{
372458
resetOxygenLevel();
459+
resetHealth();
373460
PlayLayer::resetLevel();
374461
};
375462

@@ -393,6 +480,49 @@ class $modify(HorriblePlayLayer, PlayLayer)
393480
bool griefEnabled = horribleMod->getSavedValue("grief", false);
394481
bool congregEnabled = horribleMod->getSavedValue("congregation", false);
395482
bool fakeDeadEnabled = horribleMod->getSavedValue("death", false);
483+
bool healthEnabled = horribleMod->getSavedValue("health", false);
484+
485+
// do stuff for health
486+
if (healthEnabled)
487+
{
488+
log::debug("health enabled, checking player health");
489+
if (m_fields->m_health > 0)
490+
{
491+
m_fields->m_health -= 0.1f;
492+
log::debug("Player health is {}", m_fields->m_health);
493+
m_player1->playSpawnEffect();
494+
m_player2->playSpawnEffect();
495+
GJBaseGameLayer::shakeCamera(1.f, 5.f, 1.f);
496+
497+
if (rand() % 2 == 0)
498+
{
499+
FMODAudioEngine::sharedEngine()->playEffect("grunt01.ogg");
500+
} else if (rand() % 2 == 1)
501+
{
502+
FMODAudioEngine::sharedEngine()->playEffect("grunt02.ogg");
503+
} else if (rand() % 2 == 2)
504+
{
505+
FMODAudioEngine::sharedEngine()->playEffect("grunt03.ogg");
506+
};
507+
508+
if (m_fields->m_healthLabel)
509+
{
510+
std::string hp = fmt::format("HP\n{}%", static_cast<int>(m_fields->m_health));
511+
m_fields->m_healthLabel->setString(hp.c_str());
512+
513+
// Update health bar
514+
float maxWidth = m_fields->m_healthBar->getContentWidth() - 4.f;
515+
float newWidth = maxWidth * (m_fields->m_health / 100.f);
516+
m_fields->m_healthBarFill->setTextureRect({0, 0, newWidth, 8});
517+
}
518+
return;
519+
}
520+
else
521+
{
522+
log::debug("Player health is 0, destroying player");
523+
PlayLayer::destroyPlayer(player, game);
524+
}
525+
}
396526

397527
// Show explosion visual effect but do not kill the player
398528
if (fakeDeadEnabled)
@@ -403,17 +533,12 @@ class $modify(HorriblePlayLayer, PlayLayer)
403533

404534
if (m_player1)
405535
{
406-
log::debug("p1 fake death");
536+
log::debug("fake death");
407537
m_player1->playDeathEffect();
408-
m_player1->playSpawnEffect();
409538
m_player1->resetPlayerIcon();
410539
m_player1->m_isDead = false;
411-
}
412-
else if (m_player2)
413-
{
414-
log::debug("p2 fake death");
540+
415541
m_player2->playDeathEffect();
416-
m_player2->playSpawnEffect();
417542
m_player2->resetPlayerIcon();
418543
m_player2->m_isDead = false;
419544
}

src/modified/PlayerObject.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ class $modify(HorriblePlayerObject, PlayerObject)
4343
auto playLayer = PlayLayer::get();
4444
auto horribleMod = getMod();
4545

46+
auto healthEnabled = horribleMod->getSavedValue<bool>("health", false);
47+
4648
if (playLayer && playLayer->m_percentageLabel)
4749
{
4850
// lil hack on getting the percentage lmao
4951
std::string percentage = playLayer->m_percentageLabel->getString();
5052
percentage.erase(std::remove(percentage.begin(), percentage.end(), '%'), percentage.end());
5153
int currentPercentage = std::stoi(percentage);
52-
//log::debug("percentage {}", currentPercentage);
54+
// log::debug("percentage {}", currentPercentage);
5355

5456
if (horribleMod->getSavedValue<bool>("freeze", false))
5557
{
@@ -67,7 +69,7 @@ class $modify(HorriblePlayerObject, PlayerObject)
6769
if (interval <= 0.0f || interval > 1.0f)
6870
interval = 1.f / 60.f; // fallback to 60 FPS if invalid
6971
CCDirector::sharedDirector()->setAnimationInterval(interval);
70-
//log::debug("cap fps to {} (interval {})", randomFPS, interval);
72+
// log::debug("cap fps to {} (interval {})", randomFPS, interval);
7173
}
7274
else
7375
{
@@ -81,11 +83,10 @@ class $modify(HorriblePlayerObject, PlayerObject)
8183
if (interval <= 0.0f || interval > 1.0f)
8284
interval = 1.f / 60.f; // fallback to 60 FPS if invalid
8385
CCDirector::sharedDirector()->setAnimationInterval(interval);
84-
//log::debug("reset fps to {} (interval {})", oldFPS, interval);
86+
// log::debug("reset fps to {} (interval {})", oldFPS, interval);
8587
}
8688
}
8789
}
88-
8990
PlayerObject::update(p0);
9091
}
91-
};
92+
};

src/popups/HorribleMenuPopup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ std::vector<std::tuple<std::string, std::string, std::string, SillyTier, bool>>
4343
"freeze",
4444
"Random 90%+ FPS Drop",
4545
"Your game FPS starts dropping between 90-99% while playing.\n<cy>Credit: Hexfire</c>",
46-
SillyTier::Low,
46+
SillyTier::Medium,
4747
false
4848
},
4949
{
@@ -70,14 +70,14 @@ std::vector<std::tuple<std::string, std::string, std::string, SillyTier, bool>>
7070
{
7171
"no-jump",
7272
"Randomly Don't Jump",
73-
"When making an input in a level, there will be a chance your character does not jump.\n<cy>Credit: GilanyKing12</c>",
73+
"When making an input in a level, there will be a chance your character does not jump.\n<cy>Credit: GilanyKing12</c>\n<cr>Note: This will not work in platformer mode</c>",
7474
SillyTier::Low,
7575
false
7676
},
7777
{
7878
"gravity",
7979
"Randomize Gravity",
80-
"Every time you jump in the level, the gravity will change to a random value.\n<cy>Credit: NJAgain</c>",
80+
"Every time you jump in the level, the gravity will change to a random value.\n<cy>Credit: NJAgain</c>\n<cr>Note: This will not work in platformer mode</c>",
8181
SillyTier::Low,
8282
false
8383
},

0 commit comments

Comments
 (0)