MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / init

Method init

Source/PlayLayer.cpp:521–695  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

519}
520
521bool PlayLayer::init(GJGameLevel* level)
522{
523 if (!Layer::init())
524 return false;
525
526 setLevel(level);
527
528 _effectManager = EffectManager::create();
529 this->addChild(_effectManager);
530
531 setInstance();
532
533 // initBatchNodes();
534
535 auto winSize = Director::getInstance()->getWinSize();
536
537 dn = ax::DrawNode::create();
538 dn->setPosition({-15, -15});
539 addChild(dn, 99999);
540
541 initBatchNodes();
542
543 this->_player1 = PlayerObject::create(GameToolbox::randomInt(1, 12), this);
544 this->_player1->setPosition({-20, 105});
545 _main2BatchNode->addChild(this->_player1, 3);
546 this->_player1->setAnchorPoint({0, 0});
547
548 _player1->setMainColor({125, 255, 0});
549 _player1->setSecondaryColor({0, 255, 255});
550
551 this->_player2 = PlayerObject::create(GameToolbox::randomInt(1, 12), this);
552 this->_player2->setPosition({-20, 105});
553 _main2BatchNode->addChild(this->_player2, 3);
554 this->_player2->setAnchorPoint({0, 0});
555
556 _player2->setMainColor({125, 255, 0});
557 _player2->setSecondaryColor({0, 255, 255});
558
559 // std::string levelStr = FileUtils::getInstance()->getStringFromFile("level.txt");
560 std::string levelStr = level->_levelString;
561
562 if (levelStr.empty())
563 {
564 nlohmann::json file = nlohmann::json::parse(FileUtils::getInstance()->getStringFromFile("Custom/mainLevels.json"));
565 if (file.contains(std::to_string(level->_levelID))) {
566 levelStr = fmt::format("H4sIAAAAAAAAA{}", file[std::to_string(level->_levelID)].get<std::string>());
567 }
568 }
569
570 // scope based timer
571 {
572 auto s = BenchmarkTimer("load level");
573 if (!levelStr.empty()) {
574 if (levelStr.at(0) != 'k') levelStr = GJGameLevel::decompressLvlStr(levelStr);
575 loadLevel(levelStr);
576 }
577 }
578

Callers 1

createMethod · 0.45

Calls 14

createFunction · 0.85
parseFunction · 0.85
BenchmarkTimerClass · 0.85
logFunction · 0.85
setPositionMethod · 0.80
emptyMethod · 0.80
setScaleYMethod · 0.80
sizeMethod · 0.80
setScaleMethod · 0.80
to_stringFunction · 0.50
setMainColorMethod · 0.45
setSecondaryColorMethod · 0.45

Tested by

no test coverage detected