diff --git a/.gitignore b/.gitignore index fe36473..889a8e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ main obj/ +rl/ raylib/ \ No newline at end of file diff --git a/Makefile b/Makefile index 760a355..7d09d44 100644 --- a/Makefile +++ b/Makefile @@ -1,42 +1,46 @@ RAYFLAGS= -D_GNU_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33 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= -ggdb -all: setup main run +all: clean setup main run setup: if [ ! -d "raylib" ]; then \ git clone --depth 1 --branch "5.0" git@github.com:raysan5/raylib.git; \ + rm -rf raylib/.git; \ fi if [ ! -d "obj" ]; then \ mkdir -p obj; \ + fi + if [ ! -d "rl" ]; then \ + mkdir -p rl; \ fi -obj/rcore.o: raylib/src/rcore.c +rl/rcore.o: raylib/src/rcore.c 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) -obj/rtextures.o: raylib/src/rtextures.c +rl/rtextures.o: raylib/src/rtextures.c 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) -obj/utils.o: raylib/src/utils.c +rl/utils.o: raylib/src/utils.c 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) -obj/rmodels.o: raylib/src/rmodels.c +rl/rmodels.o: raylib/src/rmodels.c 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) SRCDIR = src diff --git a/inc/BackGround.hpp b/inc/BackGround.hpp index 5b8a494..717778b 100644 --- a/inc/BackGround.hpp +++ b/inc/BackGround.hpp @@ -12,11 +12,23 @@ public: private: void starts(); + void moon(); void mounten(); - void drawMounten(std::vector &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; 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 mountenData; }; diff --git a/src/BackGround.cpp b/src/BackGround.cpp index 08acb87..99d2f35 100644 --- a/src/BackGround.cpp +++ b/src/BackGround.cpp @@ -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 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 &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 &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);