lv1: slightly improve random generation
This commit is contained in:
parent
bf611f7cd3
commit
cb76c5137c
|
@ -13,6 +13,7 @@ set(SOURCES
|
|||
src/generator/gen1.cpp
|
||||
src/generator/gen2.cpp
|
||||
src/generator/gen3.cpp
|
||||
src/generator/path.cpp
|
||||
src/level.cpp
|
||||
src/log.cpp
|
||||
src/main.cpp
|
||||
|
|
|
@ -4,6 +4,18 @@
|
|||
struct level;
|
||||
typedef struct level level_t;
|
||||
|
||||
/* A utility structure holding data for path carver - a generator tool that
|
||||
produces a random traversable path. */
|
||||
struct path
|
||||
{
|
||||
path(int initial_pos);
|
||||
void next(struct section *section);
|
||||
|
||||
private:
|
||||
int pos;
|
||||
bool last_skipped;
|
||||
};
|
||||
|
||||
struct generator
|
||||
{
|
||||
virtual void generate(level_t *) = 0;
|
||||
|
@ -16,7 +28,7 @@ struct gen1 : public generator
|
|||
void generate(level_t *) override;
|
||||
~gen1() override = default;
|
||||
|
||||
int last_pos;
|
||||
path paths[3];
|
||||
};
|
||||
|
||||
struct gen2 : public generator
|
||||
|
|
|
@ -3,32 +3,41 @@
|
|||
|
||||
#define N PLATFORM_COUNT
|
||||
|
||||
gen1::gen1() : last_pos{0}
|
||||
gen1::gen1(): paths{{0}, {N/3}, {N*2/3}}
|
||||
{
|
||||
srand(0xc0ffee);
|
||||
srand(0xc0ffee);
|
||||
}
|
||||
|
||||
void gen1::generate(level_t *level)
|
||||
{
|
||||
struct section section;
|
||||
int r = rand() % 3;
|
||||
int kind = rand() % 2;
|
||||
int length = 2 + rand() % 6;
|
||||
|
||||
if(r == 0) {
|
||||
for(int i = 0; i < N; i++)
|
||||
section.platforms[i].type = PLATFORM_WHITE;
|
||||
}
|
||||
else if(r == 1) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
auto t = (i % 2) ? PLATFORM_WHITE : PLATFORM_EMPTY;
|
||||
section.platforms[i].type = t;
|
||||
}
|
||||
}
|
||||
else if(r == 2) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
auto t = (i % 2) ? PLATFORM_EMPTY : PLATFORM_WHITE;
|
||||
section.platforms[i].type = t;
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < length; k++) {
|
||||
struct section section;
|
||||
for(int i = 0; i < N; i++)
|
||||
section.platforms[i].type = PLATFORM_EMPTY;
|
||||
|
||||
level->section_buffer.push_back(section);
|
||||
/* Kind #0: Only the random paths */
|
||||
for(int i = 0; i < 3; i++)
|
||||
this->paths[i].next(§ion);
|
||||
|
||||
/* Kind #1: Also add some fixed blocks */
|
||||
if(kind == 1) {
|
||||
int r = rand() % 3;
|
||||
|
||||
if(r == 0 || r == 1) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
auto t = ((i ^ k) & 1) ? PLATFORM_WHITE : PLATFORM_EMPTY;
|
||||
section.platforms[i].type = t;
|
||||
}
|
||||
}
|
||||
if(r == 2) {
|
||||
for(int i = 0; i < N; i++)
|
||||
section.platforms[i].type = PLATFORM_WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
level->section_buffer.push_back(section);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#include "../generator.h"
|
||||
#include "../level.h"
|
||||
|
||||
path::path(int initial_pos):
|
||||
pos {initial_pos}, last_skipped {true}
|
||||
{
|
||||
}
|
||||
|
||||
void path::next(struct section *section)
|
||||
{
|
||||
int skip = !this->last_skipped && (rand() % 4 == 0);
|
||||
|
||||
if(skip) {
|
||||
this->last_skipped = true;
|
||||
}
|
||||
else {
|
||||
int diff = rand() % 3 - 1;
|
||||
section->platforms[this->pos].type = PLATFORM_WHITE;
|
||||
this->pos = (this->pos + PLATFORM_COUNT + diff) % PLATFORM_COUNT;
|
||||
this->last_skipped = false;
|
||||
}
|
||||
}
|
|
@ -4,13 +4,13 @@
|
|||
/* Radius of the level cylinder, in world units. */
|
||||
#define LEVEL_RADIUS num(4.0)
|
||||
/* Section lengths, in world units. */
|
||||
#define SECTION_LENGTH num(4.0)
|
||||
#define SECTION_LENGTH num(3.0)
|
||||
/* Number of platforms in the world cylinder. */
|
||||
#define PLATFORM_COUNT 10
|
||||
/* Magnitude of the gravity field, locally (world units/s^2), when holding the
|
||||
jump button and when releasing it. */
|
||||
#define HOVERING_GRAVITY num(-1.25)
|
||||
#define FALLING_GRAVITY num(-6.0)
|
||||
#define FALLING_GRAVITY num(-8.0)
|
||||
/* Vertical speed granted when a jump starts (world units/s). */
|
||||
#define JUMP_THRUST num(1.5)
|
||||
|
||||
|
|
Loading…
Reference in New Issue