|
|
|
@ -1,4 +1,6 @@
@@ -1,4 +1,6 @@
|
|
|
|
|
#include "environment.h" |
|
|
|
|
#include "draw.h" |
|
|
|
|
|
|
|
|
|
double linear_interpolate(double a0, double a1, double w) { |
|
|
|
|
return (1.0f - w) * a0 + w * a1; |
|
|
|
|
} |
|
|
|
@ -33,8 +35,30 @@ double perlin(Vect coordinate) {
@@ -33,8 +35,30 @@ double perlin(Vect coordinate) {
|
|
|
|
|
return linear_interpolate(ix0, ix1, sy); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ArrayList get_colours(int seed) { |
|
|
|
|
|
|
|
|
|
struct colour_pallete get_pallete (int seed) { |
|
|
|
|
struct colour base = get_random_color(seed); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct colour c1 = get_hsv(base); |
|
|
|
|
c1 = get_hsv(base); |
|
|
|
|
struct colour_pallete cols; |
|
|
|
|
|
|
|
|
|
c1.l = 0.1; |
|
|
|
|
cols.bg = get_rgb(c1); |
|
|
|
|
c1.l += 0.3; |
|
|
|
|
|
|
|
|
|
c1.h += 30; |
|
|
|
|
cols.fg1 = get_rgb(c1); |
|
|
|
|
|
|
|
|
|
c1.h += 30; |
|
|
|
|
cols.fg2 = get_rgb(c1); |
|
|
|
|
|
|
|
|
|
c1.h += 30; |
|
|
|
|
cols.fg3 = get_rgb(c1); |
|
|
|
|
|
|
|
|
|
return cols; |
|
|
|
|
|
|
|
|
|
struct colour *adj = get_adjacent(base, 20, 4); |
|
|
|
|
ArrayList l = new_arlst_wfree(4, free); |
|
|
|
|
|
|
|
|
@ -42,7 +66,10 @@ ArrayList get_colours(int seed) {
@@ -42,7 +66,10 @@ ArrayList get_colours(int seed) {
|
|
|
|
|
arlst_add(&l, adj + i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return l; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int comp(const void *one, const void *two) { |
|
|
|
|
return *(int*)one > *(int*)two; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct environment get_scene_at(Vect coordinate, int seed) { |
|
|
|
@ -63,19 +90,64 @@ struct environment get_scene_at(Vect coordinate, int seed) {
@@ -63,19 +90,64 @@ struct environment get_scene_at(Vect coordinate, int seed) {
|
|
|
|
|
e.ceil = new_arlst_wfree(E_ROOM_TILES, free); |
|
|
|
|
e.bg1 = new_arlst_wfree(E_ROOM_TILES, free); |
|
|
|
|
e.bg2 = new_arlst_wfree(E_ROOM_TILES, free); |
|
|
|
|
e.colours = get_colours(seed); |
|
|
|
|
|
|
|
|
|
e.colours = get_pallete(seed); |
|
|
|
|
|
|
|
|
|
Vect bit; |
|
|
|
|
bit.y = 100 * seed; |
|
|
|
|
Vect pos; |
|
|
|
|
|
|
|
|
|
srand(seed); |
|
|
|
|
|
|
|
|
|
Vect node; |
|
|
|
|
node.y = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < E_ROOM_WIDTH; i += E_ROOM_RES) { |
|
|
|
|
bit.x = room_coord.x + i; |
|
|
|
|
double *z = malloc(sizeof(double)); |
|
|
|
|
*z = perlin(bit); |
|
|
|
|
bit.y = seed; |
|
|
|
|
node.x = bit.x; |
|
|
|
|
|
|
|
|
|
int r1 = 1.5*(rand() % 500) - (rand() % 100); |
|
|
|
|
int r2 = 1.5*(rand() % 200) - (rand() % 200); |
|
|
|
|
int r3 = (rand() % 100) - (rand() % 500); |
|
|
|
|
int r4 = 50; |
|
|
|
|
|
|
|
|
|
int r[4] = {r1, r2, r3, r4}; |
|
|
|
|
qsort(r, 4, sizeof(int), comp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node.y += r[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// node.y = fmod(perlin(bit), 3000);
|
|
|
|
|
Vect *z = malloc(sizeof(Vect)); |
|
|
|
|
*z = node; |
|
|
|
|
printf("%f %f\n", bit.x, z->y); |
|
|
|
|
|
|
|
|
|
arlst_add(&e.floor, z); |
|
|
|
|
arlst_add(&e.ceil, z + 90); |
|
|
|
|
arlst_add(&e.bg1, z + 20); |
|
|
|
|
arlst_add(&e.bg2, z + 70); |
|
|
|
|
|
|
|
|
|
z = malloc(sizeof(Vect)); |
|
|
|
|
*z = node; |
|
|
|
|
z->y += r[1]; |
|
|
|
|
printf("%f %f\n", bit.x, z->y); |
|
|
|
|
|
|
|
|
|
arlst_add(&e.bg1, z); |
|
|
|
|
|
|
|
|
|
z = malloc(sizeof(Vect)); |
|
|
|
|
*z = node; |
|
|
|
|
z->y += r[2]; |
|
|
|
|
printf("%f %f\n", bit.x, z->y); |
|
|
|
|
arlst_add(&e.bg2, z); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
z = malloc(sizeof(Vect)); |
|
|
|
|
*z = node; |
|
|
|
|
z->y += r[3]; |
|
|
|
|
printf("%f %f\n", bit.x, z->y); |
|
|
|
|
|
|
|
|
|
arlst_add(&e.ceil, z); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
init = true; |
|
|
|
|
|
|
|
|
|