Add moon to backGround
This commit is contained in:
parent
e6f102266c
commit
2d67f41ab1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
main
|
main
|
||||||
obj/
|
obj/
|
||||||
|
rl/
|
||||||
raylib/
|
raylib/
|
24
Makefile
24
Makefile
@ -1,42 +1,46 @@
|
|||||||
RAYFLAGS= -D_GNU_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33
|
RAYFLAGS= -D_GNU_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33
|
||||||
RAYINCLUDE= -Iraylib/src -Iraylib/src/external/glfw/include -Iraylib/src/external/glfw/deps/mingw
|
RAYINCLUDE= -Iraylib/src -Iraylib/src/external/glfw/include -Iraylib/src/external/glfw/deps/mingw
|
||||||
RAYOBJECTS= obj/rcore.o obj/rshapes.o obj/rtextures.o obj/rtext.o obj/utils.o obj/rglfw.o obj/rmodels.o obj/raudio.o
|
RAYOBJECTS= rl/rcore.o rl/rshapes.o rl/rtextures.o rl/rtext.o rl/utils.o rl/rglfw.o rl/rmodels.o rl/raudio.o
|
||||||
|
|
||||||
#RAYOPT= -O3
|
#RAYOPT= -O3
|
||||||
RAYOPT= -ggdb
|
RAYOPT= -ggdb
|
||||||
|
|
||||||
all: setup main run
|
all: clean setup main run
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
if [ ! -d "raylib" ]; then \
|
if [ ! -d "raylib" ]; then \
|
||||||
git clone --depth 1 --branch "5.0" git@github.com:raysan5/raylib.git; \
|
git clone --depth 1 --branch "5.0" git@github.com:raysan5/raylib.git; \
|
||||||
|
rm -rf raylib/.git; \
|
||||||
fi
|
fi
|
||||||
if [ ! -d "obj" ]; then \
|
if [ ! -d "obj" ]; then \
|
||||||
mkdir -p obj; \
|
mkdir -p obj; \
|
||||||
|
fi
|
||||||
|
if [ ! -d "rl" ]; then \
|
||||||
|
mkdir -p rl; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
obj/rcore.o: raylib/src/rcore.c
|
rl/rcore.o: raylib/src/rcore.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
obj/rshapes.o: raylib/src/rshapes.c
|
rl/rshapes.o: raylib/src/rshapes.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
obj/rtextures.o: raylib/src/rtextures.c
|
rl/rtextures.o: raylib/src/rtextures.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
obj/rtext.o: raylib/src/rtext.c
|
rl/rtext.o: raylib/src/rtext.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
obj/utils.o: raylib/src/utils.c
|
rl/utils.o: raylib/src/utils.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
obj/rglfw.o: raylib/src/rglfw.c
|
rl/rglfw.o: raylib/src/rglfw.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
obj/rmodels.o: raylib/src/rmodels.c
|
rl/rmodels.o: raylib/src/rmodels.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
obj/raudio.o: raylib/src/raudio.c
|
rl/raudio.o: raylib/src/raudio.c
|
||||||
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE)
|
||||||
|
|
||||||
SRCDIR = src
|
SRCDIR = src
|
||||||
|
@ -12,11 +12,23 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void starts();
|
void starts();
|
||||||
|
void moon();
|
||||||
void mounten();
|
void mounten();
|
||||||
void drawMounten(std::vector<float> &data, int line, int varience, Color color);
|
void drawMounten(int line, int varience, Color color);
|
||||||
|
|
||||||
|
int size = 0;
|
||||||
|
Texture2D texShapes = {1, 1, 1, 1, 7};
|
||||||
|
|
||||||
|
Color backGroundColor = {21, 34, 56, 255};
|
||||||
|
|
||||||
size_t numOfStarts = 150;
|
size_t numOfStarts = 150;
|
||||||
Color starColor = WHITE;
|
Color starColor = WHITE;
|
||||||
int size = 0;
|
|
||||||
Texture2D texShapes = {1, 1, 1, 1, 7};
|
Color moonColor = {240, 240, 190, 255};
|
||||||
|
int minSizeOfMoon = 40;
|
||||||
|
int maxSizeOfMoon = 60;
|
||||||
|
|
||||||
|
Color mountenColor = {28, 28, 38, 255};
|
||||||
|
size_t mountenDataCap = 20;
|
||||||
|
std::vector<float> mountenData;
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "BackGround.hpp"
|
#include "BackGround.hpp"
|
||||||
|
#include "Math.hpp"
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "rlgl.h"
|
#include "rlgl.h"
|
||||||
#include "external/stb_perlin.h"
|
#include "external/stb_perlin.h"
|
||||||
@ -7,13 +9,15 @@
|
|||||||
void BackGround::init(int size)
|
void BackGround::init(int size)
|
||||||
{
|
{
|
||||||
this->size = size;
|
this->size = size;
|
||||||
|
mountenData.assign(mountenDataCap, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackGround::newGen()
|
void BackGround::newGen()
|
||||||
{
|
{
|
||||||
ClearBackground({21, 34, 56, 255});
|
ClearBackground(backGroundColor);
|
||||||
starts();
|
starts();
|
||||||
// mounten();
|
moon();
|
||||||
|
mounten();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackGround::starts()
|
void BackGround::starts()
|
||||||
@ -49,43 +53,52 @@ void BackGround::starts()
|
|||||||
rlSetTexture(0);
|
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()
|
void BackGround::mounten()
|
||||||
{
|
{
|
||||||
int len = 20;
|
int len = 20;
|
||||||
int offsetX = GetRandomValue(20, 1000);
|
int offsetX = GetRandomValue(20, 1000);
|
||||||
int offsetY = 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 < mountenData.size(); i++)
|
||||||
for (size_t i = 0; i < data.size(); i++)
|
|
||||||
{
|
{
|
||||||
float nx = (float)(i + offsetX) * (scale / (float)len);
|
float nx = (float)(i + offsetX) * sc;
|
||||||
float ny = (float)(offsetY) * (scale / (float)1);
|
float p = stb_perlin_fbm_noise3(nx, offsetY, 1.0f, 2.0f, 0.5f, 6);
|
||||||
|
|
||||||
float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6);
|
|
||||||
if (p < -1.0f)
|
if (p < -1.0f)
|
||||||
p = -1.0f;
|
p = -1.0f;
|
||||||
if (p > 1.0f)
|
if (p > 1.0f)
|
||||||
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 x = 0;
|
||||||
int diff = size / (data.size() - 1);
|
int diff = size / (mountenData.size() - 1);
|
||||||
|
|
||||||
rlSetTexture(texShapes.id);
|
rlSetTexture(texShapes.id);
|
||||||
rlBegin(RL_QUADS);
|
rlBegin(RL_QUADS);
|
||||||
rlNormal3f(0.0f, 0.0f, 1.0f);
|
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
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
|
// topLeft
|
||||||
rlTexCoord2f(0, 0);
|
rlTexCoord2f(0, 0);
|
||||||
@ -95,7 +108,7 @@ void BackGround::drawMounten(std::vector<float> &data, int line, int varience, C
|
|||||||
rlVertex2f(x, size);
|
rlVertex2f(x, size);
|
||||||
|
|
||||||
x += diff;
|
x += diff;
|
||||||
pervY = line + (data[i] * varience);
|
pervY = line + (mountenData[i] * varience);
|
||||||
|
|
||||||
// bottomRight
|
// bottomRight
|
||||||
rlTexCoord2f(1, 1);
|
rlTexCoord2f(1, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user