Fix the generation of new platforms so they stick to the average.
This commit is contained in:
parent
4166983809
commit
61d19865dd
2 changed files with 13 additions and 9 deletions
|
@ -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@"
|
||||
|
|
|
@ -29,26 +29,28 @@
|
|||
#include <algorithm>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/circular_buffer.hpp>
|
||||
#include <boost/algorithm/clamp.hpp>
|
||||
|
||||
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<float>(g_platfHeight), (static_cast<float>(REFERENCE_HEIGHT) - parStart) / static_cast<float>(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<float>(RAND_MAX);
|
||||
const float yDist = static_cast<float>(std::rand()) * invRandMax * (lowerRange + upperRange - minDist) + minDist;
|
||||
const float yDist = static_cast<float>(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<float>(totalPlatf);
|
||||
const int2 platfWH(g_platfWidth, g_platfHeight);
|
||||
const float2 platfWH(static_cast<float>(g_platfWidth), static_cast<float>(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<float2>(platfWH)));
|
||||
m_localdata->platforms.push_back(Platform(m_localdata->sdlmain, newPos, &m_localdata->texture, platfWH));
|
||||
|
||||
if (static_cast<float>(REFERENCE_HEIGHT) - newPos.y() < averageTarget)
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue