void CreditScene::update(float) { if (_buttons.empty()) return; if(_trigged) { if (Graphics::getInstance()->isBlack()) { (*_cursor)->GET_CMP(ButtonCmp)->execute(); } return; } auto playerInputCmp = Scene::getPlayerInput()->GET_CMP(InputCmp); if (checkConfirmButton(playerInputCmp->_isJump)){ Graphics::getInstance()->fadeOut(1.5f); _trigged = true; } else if (checkUpButton(playerInputCmp->_isUp)) { _darker(); if (_cursor == _buttons.begin()) { _cursor = --(_buttons.end()); } else { --_cursor; } _brighter(); } else if (checkDownButton(playerInputCmp->_isDown)) { _darker(); ++_cursor; if (_cursor == _buttons.end()) { _cursor = _buttons.begin(); } _brighter(); } }
static colour brighten(colour c, colour against) { uint r = red(c), g = green(c), b = blue(c); // "brighten" away from the background: // if we are closer to black than the contrast reference, rather darken bool darken = colour_dist(c, 0) < colour_dist(against, 0); #ifdef debug_brighten printf ("%s %06X against %06X\n", darken ? "darkening" : "brighting", c, against); #endif uint _brighter() { uint s = min(85, 255 - max(max(r, g), b)); return make_colour(r + s, g + s, b + s); } uint _darker() { int sub = 70; return make_colour(max(0, (int)r - sub), max(0, (int)g - sub), max(0, (int)b - sub)); } colour bright; uint thrsh = 22222; // contrast threshhold; // if we're closer to either fg or bg, // turn "brightening" into the other direction if (darken) { bright = _darker(); #ifdef debug_brighten printf ("darker %06X -> %06X dist %d\n", c, bright, colour_dist(c, bright)); #endif if (colour_dist(bright, c) < thrsh || colour_dist(bright, against) < thrsh) { bright = _brighter(); #ifdef debug_brighten printf (" fix %06X -> %06X dist %d/%d\n", c, bright, colour_dist(bright, c), colour_dist(bright, against)); #endif } } else { bright = _brighter(); #ifdef debug_brighten printf ("lightr %06X -> %06X dist %d\n", c, bright, colour_dist(c, bright)); #endif if (colour_dist(bright, c) < thrsh || colour_dist(bright, against) < thrsh) { bright = _darker(); #ifdef debug_brighten printf (" fix %06X -> %06X dist %d/%d\n", c, bright, colour_dist(bright, c), colour_dist(bright, against)); #endif } } return bright; }
bool CreditScene::init() { Graphics::getInstance()->fadeIn(0.6f); _isInit = true; auto playerInput = Factory::get()->loadEntityFromFile("playerInput"); playerInput->init(); Scene::setPlayerInput(playerInput); _credits = Factory::get()->loadEntityFromFile("credits"); _credits->init(); auto PosCmp = _credits->GET_CMP(PositionComponent); PosCmp->setPosition(Graphics::getInstance()->getScreenSize().cast<float>() * 0.5); auto SpCmp = _credits->GET_CMP(SpriteCmp); // 1.5 1.5 looks good SpCmp->rescale(2.0f, 2.0f); Eigen::Vector2f pos = Graphics::getInstance()->getScreenSize().cast<float>() * 0.75; pos.x() = Graphics::getInstance()->getScreenSize().cast<float>().x() * 0.88; Entity* returnButton = Factory::get()->loadEntityFromFile("buttonBack"); returnButton->init(); std::function<void()> optionFunc = [this](){ free(); Director::get()->pushScene(new MenuScene()); }; returnButton->GET_CMP(ButtonCmp)->setCallback(optionFunc); PositionComponent* posCmp = returnButton->GET_CMP(PositionComponent); pos.y() += 200.0f; posCmp->setPosition(pos); _buttons.push_back(returnButton); _cursor = _buttons.begin(); _brighter(); return _isInit; }