@@ -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 }
0 commit comments