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

Method updateCamera

Source/PlayLayer.cpp:810–890  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808}
809
810void PlayLayer::updateCamera(float dt)
811{
812 auto winSize = Director::getInstance()->getWinSize();
813 Vec2 cam = m_obCamPos;
814
815 PlayerObject* player = _player1;
816 Vec2 pPos = player->getPosition();
817
818 if (player->_currentGamemode != PlayerGamemodeCube || _isDualMode)
819 {
820 cam.y = (winSize.height * -0.5f) + m_fCameraYCenter;
821 if (cam.y <= 0.0f)
822 cam.y = 0.0f;
823 }
824 else
825 {
826 float unk2 = 90.0f;
827 float unk3 = 120.0f;
828 if (player->isGravityFlipped())
829 {
830 unk2 = 120.0f;
831 unk3 = 90.0f;
832 }
833 if (pPos.y <= winSize.height + cam.y - unk2)
834 {
835 if (pPos.y < unk3 + cam.y)
836 cam.y = pPos.y - unk3;
837 }
838 else
839 cam.y = pPos.y - winSize.height + unk2;
840 if (!player->isGravityFlipped())
841 {
842 Vec2 lastGroundPos = player->getLastGroundPos();
843
844 if (lastGroundPos.y == 105.f)
845 if (pPos.y <= cam.y + winSize.height - unk2)
846 cam.y = 0.0f;
847 }
848 }
849
850 cam.y = clampf(cam.y, 0.0f, 1140.f - winSize.height);
851
852 if (pPos.x >= winSize.width / 2.5f && !_player1->isDead() && !_player2->isDead() &&
853 !player->m_bIsPlatformer) // wrong but works for now
854 {
855 this->m_pBG->setPositionX(this->m_pBG->getPositionX() -
856 dt * player->getPlayerSpeed() * _bottomGround->getSpeed() * 0.1175f);
857 _bottomGround->update(dt * player->getPlayerSpeed());
858 _ceiling->update(dt * player->getPlayerSpeed());
859 cam.x = pPos.x - (winSize.width / 2.5f);
860 }
861 else if (player->m_bIsPlatformer)
862 cam.x = pPos.x - winSize.width / 2.f;
863
864 if (this->m_pBG->getPosition().x <= cam.x - 1024.f)
865 this->m_pBG->setPositionX(this->m_pBG->getPositionX() + 1024.f);
866
867 this->m_pBG->setPositionX(this->m_pBG->getPositionX() + (cam.x - m_obCamPos.x));

Callers 1

updateMethod · 0.95

Calls 6

isGravityFlippedMethod · 0.80
getLastGroundPosMethod · 0.80
isDeadMethod · 0.80
getPlayerSpeedMethod · 0.80
setPositionMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected