platform colors and generator updates

This commit is contained in:
Lephenixnoir 2022-08-24 20:40:21 +02:00
parent c4147de174
commit 6cf0b59913
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 52 additions and 23 deletions

View File

@ -1,20 +1,32 @@
#include "../generator.h"
#include "../level.h"
gen1::gen1() : last_pos{0} { }
gen1::gen1() : last_pos{0}
{
srand(0xc0ffee);
}
void gen1::generate(level_t *level)
{
struct section section;
int r = rand() % 3;
this->last_pos += 1;
this->last_pos %= PLATFORM_COUNT;
for (int i = 0; i < PLATFORM_COUNT; ++i) {
section.platforms[i].type = PLATFORM_EMPTY;
if (i == this->last_pos)
if(r == 0) {
for(int i = 0; i < PLATFORM_COUNT; i++)
section.platforms[i].type = PLATFORM_WHITE;
}
else if(r == 1) {
for(int i = 0; i < PLATFORM_COUNT; i++) {
auto t = (i % 2) ? PLATFORM_WHITE : PLATFORM_EMPTY;
section.platforms[i].type = t;
}
}
else if(r == 2) {
for(int i = 0; i < PLATFORM_COUNT; i++) {
auto t = (i % 2) ? PLATFORM_EMPTY : PLATFORM_WHITE;
section.platforms[i].type = t;
}
}
level->section_buffer.push_back(section);
}

View File

@ -16,9 +16,11 @@ void gen2::generate(level_t *level)
this->last_pos = 0;
for (int i = 0; i < PLATFORM_COUNT; ++i) {
section.platforms[i].type = PLATFORM_EMPTY;
if (i == this->last_pos)
section.platforms[i].type = PLATFORM_WHITE;
else
section.platforms[i].type =
(rand() % 2) ? PLATFORM_EMPTY : PLATFORM_WHITE;
}
level->section_buffer.push_back(section);

View File

@ -81,15 +81,20 @@ int main(void)
for(int i = 0; i < PLATFORM_COUNT; i++) {
/* Set this to get the full tunnel test */
constexpr bool full_tunnel = false;
/* Set this to get the OG full tunnel coloring */
constexpr bool og_coloring = false;
int color = C_WHITE;
if(full_tunnel) {
if(!full_tunnel && s->platforms[i].type != PLATFORM_WHITE)
continue;
if(og_coloring) {
int gray = ((i + depth + sections_passed) % PLATFORM_COUNT)
* 31 / PLATFORM_COUNT;
color = C_RGB(gray, gray, gray);
}
else {
if(s->platforms[i].type != PLATFORM_WHITE) continue;
color = camera_platform_color(&camera, i);
}
struct prect p = render_platform_position(i, z);

View File

@ -136,17 +136,6 @@ void camera_set_angle(struct camera *camera, num angle)
camera->_angle_rotation = vec2(num_cos(angle), num_sin(angle));
}
static num cubic(num t)
{
if(t <= 0.5) {
return 4 * t * t * t;
}
else {
t = num(1) - t;
return num(1) - 4 * t * t * t;
}
}
num camera_compute_platform_angle(struct camera *camera)
{
num arc = render_platform_arc();
@ -158,6 +147,24 @@ num camera_compute_platform_angle(struct camera *camera)
return a;
}
int camera_platform_color(struct camera *camera, int platform_id)
{
/* Accounting for the full angle is too precise and results in weird
color jumps at different times across platforms, instead switch at half
movement. Instead just count entire platforms. */
int down = camera->platform;
if(camera->rot_direction && camera->rot_t >= CAMERA_ROTATION_DURATION / 2)
down += camera->rot_direction;
int dist = platform_id - down;
if(dist < 0)
dist += PLATFORM_COUNT;
dist = std::min(dist, PLATFORM_COUNT - dist);
int gray = 31 - 2 * dist;
return C_RGB(gray, gray, gray);
}
void render_triangle(vec3 *p1, vec3 *p2, vec3 *p3, int color)
{
azrp_triangle(

View File

@ -6,12 +6,12 @@
using namespace libnum;
/* Vertical FOV, in degrees */
#define RENDER_FOV 120.0
#define RENDER_FOV 150.0
/* Radius of the level cylinder, in world units */
#define RENDER_RADIUS num(4.0)
/* Camera depth in the level cylinder, in world units, should be between 0
and RENDER_RADIUS */
#define RENDER_CAMERA_DEPTH num(2.3)
#define RENDER_CAMERA_DEPTH num(2.9)
/* Section lengths, in world units */
#define RENDER_SECTION_LENGTH num(4.0)
/* Number of sections visible in advance */
@ -65,6 +65,9 @@ void camera_set_angle(struct camera *camera, num angle);
/* Compute the camera's viewing angle based on its platform position. */
num camera_compute_platform_angle(struct camera *camera);
/* Compute the platform's color based on the camera's angle. */
int camera_platform_color(struct camera *camera, int platform_id);
/* Queue an Azur command to render the triangle defined by p1/p2/p3. Only the
x/y coordinates are used, z is ignored. */
void render_triangle(vec3 *p1, vec3 *p2, vec3 *p3, int color);