Skip to content

Commit

Permalink
Fix robert scaling, Fix double jump jumpscare bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NicknameGG committed Jan 28, 2024
1 parent 5ab4a58 commit c731fbc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
5 changes: 3 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
57 changes: 40 additions & 17 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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
Expand All @@ -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);

Expand All @@ -35,17 +51,24 @@ class $modify(PlayerObject) {
// Check if randomizing is enabled
auto randomizeOption = Mod::get()->getSettingValue<bool>("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)
Expand All @@ -57,14 +80,6 @@ class $modify(PlayerObject) {
if (!GameManager::sharedState()->getPlayLayer())
return;

// Check if randomizing is enabled
auto randomizeOption = Mod::get()->getSettingValue<bool>("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
Expand All @@ -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");
}
};

0 comments on commit c731fbc

Please sign in to comment.