From c731fbc5fbd2b60288724c067423e43724453830 Mon Sep 17 00:00:00 2001 From: NicknameGG Date: Sun, 28 Jan 2024 16:13:19 -0600 Subject: [PATCH] Fix robert scaling, Fix double jump jumpscare bug --- mod.json | 5 +++-- src/main.cpp | 57 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/mod.json b/mod.json index a3c84e9..b033710 100644 --- a/mod.json +++ b/mod.json @@ -1,13 +1,14 @@ { "geode": "2.0.0", - "version": "v1.2.0", + "version": "v1.2.1", "id": "n.robtop-jumpscare", "name": "Robtop Jumpscare", "developer": "n", "gd": { - "android": "2.200", + "android": "2.205", "win": "2.204" }, + "repository": "https://github.com/NicknameGG/robtop-jumpscare", "description": "Jumpscare yourself everytime you jump!", "resources": { "files": [ diff --git a/src/main.cpp b/src/main.cpp index 57b12d7..4414c5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,10 +5,20 @@ using namespace geode::prelude; CCSprite *RobertTopala = nullptr; bool isHolding = false; +bool wasLastPushInAir = false; class $modify(PlayerObject) { void jumpscare() { + geode::log::info("Jumpscare called"); + // Check if randomizing is enabled + auto randomizeOption = Mod::get()->getSettingValue("randomize-jumpscare"); + + // if randomize is turned on then there is 1 in 100 chance of the jumpscare + if (randomizeOption && (rand() % 100 != 0)) { + return; + } + FMODAudioEngine::sharedEngine()->playEffect("vine-boom.mp3"_spr); // If action is running stop it @@ -22,6 +32,12 @@ class $modify(PlayerObject) { RobertTopala->runAction(CCFadeOut::create(1.0))->setTag(1); } + void playerDestroyed(bool p0) { + geode::log::info("========== Player destroyed =========="); + PlayerObject::playerDestroyed(p0); + isHolding = false; + } + TodoReturn releaseButton(PlayerButton p0) { PlayerObject::releaseButton(p0); @@ -35,17 +51,24 @@ class $modify(PlayerObject) { // Check if randomizing is enabled auto randomizeOption = Mod::get()->getSettingValue("randomize-jumpscare"); - // increment jump jumpscares only happen if randomization is disabled. + // increment jump jumpscares only happen if randomization is disabled. if (randomizeOption == false) { - // Check if robert exists and if the user is holding jump (Works only for the cube) - const auto runningScene = CCDirector::get()->getRunningScene(); - if (runningScene->getChildByID("robert-topala") && isHolding) { - this->jumpscare(); - } - } + // Check if robert exists and if the user is holding jump (Works only for the cube) + const auto runningScene = CCDirector::get()->getRunningScene(); + geode::log::info("Incrementing jumps able to jumpscare, {}", wasLastPushInAir); + + if (runningScene->getChildByID("robert-topala") && isHolding && !wasLastPushInAir) { + this->jumpscare(); + } } + wasLastPushInAir = false; + } + TodoReturn pushButton(PlayerButton p0) { + geode::log::info("Pushing button"); + wasLastPushInAir = !this->m_isOnGround; + PlayerObject::pushButton(p0); if (p0 != PlayerButton::Jump) @@ -57,14 +80,6 @@ class $modify(PlayerObject) { if (!GameManager::sharedState()->getPlayLayer()) return; - // Check if randomizing is enabled - auto randomizeOption = Mod::get()->getSettingValue("randomize-jumpscare"); - - // if randomize is turned on then there is 1 in 100 chance of the jumpscare - if (randomizeOption && (rand() % 100 != 0)) { - return; - } - const auto runningScene = CCDirector::get()->getRunningScene(); // Create robert if it doesn't exist in scene @@ -73,15 +88,23 @@ class $modify(PlayerObject) { RobertTopala->setID("robert-topala"); CCSize winSize = CCDirector::get()->getWinSize(); + float scaleRatio = (winSize.height / RobertTopala->getContentSize().height); + // Scale robert to fit screen - RobertTopala->setScaleX((winSize.width / RobertTopala->getContentSize().width)); - RobertTopala->setScaleY((winSize.height / RobertTopala->getContentSize().height)); + RobertTopala->setScaleX(scaleRatio); + RobertTopala->setScaleY(scaleRatio); // Center the robert RobertTopala->setPosition({winSize.width / 2, winSize.height / 2}); runningScene->addChild(RobertTopala, 100); + + // Set robert opacity to 0 + RobertTopala->setOpacity(0); } + this->jumpscare(); + + geode::log::info("End of pushButton"); } };