Add moon to backGround
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "BackGround.hpp"
|
||||
#include "Math.hpp"
|
||||
|
||||
#include "raylib.h"
|
||||
#include "rlgl.h"
|
||||
#include "external/stb_perlin.h"
|
||||
@@ -7,13 +9,15 @@
|
||||
void BackGround::init(int size)
|
||||
{
|
||||
this->size = size;
|
||||
mountenData.assign(mountenDataCap, 0);
|
||||
}
|
||||
|
||||
void BackGround::newGen()
|
||||
{
|
||||
ClearBackground({21, 34, 56, 255});
|
||||
ClearBackground(backGroundColor);
|
||||
starts();
|
||||
// mounten();
|
||||
moon();
|
||||
mounten();
|
||||
}
|
||||
|
||||
void BackGround::starts()
|
||||
@@ -49,43 +53,52 @@ void BackGround::starts()
|
||||
rlSetTexture(0);
|
||||
}
|
||||
|
||||
void BackGround::moon()
|
||||
{
|
||||
int xpos = GetRandomValue(100, size - 100);
|
||||
int ypos = GetRandomValue(100, 300);
|
||||
int r = GetRandomValue(minSizeOfMoon, maxSizeOfMoon);
|
||||
|
||||
DrawCircle(xpos, ypos, r + 20, ColorLerp(backGroundColor, moonColor, 0.02f));
|
||||
DrawCircle(xpos, ypos, r + 10, ColorLerp(backGroundColor, moonColor, 0.05f));
|
||||
DrawCircle(xpos, ypos, r, moonColor);
|
||||
}
|
||||
|
||||
void BackGround::mounten()
|
||||
{
|
||||
int len = 20;
|
||||
int offsetX = GetRandomValue(20, 1000);
|
||||
int offsetY = GetRandomValue(20, 1000);
|
||||
float scale = 1;
|
||||
float sc = (4 / (float)len);
|
||||
|
||||
std::vector<float> data(len);
|
||||
for (size_t i = 0; i < data.size(); i++)
|
||||
for (size_t i = 0; i < mountenData.size(); i++)
|
||||
{
|
||||
float nx = (float)(i + offsetX) * (scale / (float)len);
|
||||
float ny = (float)(offsetY) * (scale / (float)1);
|
||||
|
||||
float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6);
|
||||
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;
|
||||
|
||||
data[i] = p;
|
||||
// mountenData[i] = (p + 1.0f) / 2.0f;
|
||||
mountenData[i] = p;
|
||||
}
|
||||
drawMounten(data, 500, 100, DARKBLUE);
|
||||
drawMounten(600, 100, mountenColor);
|
||||
}
|
||||
|
||||
void BackGround::drawMounten(std::vector<float> &data, int line, int varience, Color color)
|
||||
void BackGround::drawMounten(int line, int varience, Color color)
|
||||
{
|
||||
int x = 0;
|
||||
int diff = size / (data.size() - 1);
|
||||
int diff = size / (mountenData.size() - 1);
|
||||
|
||||
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 + (data[0] * varience);
|
||||
int pervY = line + (mountenData[0] * varience);
|
||||
|
||||
for (size_t i = 1; i <= data.size(); i++)
|
||||
for (size_t i = 1; i <= mountenData.size(); i++)
|
||||
{
|
||||
// topLeft
|
||||
rlTexCoord2f(0, 0);
|
||||
@@ -95,7 +108,7 @@ void BackGround::drawMounten(std::vector<float> &data, int line, int varience, C
|
||||
rlVertex2f(x, size);
|
||||
|
||||
x += diff;
|
||||
pervY = line + (data[i] * varience);
|
||||
pervY = line + (mountenData[i] * varience);
|
||||
|
||||
// bottomRight
|
||||
rlTexCoord2f(1, 1);
|
||||
|
||||
Reference in New Issue
Block a user