Generate new platforms as you climb.
This is actually broken as platforms never unregister themselves. An upcoming refactoring will change things, so registering/unregistering will not be necessary anymore.
This commit is contained in:
parent
f142367a8a
commit
d5d75b034e
2 changed files with 22 additions and 27 deletions
|
@ -115,7 +115,8 @@ namespace cloonel {
|
|||
///--------------------------------------------------------------------------
|
||||
PlatformSystem::PlatformSystem (const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance) :
|
||||
Placeable(float2(0.0f)),
|
||||
m_localdata(new LocalData(parTexturePath, parSDLMain, parScene, parMaxDistance))
|
||||
m_localdata(new LocalData(parTexturePath, parSDLMain, parScene, parMaxDistance)),
|
||||
m_targetAverage(parMaxDistance / 5.25f) //TODO: change this value to make up for the difficulty
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -128,21 +129,27 @@ namespace cloonel {
|
|||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void PlatformSystem::SpawnPlatforms() {
|
||||
//const int2 refWH(REFERENCE_WIDTH, REFERENCE_HEIGHT);
|
||||
//const int2 platfWH(g_platfWidth, g_platfHeight);
|
||||
const size_t totalPlatf = MAX_PLATFORMS_ON_SCREEN;
|
||||
const float2 platfWH(static_cast<float>(g_platfWidth), static_cast<float>(g_platfHeight));
|
||||
|
||||
// if (m_localdata.platforms.back().platform->TopLeft().y() <= 0.0f) {
|
||||
// const float2 newPos(static_cast<float>(std::rand() % (refWH.x() - platfWH.x())), static_cast<float>(std::rand() % (refWH.y() - platfWH.y())));
|
||||
size_t freePlatforms = 0;
|
||||
for (size_t z = 0; z < m_localdata->platforms.size(); ++z) {
|
||||
if (m_localdata->platforms[z].platform->GetPos().y() < 0.0f)
|
||||
++freePlatforms;
|
||||
else
|
||||
break;
|
||||
}
|
||||
freePlatforms = totalPlatf - m_localdata->platforms.size() + freePlatforms;
|
||||
|
||||
//if (m_localdata->platforms.empty()) {
|
||||
// const float2 newPos(static_cast<float>(std::rand() % (refWH.x() - platfWH.x())), static_cast<float>(std::rand() % (refWH.y() - platfWH.y())));
|
||||
// m_localdata->platforms.push_back(Platform(m_localdata->sdlmain, newPos, &m_localdata->texture, static_cast<float2>(platfWH)));
|
||||
float prevPlatf = (m_localdata->platforms.empty() ? 0.0f : m_localdata->platforms.back().platform->GetPos().y() + GetPos().y());
|
||||
while (static_cast<float>(REFERENCE_HEIGHT) - prevPlatf >= m_targetAverage) {
|
||||
assert(freePlatforms > 0);
|
||||
const auto newPos(PositionForNewPlatf(prevPlatf, m_targetAverage, m_localdata->maxDistance, freePlatforms));
|
||||
--freePlatforms;
|
||||
prevPlatf = newPos.y();
|
||||
|
||||
// PlatformInfo& newPlatf = m_localdata->platforms.back();
|
||||
// m_localdata->scene->AddDrawable(&newPlatf.platform);
|
||||
// const Mover::PlaceableTicketType ticket = m_localdata->mover.RegisterPlaceable(&newPlatf.platform);
|
||||
// newPlatf.ticket = ticket;
|
||||
//}
|
||||
m_localdata->platforms.push_back(Platform(m_localdata->sdlmain, newPos, &m_localdata->texture, platfWH));
|
||||
}
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
@ -152,20 +159,7 @@ namespace cloonel {
|
|||
|
||||
//Spawn the initial platforms
|
||||
m_localdata->platforms.clear();
|
||||
const size_t totalPlatf = MAX_PLATFORMS_ON_SCREEN;
|
||||
//const auto totalPlatfFloatInv = 1.0f / static_cast<float>(totalPlatf);
|
||||
const float2 platfWH(static_cast<float>(g_platfWidth), static_cast<float>(g_platfHeight));
|
||||
float prevPlatf = 0.0f;
|
||||
const float averageTarget = m_localdata->maxDistance / 5.25f; //TODO: change this value to make up for the difficulty
|
||||
for (size_t z = 0; z < totalPlatf; ++z) {
|
||||
const auto newPos(PositionForNewPlatf(prevPlatf, averageTarget, m_localdata->maxDistance, totalPlatf - z));
|
||||
prevPlatf = newPos.y();
|
||||
|
||||
m_localdata->platforms.push_back(Platform(m_localdata->sdlmain, newPos, &m_localdata->texture, platfWH));
|
||||
|
||||
if (static_cast<float>(REFERENCE_HEIGHT) - newPos.y() < averageTarget)
|
||||
break;
|
||||
}
|
||||
this->SpawnPlatforms();
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace cloonel {
|
|||
const std::unique_ptr<LocalData> m_localdata;
|
||||
ColliderRegisterFunc m_registerToCollider;
|
||||
ColliderUnregisterFunc m_unregisterFromCollider;
|
||||
float m_targetAverage;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
|
|
Loading…
Reference in a new issue