summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/image/sand.pngbin0 -> 1201 bytes
-rw-r--r--res/image/snow.pngbin0 -> 5087 bytes
-rw-r--r--res/image/stone.pngbin0 -> 5294 bytes
-rw-r--r--res/image/water.pngbin0 -> 942 bytes
-rwxr-xr-xres/shaders/simple_shader.frag2
-rw-r--r--src/chunk.cpp44
-rw-r--r--src/chunk.hpp12
-rwxr-xr-xsrc/first_app.cpp6
8 files changed, 44 insertions, 20 deletions
diff --git a/res/image/sand.png b/res/image/sand.png
new file mode 100644
index 0000000..b82eaca
--- /dev/null
+++ b/res/image/sand.png
Binary files differ
diff --git a/res/image/snow.png b/res/image/snow.png
new file mode 100644
index 0000000..f8f1fa6
--- /dev/null
+++ b/res/image/snow.png
Binary files differ
diff --git a/res/image/stone.png b/res/image/stone.png
new file mode 100644
index 0000000..020c8c5
--- /dev/null
+++ b/res/image/stone.png
Binary files differ
diff --git a/res/image/water.png b/res/image/water.png
new file mode 100644
index 0000000..7b54110
--- /dev/null
+++ b/res/image/water.png
Binary files differ
diff --git a/res/shaders/simple_shader.frag b/res/shaders/simple_shader.frag
index 1ea39c7..e7d6bdb 100755
--- a/res/shaders/simple_shader.frag
+++ b/res/shaders/simple_shader.frag
@@ -6,7 +6,7 @@ layout (location = 2) in flat int fragTex;
layout (location = 0) out vec4 outColor;
-layout (binding = 1) uniform sampler2D texSampler[3];
+layout (binding = 1) uniform sampler2D texSampler[6];
void main() {
outColor = texture(texSampler[fragTex], fragUv) + fragLight;
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 2f7c969..0fc52fe 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -57,13 +57,12 @@ static std::map<uint8_t, Block> blocks{};
static std::map<std::string, uint32_t> texturesIds{};
static std::vector<xe::Image*> textures{};
-void loadTexture(const std::string& filePath) {
- xe::Image* image = xe::Image::createImage(filePath, false);
- texturesIds[filePath] = static_cast<uint32_t>(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<uint32_t>(textures.size());
+ textures.push_back(image);
+ }
return texturesIds[filePath];
}
@@ -72,11 +71,13 @@ std::vector<xe::Image*>& 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 <memory>
#include <string>
#include <map>
+#include <algorithm>
#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};