diff --git a/inc/BackGround.hpp b/inc/BackGround.hpp index 717778b..2c10091 100644 --- a/inc/BackGround.hpp +++ b/inc/BackGround.hpp @@ -13,8 +13,7 @@ public: private: void starts(); void moon(); - void mounten(); - void drawMounten(int line, int varience, Color color); + void mounten(size_t mountenSegments, float scale, int min, int max, Color color); int size = 0; Texture2D texShapes = {1, 1, 1, 1, 7}; @@ -27,8 +26,7 @@ private: Color moonColor = {240, 240, 190, 255}; int minSizeOfMoon = 40; int maxSizeOfMoon = 60; + int maxYPosOfMoon = 600; Color mountenColor = {28, 28, 38, 255}; - size_t mountenDataCap = 20; - std::vector mountenData; }; diff --git a/src/BackGround.cpp b/src/BackGround.cpp index 8eec891..3ed5cac 100644 --- a/src/BackGround.cpp +++ b/src/BackGround.cpp @@ -3,13 +3,13 @@ #include "raylib.h" #include "rlgl.h" +#include "raymath.h" #include "external/stb_perlin.h" // Public void BackGround::init(int size) { this->size = size; - mountenData.assign(mountenDataCap, 0); } void BackGround::newGen() @@ -17,7 +17,9 @@ void BackGround::newGen() ClearBackground(backGroundColor); starts(); moon(); - mounten(); + mounten(20, 0.3, 550, 650, mountenColor); + mounten(21, 0.3, 650, 730, ColorLerp(mountenColor, BLACK, 0.1f)); + mounten(23, 0.3, 730, 780, ColorLerp(mountenColor, BLACK, 0.3f)); } void BackGround::starts() @@ -66,58 +68,46 @@ void BackGround::moon() DrawCircle(xpos, ypos, r, moonColor); } -void BackGround::mounten() +void BackGround::mounten(size_t mountenSegments, float scale, int min, int max, Color color) { - int len = 20; + // get random offset in the perlin noise int offsetX = GetRandomValue(20, 1000); int offsetY = GetRandomValue(20, 1000); - float sc = (4 / (float)len); - for (size_t i = 0; i < mountenData.size(); i++) - { - float nx = (float)(i + offsetX) * sc; - float p = stb_perlin_fbm_noise3(nx, offsetY, 1.0f, 2.0f, 0.5f, 6); - if (p < -1.0f) - p = -1.0f; - if (p > 1.0f) - p = 1.0f; - - // mountenData[i] = (p + 1.0f) / 2.0f; - mountenData[i] = p; - } - drawMounten(600, 100, mountenColor); -} - -void BackGround::drawMounten(int line, int varience, Color color) -{ int x = 0; - int diff = size / (mountenData.size() - 1); + int diff = size / (mountenSegments - 1); + + float nx = (float)offsetX * scale; + float p = stb_perlin_fbm_noise3(nx, offsetY, 1.0f, 2.0f, 0.5f, 6); + p = (p + 1.0f) / 2.0f; + int y = Lerp(min, max, p); rlSetTexture(texShapes.id); rlBegin(RL_QUADS); rlNormal3f(0.0f, 0.0f, 1.0f); rlColor4ub(color.r, color.g, color.b, color.a); - int pervY = line + (mountenData[0] * varience); - - for (size_t i = 1; i <= mountenData.size(); i++) + for (size_t i = 1; i <= mountenSegments; i++) { // topLeft rlTexCoord2f(0, 0); - rlVertex2f(x, pervY); + rlVertex2f(x, y); // bottomLeft rlTexCoord2f(0, 1); rlVertex2f(x, size); + nx = (float)(i + offsetX) * scale; + p = stb_perlin_fbm_noise3(nx, offsetY, 1.0f, 2.0f, 0.5f, 6); + p = (p + 1.0f) / 2.0f; + y = Lerp(min, max, p); x += diff; - pervY = line + (mountenData[i] * varience); // bottomRight rlTexCoord2f(1, 1); rlVertex2f(x, size); // topRight rlTexCoord2f(1, 0); - rlVertex2f(x, pervY); + rlVertex2f(x, y); } rlEnd(); rlSetTexture(0);