From 001cbb9141ecd8e1f3f6f63b4c5765cb87eff4a2 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Wed, 28 Sep 2022 22:55:07 -0400 Subject: [PATCH] cooler chunk generation --- res/image/sand.png | Bin 0 -> 1201 bytes res/image/snow.png | Bin 0 -> 5087 bytes res/image/stone.png | Bin 0 -> 5294 bytes res/image/water.png | Bin 0 -> 942 bytes res/shaders/simple_shader.frag | 2 +- src/chunk.cpp | 44 +++++++++++++++++++++------------ src/chunk.hpp | 12 +++++++++ src/first_app.cpp | 6 ++--- 8 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 res/image/sand.png create mode 100644 res/image/snow.png create mode 100644 res/image/stone.png create mode 100644 res/image/water.png diff --git a/res/image/sand.png b/res/image/sand.png new file mode 100644 index 0000000000000000000000000000000000000000..b82eacadf73a752cbe5d9f7330144a2ab8abb08a GIT binary patch literal 1201 zcmV;i1Wx;jP)EX>4Tx04R}tkv&MmKpe$iQ^gM|4t5Yx$WWauh)QwPDionYs1;guFuC*#nlvOS zE{=k0!NHHks)LKOt`4q(Aou~|=;Wm6A|?JWDYS_3;J6>}?mh0_0YbgZG^=9*&~)2O zCE{WxyDE0Qq6Z@o5JXI7mN6$uN%)Shdj$A;7v)+0=l&dhYR+OnKqQ`JhG`RT5XUxc zgY!Odm=$G}_?&p$qze*1a$WKGjdQ_efoF!zbZVYBOe_}KSZQNcG&SOB;)ts0lrLmF zRyl8R*2-1ZyeEHQD5tM1bDice5?I6%B#2N@MG0lth|;Q)Vj)HQaUcJX>zBx-kgEhn zjs;YpL3aJ%fAG6oD?c^qC57TZ=ZoWfi~?P|K%?e3-^Y&AI01ssz?I(eSL(pbC+W48 z7C8d?w}Ff6mZt0hmpj1VlOdb3D+Or^`8@D`M&FbL25y1gHLthkK29HiGxhU`@Flmy|;hQH2eDjVUBX3bhL4_00009a7bBm000XU000XU0RWnu7ytkO2XskI zMF-{y9Rdq65(Ki70008ONklc-d0D$3NXVH-?*_Pvkq(IY5Zy1L1#_%va z0K*MT%MDOUn514}*;>!a4c|L_+54Y=NM*4=2tka2d7eR7thE?psF$zsc0`(*X=;hV zQq^0=u_yWgu~;lnN@4N^Aw975Rp=`Twal@5S~1wF`={s z83<{lt_zgb_z)0Ma(MoeRkI@OEK22QWk@OEyk#6GRBz8rz9*MCnUrKnU`)l_T~JE# z@^V5bi8G$MS|Wr(ON~;Rm-dJ%ih|@5MlA^f7CNDnW>YIfrntSiL*yALMf{xbZsO7( z*)&^hJk#8K%kK09+B5l%ZXA$CaDBa{u9u9iV+t2cX>f67vIEN5K$HqU z_dNae6XV!33>_f`GC3p2*zXUliY;$mf62K!5avWC1i7jab-f^onP$@hV%JC zRnQih`7c>b5qyFKgmikK4pF!0UW z?>V(C&1#Lcmf7_Pnc@A6$xCErP~LgGbreP;guv(uH_a%OVZ%V%ACM-p-ybL!hE>(z zCX00~g{crRIaHpJks(#i?br9{Leuv>QW#93(Rqo^_5VX7Qe{Y$VO`IE`vG`7iWSP1 P00000NkvXXu0mjf&IB+M literal 0 HcmV?d00001 diff --git a/res/image/snow.png b/res/image/snow.png new file mode 100644 index 0000000000000000000000000000000000000000..f8f1fa626716e98b459612a8d4caf3f301909bf7 GIT binary patch literal 5087 zcmeHKdr%Yi77mCYFQH&7we=d8hlqx}pAcRNNGw5+fY_I8HXB&Ui)4X-MFA^f5zs19 z6}c*i2qL#iOEGW-G)k?aRz+Le=%lD1t)liSLId3dM4a21JI>txXJ(S@p2v62`F`h| zWH-e`FL8F5rM)8%Xa>wyqXUu4X_{;@GX zQ-|ldu!J1dr53BwV#d;Z*Met)w%Z*~GM~Ke_OA*In#*l+2p>tJN!=^!hDZvvOxoLkvB)#Dk3=cpPjY4n%kU5t}Nzelp1P zr10a|Au_NHr0%6hNO3heVLqXSDSDg!x+7^R#Se?fHobn)H{A1T8MRN;-so1<@e6SadpztEF#=VwcjbsEHgDJ7GoY={ ztpD8ZaK1NFva-Hwo^qPn_fTwoU38mm@ve%rooRMD)4}o4(?21gX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DW2?2y9ECM8k zsUVd}l1gZ_DGnJg62NO04#E>77kAh zgQ!w1QYvL!z?>4^>^Z3xV&fzMQIHR!Fa}DZP&gzuhr$w>FBlvulR%U5=5Hy zzpTx}gAW`(@<>F3#m};c#wRKcP8+`)zm*}DQNrUbL%{)|@e(v(1}w4UiD8YapcGJ% z3}f44qFtZMk-umKHV85$Vm6yVWwICq8Uv;g#B3IwAf=KS5)wnqrcaPJiLOyf(M(Vc zhbCh@Vq9VEY2ga*YdNTeFXxh(0-H|(BaA>|6J8L;njnlgQ83ZGGoDu*Nc=BO0xbqp zmJH@MF2j}=whM`q%W#4-EZ@KLHE|YyX9zt0b&yx$_cdLw>3SswUdi}%cfF?Tl^A#> zB5EYoJ}LCY;BN)$deHuiLMbkJlP9vyvTGTk?scCfR< zFs;2Ra-{}`b96Vqt#G?4JTRdhDiDU--Lao*ZR_KeC3qVX#S8eMq8Zn`i}RdqLT6Za zI9zl{7$!a%ym=}qce87)%#-TUQnhx&iOytg{5$gZKAd6vkY2fXztf<%eO?bs;dUjV r%L!@B$Q{iw%G?XiHe9)QyxnAVJ>T|HBP=&!0dRuwX#SC~r2IbtMt-6l literal 0 HcmV?d00001 diff --git a/res/image/stone.png b/res/image/stone.png new file mode 100644 index 0000000000000000000000000000000000000000..020c8c5f59bca53eb7f1d64098fbb19e6f70a99b GIT binary patch literal 5294 zcmeHKdsIwo8=sO8UDV;wiKZdxGS_CBi>6W&O_~}?x*W7;&z@Lkvd$tCMMYkkXF-}%q1H8XoZ&+qxY&+~hq_nFzh z^1T=8>zV3dFc^KV2WJWTZKQsW*G4~6w}(1lFgny&zW`(j5RH{9WFj~m!Xhzp2n(rT z5eB2WRhSuevS99{gb(5=WjZF~Gaq8>UNsuT4!&C7aj4R-X;*Uwf12wK`aL-4{kz~E z^Pefqh5m8!t0yL8ZgucjXEwLbq;j(z-s=V&|1#L(l8 zzF|f#9N6mDXk9POEPqfF8w^y#0KiFqQZCN1iD$?-F>Q(ssH(8V24;%au70j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l&dhYR+OnKqQ`JhG`RT5XUxc zgY!Odm=$G}_?&p$qze*1a$WKGjdQ_efoF!zbZVYBOe_}KSZQNcG&SOB;)ts0lrLmF zRyl8R*2-1ZyeEHQD5tM1bDice5?I6%B#2N@MG0lth|;Q)Vj)HQaUcJX>zBx-kgEhn zjs;YpL3aJ%fAG6oD?c^qC57TZ=ZoWfi~?P|K%?e3-^Y&AI01ssz?I(eSL(pbC+W48 z7C8d?w}Ff6mZt0hmpj1VlOdb3D+Or^`8@D`M&FbL25y1gHLthkK29HiGxhU`@Flmy|;hQH2eDjVUBX3bhL4_00009a7bBm000XU000XU0RWnu7ytkO2XskI zMF-{y9ReIEbL^hQ0005KNkl>QJpTAz~eGzP(Ovg-Q7VggeX(LjA$PVTRmSY0KWVnmN zx1>6(@5%B4l(>aa^L>6b1hl(*!w%55B$nd*43ZI1fC1p{w1*%I9>2ip81xSNW;B51 zSX7SUDu6_~Ax8x97i8ji0<2LLtOad7=WNpC&!?y=q>;N4QQ`-qcW6100Wu4KwgbO2 z;#_1DnYY}igKaG&Xl(}>mqw#+Ne1Lw3^a4vuE;DZ#r`R2dttlc?U|v$CHgkFdjoUG zO!^vggHf{_g_<}#7BbP?9T-_jm=_t)x1vgzPbXTke;R||PY^LFWF}QfbWxR8zd=AD zB{pR`y$Gq;?TZR%_t3WWKiP*&A6$SKa-b|^MXW*+%X87{D(+2XNmu)ZkmJ0oiU{VB z4eMKba7+;AAoJ1y=JO9k&f&Ta{s`16hecUjlVeZ;g_+Mos(EmOM#em_I46BAsDW@< zJ5#rfS|SVD9en*!$Olkl(A@2le3Id96qqM|pX?qAGvn blocks{}; static std::map texturesIds{}; static std::vector textures{}; -void loadTexture(const std::string& filePath) { - xe::Image* image = xe::Image::createImage(filePath, false); - texturesIds[filePath] = static_cast(textures.size()); - textures.push_back(image); -} - uint32_t getTexture(const std::string& filePath) { + if(!texturesIds.count(filePath)) { + xe::Image* image = xe::Image::createImage(filePath, false); + texturesIds[filePath] = static_cast(textures.size()); + textures.push_back(image); + } return texturesIds[filePath]; } @@ -72,11 +71,13 @@ std::vector& Chunk::getTextures() { } void Chunk::load() { - loadTexture(DIRT_TEXTURE); - loadTexture(GRASS_TEXTURE); - loadTexture(GRASS_TOP_TEXTURE); blocks[DIRT] = {{getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE)}}; blocks[GRASS] = {{getTexture(GRASS_TEXTURE), getTexture(GRASS_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(GRASS_TEXTURE), getTexture(GRASS_TEXTURE)}}; + blocks[GREEN] = {{getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE)}}; + blocks[STONE] = {{getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE)}}; + blocks[SNOW] = {{getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE)}}; + blocks[SAND] = {{getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE)}}; + blocks[WATER] = {{getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE)}}; } void Chunk::unload() { @@ -177,14 +178,25 @@ void Chunk::generate(Chunk* c) { for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { - int height = perlin.octave2D_01((( x + c->gridX * 16) * 0.01), ((z + c->gridZ * 16) * 0.01), 4) * 20; - for(int y = 0; y < 256; y++) { - if(y == height){ - c->setBlock(x, y, z, GRASS); - } else if(y < height) + double noise = perlin.octave2D_01((( x + c->gridX * 16) * 0.01), ((z + c->gridZ * 16) * 0.01), 4); + int height = noise * 40; + for(int y = 0; y < std::max(height, WATER_LEVEL); y++) { + int difference = y - WATER_LEVEL; + if (difference < 0) { + c->setBlock(x, y, z, WATER); + } else if(difference < 3) { + c->setBlock(x, y, z, SAND); + } else if(difference < 5) { c->setBlock(x, y, z, DIRT); - else - c->setBlock(x, y, z, AIR); + } else if(difference < 6) { + c->setBlock(x, y, z, GRASS); + } else if(difference < 10) { + c->setBlock(x, y, z, GREEN); + } else if(difference < 16) { + c->setBlock(x, y, z, STONE); + } else if(difference < 18) { + c->setBlock(x, y, z, SNOW); + } } } } diff --git a/src/chunk.hpp b/src/chunk.hpp index 734c07b..8d1f03c 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -13,15 +13,27 @@ #include #include #include +#include #define INVALID -1 #define AIR 0 #define DIRT 1 #define GRASS 2 +#define GREEN 3 +#define STONE 4 +#define SNOW 5 +#define SAND 6 +#define WATER 7 #define DIRT_TEXTURE "res/image/dirt.png" #define GRASS_TEXTURE "res/image/grass.png" #define GRASS_TOP_TEXTURE "res/image/grass_top.png" +#define STONE_TEXTURE "res/image/stone.png" +#define SNOW_TEXTURE "res/image/snow.png" +#define SAND_TEXTURE "res/image/sand.png" +#define WATER_TEXTURE "res/image/water.png" + +static constexpr int WATER_LEVEL = 20; namespace app { diff --git a/src/first_app.cpp b/src/first_app.cpp index e677d06..a20dcb0 100755 --- a/src/first_app.cpp +++ b/src/first_app.cpp @@ -18,9 +18,9 @@ void FirstApp::run() { SimpleRenderer renderer{xeEngine, Chunk::getTextures()}; - xe::Sound sound{"res/sound/when_the_world_ends.wav"}; - sound.setLooping(true); - sound.play(); + // xe::Sound sound{"res/sound/when_the_world_ends.wav"}; + // sound.setLooping(true); + // sound.play(); KeyboardMovementController cameraController{xeEngine.getInput(), viewerObject};