diff --git a/src/CloonelJumpConfig.h.in b/src/CloonelJumpConfig.h.in index e563dec..1d2fc18 100644 --- a/src/CloonelJumpConfig.h.in +++ b/src/CloonelJumpConfig.h.in @@ -30,6 +30,8 @@ #define DEF_WIN_HEIGHT REFERENCE_HEIGHT #define DEF_RANDOM_SEED 1984 #define MAX_PLATFORMS_ON_SCREEN 24 +#define REFERENCE_PLATFORM_WIDTH 104 +#define REFERENCE_PLATFORM_HEIGHT 25 /* TODO: make this path relative */ #define GAME_BASE_PATH "@CMAKE_SOURCE_DIR@" diff --git a/src/platformsystem.cpp b/src/platformsystem.cpp index f8c07a8..7f1c915 100644 --- a/src/platformsystem.cpp +++ b/src/platformsystem.cpp @@ -29,26 +29,28 @@ #include #include #include +#include namespace cloonel { namespace { - const uint32_t g_platfWidth = 104; - const uint32_t g_platfHeight = 25; + const uint32_t g_platfWidth = REFERENCE_PLATFORM_WIDTH; + const uint32_t g_platfHeight = REFERENCE_PLATFORM_HEIGHT; float2 PositionForNewPlatf (float parStart, float parAverage, float parMaxDist, size_t parLeft) { assert(parAverage >= 0.0f); const float& maxDist = parMaxDist; const float minDist = std::max(static_cast(g_platfHeight), (static_cast(REFERENCE_HEIGHT) - parStart) / static_cast(parLeft)); + const float average = boost::algorithm::clamp(parAverage, minDist, maxDist); assert(minDist <= maxDist); //make sure the player can jump all the way to the top - assert(minDist <= parAverage); //that would screw up the player + assert(minDist >= 0.0f); - const float upperRange = std::max(parAverage, maxDist) - parAverage; - const float lowerRange = std::max(parAverage, minDist) - minDist; + const float upperRange = std::max(average, maxDist) - average; + const float lowerRange = std::max(average, minDist) - minDist; assert(upperRange >= 0.0f); assert(lowerRange >= 0.0f); const float invRandMax = 1.0f / static_cast(RAND_MAX); - const float yDist = static_cast(std::rand()) * invRandMax * (lowerRange + upperRange - minDist) + minDist; + const float yDist = static_cast(std::rand()) * invRandMax * 2.0f * std::min(lowerRange, upperRange) + minDist; assert(yDist >= minDist and yDist <= maxDist); const auto rndNum = std::rand() % (REFERENCE_WIDTH - g_platfWidth); @@ -151,14 +153,14 @@ namespace cloonel { m_localdata->platforms.clear(); const size_t totalPlatf = MAX_PLATFORMS_ON_SCREEN; //const auto totalPlatfFloatInv = 1.0f / static_cast(totalPlatf); - const int2 platfWH(g_platfWidth, g_platfHeight); + const float2 platfWH(static_cast(g_platfWidth), static_cast(g_platfHeight)); float prevPlatf = 0.0f; - const float averageTarget = m_localdata->maxDistance / 8.0f; //TODO: change this value to make up for the difficulty + 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, static_cast(platfWH))); + m_localdata->platforms.push_back(Platform(m_localdata->sdlmain, newPos, &m_localdata->texture, platfWH)); if (static_cast(REFERENCE_HEIGHT) - newPos.y() < averageTarget) break;