BosonX/src/level.cpp

60 lines
1.1 KiB
C++
Raw Normal View History

2022-08-20 16:32:37 +02:00
#include "level.h"
#include "generator.h"
2022-08-20 15:06:19 +02:00
#include <gint/display.h>
level_t level_create(int level)
{
level_t l;
switch(level) {
2022-08-20 16:32:37 +02:00
case 2:
l.gen = std::make_unique<struct gen2>();
break;
case 3:
l.gen = std::make_unique<struct gen3>();
break;
2022-08-20 15:06:19 +02:00
default:
l.gen = std::make_unique<struct gen1>();
}
return l;
}
void level_update(level_t *level)
{
while (level->section_buffer.size() < LEVEL_BUFFER_LENGTH) {
2022-08-20 15:06:19 +02:00
level->gen->generate(level);
}
}
void level_advance(level_t *level)
{
if(level->section_buffer.size())
level->section_buffer.erase(level->section_buffer.begin());
2022-08-20 15:06:19 +02:00
}
void level_display(level_t *level)
{
int w;
int h;
int sx;
int sy;
dsize("@", NULL, &w, &h);
sx = (DWIDTH - (PLATFORM_COUNT * w)) / 2;
sy = (DHEIGHT - (LEVEL_BUFFER_LENGTH * h)) / 2;
2022-08-20 16:32:37 +02:00
drect_border(
sx, sy,
sx + (PLATFORM_COUNT * w), sy + (LEVEL_BUFFER_LENGTH * h),
2022-08-20 16:32:37 +02:00
C_NONE, 2, C_BLACK
);
2022-08-20 15:06:19 +02:00
for (int i = 4; i >= 0; --i) {
for (int j = 0; j < PLATFORM_COUNT; ++j) {
if (level->section_buffer[i].platforms[j].type != PLATFORM_EMPTY)
dtext(sx + (w * j), sy + (h * i), C_BLACK, "@");
}
}
}