BosonX/src/level.cpp

79 lines
1.9 KiB
C++
Raw Permalink Normal View History

2022-08-20 16:32:37 +02:00
#include "level.h"
#include "generator.h"
#include "util.h"
2022-08-20 15:06:19 +02:00
#include <gint/display.h>
2023-08-02 18:37:03 +02:00
#include <algorithm>
2022-08-20 15:06:19 +02:00
2023-05-24 13:08:59 +02:00
struct level level_create(int level)
2022-08-20 15:06:19 +02:00
{
2023-05-24 13:08:59 +02:00
struct level l;
switch(level) {
default:
2023-06-15 20:22:33 +02:00
l.name = "geon";
l.gen = std::make_unique<GeonGenerator>();
l.bgcolor = RGB24(0x49759f);
break;
2023-05-24 13:08:59 +02:00
case 2:
2023-06-15 20:22:33 +02:00
l.name = "acceleron";
l.gen = std::make_unique<AcceleronGenerator>();
l.bgcolor = RGB24(0xe7c272);
2023-05-24 13:08:59 +02:00
break;
case 3:
2023-06-15 20:22:33 +02:00
l.name = "radion";
2023-08-03 08:21:20 +02:00
l.gen = std::make_unique<RadionGenerator>();
l.bgcolor = RGB24(0xe17c6a);
2023-05-24 13:08:59 +02:00
break;
}
return l;
2022-08-20 15:06:19 +02:00
}
2023-08-02 18:37:03 +02:00
static int local_depth(struct platform const &p)
{
if(p.type == PLATFORM_BLOCK)
return 0;
else if(p.type == PLATFORM_BLOCK_TOP)
return 2;
else
return 1;
}
static int relative_distance(struct platform const &p, int face)
{
int d = abs(p.face - face) % PLATFORM_COUNT;
return (d <= PLATFORM_COUNT / 2) ? d : PLATFORM_COUNT - d;
}
/* Hack */
static int reference_face = 0;
static bool compare_platforms(struct platform const &p1,
struct platform const &p2)
{
if(p1.z != p2.z)
return p1.z < p2.z;
int d1 = local_depth(p1);
int d2 = local_depth(p2);
if(d1 != d2)
return d1 < d2;
int rd1 = relative_distance(p1, reference_face);
int rd2 = relative_distance(p2, reference_face);
return rd1 < rd2;
}
void level_update(struct level *level, num z, int face)
2022-08-20 15:06:19 +02:00
{
2023-05-24 13:08:59 +02:00
while(!level->platform_buffer.size()
|| level->platform_buffer[level->platform_buffer.size() - 1].z
< z + RENDER_DEPTH)
level->gen->generate(level);
2023-08-02 18:37:03 +02:00
reference_face = face;
std::stable_sort(level->platform_buffer.begin(),
level->platform_buffer.end(),
compare_platforms);
2022-08-20 15:06:19 +02:00
}