add generator level1 (WIP)
This commit is contained in:
parent
8182afc61c
commit
4f38cd911b
|
@ -12,6 +12,7 @@ __pycache__/
|
|||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.vscode
|
||||
.nvimrc
|
||||
|
||||
# Screenshots and videos
|
||||
/screens
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#define N PLATFORM_COUNT
|
||||
|
||||
gen1::gen1(): m_path_carvers{{0}, {N/2}, {2*N/3}}
|
||||
gen1::gen1(): m_path_carver{0}
|
||||
{
|
||||
m_last_z = 0;
|
||||
srand(0xc0ffee);
|
||||
|
@ -11,48 +11,74 @@ gen1::gen1(): m_path_carvers{{0}, {N/2}, {2*N/3}}
|
|||
|
||||
void gen1::generate(struct level *level)
|
||||
{
|
||||
int kind = rand() % 2;
|
||||
int length = 2 + rand() % 6;
|
||||
struct platform p1;
|
||||
struct platform p2;
|
||||
static const int freq[] = {
|
||||
1,
|
||||
2, 2, 2, 2,
|
||||
3, 3, 3, 3, 3, 3,
|
||||
4,
|
||||
5, 5, 5,
|
||||
};
|
||||
|
||||
for(int k = 0; k < length; k++) {
|
||||
/* Generate an old-style "section" */
|
||||
m_path_carver.next(
|
||||
(rand() % 2) ? PLATFORM_LEN_LONG : PLATFORM_LEN_SHORT,
|
||||
&p1,
|
||||
true
|
||||
);
|
||||
|
||||
/* Kind #0: Only the random paths */
|
||||
for(int i = 0; i < 3; i++) {
|
||||
struct platform p;
|
||||
if(m_path_carvers[i].next(SECTION_LENGTH, &p))
|
||||
level->platform_buffer.push_back(p);
|
||||
p2 = p1;
|
||||
|
||||
switch (freq[rand() % (sizeof(freq) / sizeof(freq[0]))])
|
||||
{
|
||||
/* full circle */
|
||||
case 1:
|
||||
for (int i = 0 ; i < 10 ; i++) {
|
||||
p2.face = i;
|
||||
p2.length = (rand() % 2) ? PLATFORM_LEN_LONG : PLATFORM_LEN_SHORT;
|
||||
level->platform_buffer.push_back(p2);
|
||||
}
|
||||
break;
|
||||
|
||||
/* 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++) {
|
||||
if((i ^ k) & 1) {
|
||||
struct platform p;
|
||||
p.face = i;
|
||||
p.type = PLATFORM_WHITE;
|
||||
p.z = m_last_z;
|
||||
p.length = SECTION_LENGTH;
|
||||
level->platform_buffer.push_back(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(r == 2) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
struct platform p;
|
||||
p.face = i;
|
||||
p.type = PLATFORM_WHITE;
|
||||
p.z = m_last_z;
|
||||
p.length = SECTION_LENGTH;
|
||||
if(level)
|
||||
level->platform_buffer.push_back(p);
|
||||
}
|
||||
}
|
||||
/* full circle 1/2 */
|
||||
case 2: {
|
||||
int kind = rand() % 2;
|
||||
for (int i = 0 ; i < 10 ; i++) {
|
||||
if ((i & 1) == kind) { continue; }
|
||||
p2.face = i;
|
||||
level->platform_buffer.push_back(p2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* 3 faces, 1 empty, 5 faces */
|
||||
case 3: {
|
||||
int toggle_len = rand() % 2;
|
||||
p2.face = p1.face;
|
||||
for (int i = 0 ; i < 3 ; i++) {
|
||||
p2.length = (toggle_len) ? PLATFORM_LEN_LONG : PLATFORM_LEN_SHORT;
|
||||
level->platform_buffer.push_back(p2);
|
||||
p2.face = (p2.face + 1) % PLATFORM_COUNT;
|
||||
}
|
||||
p2.face = (p2.face + 1) % PLATFORM_COUNT;
|
||||
for (int i = 0 ; i < 5 ; i++) {
|
||||
level->platform_buffer.push_back(p2);
|
||||
p2.face = (p2.face + 1) % PLATFORM_COUNT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
m_last_z += SECTION_LENGTH;
|
||||
/* 1 face, 1 empty, 1 face, 1 emtpy, 1 face */
|
||||
case 4:
|
||||
//TODO : height
|
||||
level->platform_buffer.push_back(p2);
|
||||
p2.face = add_to_face(p2.face, -2);
|
||||
level->platform_buffer.push_back(p2);
|
||||
p2.face = add_to_face(p2.face, 4);
|
||||
level->platform_buffer.push_back(p2);
|
||||
break;
|
||||
|
||||
/* foce 1 face */
|
||||
default:
|
||||
level->platform_buffer.push_back(p1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ using namespace libnum;
|
|||
#define SECTION_LENGTH num(3.0)
|
||||
/* Number of platforms in the world cylinder. */
|
||||
#define PLATFORM_COUNT 10
|
||||
/* Platforms len information, in word units */
|
||||
#define PLATFORM_LEN_LONG num(3.0)
|
||||
#define PLATFORM_LEN_SHORT num(1)
|
||||
/* 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)
|
||||
|
|
Loading…
Reference in New Issue