]> git.lizzy.rs Git - dragonblocks3d-lua.git/commitdiff
Trees; Random Seed
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 14 Aug 2020 12:15:04 +0000 (14:15 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 14 Aug 2020 12:15:04 +0000 (14:15 +0200)
15 files changed:
modules/Client/src/graphics.lua
modules/Client/src/init.lua
modules/Game/ressources/dirt.png
modules/Game/ressources/grass.png [new file with mode: 0644]
modules/Game/ressources/leaves.png [new file with mode: 0644]
modules/Game/ressources/old/dirt.png [new file with mode: 0644]
modules/Game/ressources/old/grass.png [new file with mode: 0644]
modules/Game/ressources/old/leaves.png [new file with mode: 0644]
modules/Game/ressources/old/stone.png [new file with mode: 0644]
modules/Game/ressources/old/tree.png [new file with mode: 0644]
modules/Game/ressources/stone.png
modules/Game/ressources/tree.png [new file with mode: 0644]
modules/Game/src/init.lua
modules/MapGen/src/init.lua
modules/RenderEngine/src/mesh.lua

index 9f412670a8313911940c1e3ff3cb52a6f180b455..a56074b39be0d6ab1ed152f0de3addc28bb833ce 100644 (file)
@@ -10,7 +10,7 @@ function graphics:init()
        RenderEngine.mesh_effect_grow_time = 0.25
        RenderEngine.mesh_effect_flyin_time = 0.5
        RenderEngine.mesh_effect_flyin_offset = 20
-       --RenderEngine.mesh_effect_rotate_speed = 
+       RenderEngine.mesh_effect_rotate_speed = 1
        
        RenderEngine:set_wireframe(false)
 
index 067b04190669832f0b42e649d6114dd480c22f6d..c368a2db581ac7bf3e34549ca29a31fe9851ae3e 100644 (file)
@@ -13,3 +13,6 @@ Dragonblocks:add_task(function()
                coroutine.yield("FPS:" .. math.floor(Dragonblocks.tps or 0))
        until false
 end)
+
+
+RenderEngine:render_loop(true)
index 5cc6e8639556cfa826aa5e5079ff318de48de4ff..617d353e0d67a14a2952b2a98375eb8a50b97d79 100644 (file)
Binary files a/modules/Game/ressources/dirt.png and b/modules/Game/ressources/dirt.png differ
diff --git a/modules/Game/ressources/grass.png b/modules/Game/ressources/grass.png
new file mode 100644 (file)
index 0000000..273d7c6
Binary files /dev/null and b/modules/Game/ressources/grass.png differ
diff --git a/modules/Game/ressources/leaves.png b/modules/Game/ressources/leaves.png
new file mode 100644 (file)
index 0000000..33ac473
Binary files /dev/null and b/modules/Game/ressources/leaves.png differ
diff --git a/modules/Game/ressources/old/dirt.png b/modules/Game/ressources/old/dirt.png
new file mode 100644 (file)
index 0000000..5cc6e86
Binary files /dev/null and b/modules/Game/ressources/old/dirt.png differ
diff --git a/modules/Game/ressources/old/grass.png b/modules/Game/ressources/old/grass.png
new file mode 100644 (file)
index 0000000..e522a90
Binary files /dev/null and b/modules/Game/ressources/old/grass.png differ
diff --git a/modules/Game/ressources/old/leaves.png b/modules/Game/ressources/old/leaves.png
new file mode 100644 (file)
index 0000000..02b6cf0
Binary files /dev/null and b/modules/Game/ressources/old/leaves.png differ
diff --git a/modules/Game/ressources/old/stone.png b/modules/Game/ressources/old/stone.png
new file mode 100644 (file)
index 0000000..a641ceb
Binary files /dev/null and b/modules/Game/ressources/old/stone.png differ
diff --git a/modules/Game/ressources/old/tree.png b/modules/Game/ressources/old/tree.png
new file mode 100644 (file)
index 0000000..d0b26b8
Binary files /dev/null and b/modules/Game/ressources/old/tree.png differ
index a641ceb677542fbf9a78417ba1cee614bbc9ab00..87e19ff46b57f2bb86553459b2ebb2805ebbc55a 100644 (file)
Binary files a/modules/Game/ressources/stone.png and b/modules/Game/ressources/stone.png differ
diff --git a/modules/Game/ressources/tree.png b/modules/Game/ressources/tree.png
new file mode 100644 (file)
index 0000000..914cb5f
Binary files /dev/null and b/modules/Game/ressources/tree.png differ
index 707ce0dd823d9f9d2e011ca4615d5be44d032d87..061eace2bc9366df3366d026f842f449593f3355 100644 (file)
@@ -1,11 +1,26 @@
-local ressource_path = Game:get_path() .. "/ressources/"
+local ressource_path = Game:get_path() .. "/ressources"
 
 BlockSystem:register_block({
        name = "game:stone",
-       texture_path = ressource_path .. "stone.png",
+       texture_path = ressource_path .. "/stone.png",
 })
 
 BlockSystem:register_block({
        name = "game:dirt",
-       texture_path = ressource_path .. "dirt.png",
+       texture_path = ressource_path .. "/dirt.png",
+})
+
+BlockSystem:register_block({
+       name = "game:grass",
+       texture_path = ressource_path .. "/grass.png",
+})
+
+BlockSystem:register_block({
+       name = "game:tree",
+       texture_path = ressource_path .. "/tree.png",
+})
+
+BlockSystem:register_block({
+       name = "game:leaves",
+       texture_path = ressource_path .. "/leaves.png",
 })
index 86f408736e8dbcacba95e9b0d77db4ac599a77de..5d2c4cb135a2d4e78aebee65322ba6f0a61c172c 100644 (file)
@@ -1,19 +1,88 @@
 local stone = BlockSystem:get_def("game:stone")
 local dirt = BlockSystem:get_def("game:dirt")
+local grass = BlockSystem:get_def("game:grass")
+local leaves = BlockSystem:get_def("game:leaves")
+local tree = BlockSystem:get_def("game:tree")
 
-local air_probability = 2
-local random_blocks = {stone, dirt}
-local random_blocks_num = #random_blocks + air_probability
+math.randomseed(os.time())
 
 function MapGen:generate(chunk)
+       local grass_layer_table, old_grass_layer_table
+       local grass_layer
        for x = 0, 15 do
-               for y = 0, 15 do
-                       for z = 0, 15 do
-                               local block = random_blocks[math.random(random_blocks_num)]
-                               if block then
-                                       chunk:add_block(glm.vec3(x, y, z), block)
+               grass_layer_table, old_grass_layer_table = {}, grass_layer_table
+               grass_layer = old_grass_layer_table and old_grass_layer_table[1] or 8 + math.random(5)
+               for z = 0, 15 do
+                       local old_grass_layer = old_grass_layer_table and old_grass_layer_table[z] or grass_layer
+                       grass_layer = math.floor((grass_layer + old_grass_layer) / 2)
+                       if math.random(3) == 1 then
+                               grass_layer = grass_layer + math.random(3) - 2
+                       end
+                       grass_layer = glm.clamp(grass_layer, 0, 15)
+                       grass_layer_table[z] = grass_layer
+                       if math.random(25) == 1 then
+                               chunk:add_block(glm.vec3(x, grass_layer, z), dirt)
+                               self:add_tree(chunk, glm.vec3(x, grass_layer + 1, z))
+                       else
+                               chunk:add_block(glm.vec3(x, grass_layer, z), grass)
+                       end
+                       local dirt_start, dirt_end = grass_layer - 1, math.max(grass_layer - 5, 0)
+                       local stone_start, stone_end = grass_layer - 6, 0
+                       if dirt_start >= 0 then
+                               for y = dirt_start, dirt_end, -1  do
+                                       chunk:add_block(glm.vec3(x, y, z), dirt)
                                end
                        end
+                       if stone_start >= 0 then
+                               for y = stone_start, stone_end, -1  do
+                                       chunk:add_block(glm.vec3(x, y, z), stone)
+                               end
+                       end
+               end
+       end
+end
+
+local tree_blocks = {
+       glm.vec3( 0,  0,  0),
+       glm.vec3( 0,  1,  0),
+       glm.vec3(-1,  2, -1),
+       glm.vec3(-1,  2,  0),
+       glm.vec3(-1,  2,  1),
+       glm.vec3( 0,  2, -1),
+       glm.vec3( 0,  2,  0),
+       glm.vec3( 0,  2,  1),
+       glm.vec3( 1,  2, -1),
+       glm.vec3( 1,  2,  0),
+       glm.vec3( 1,  2,  1),
+       glm.vec3(-1,  3, -1),
+       glm.vec3(-1,  3,  0),
+       glm.vec3(-1,  3,  1),
+       glm.vec3( 0,  3, -1),
+       glm.vec3( 0,  3,  0),
+       glm.vec3( 0,  3,  1),
+       glm.vec3( 1,  3, -1),
+       glm.vec3( 1,  3,  0),
+       glm.vec3( 1,  3,  1),
+       glm.vec3(-1,  4, -1),
+       glm.vec3(-1,  4,  0),
+       glm.vec3(-1,  4,  1),
+       glm.vec3( 0,  4, -1),
+       glm.vec3( 0,  4,  0),
+       glm.vec3( 0,  4,  1),
+       glm.vec3( 1,  4, -1),
+       glm.vec3( 1,  4,  0),
+       glm.vec3( 1,  4,  1),
+}
+
+function MapGen:add_tree(chunk, tree_pos)
+       for i, p in ipairs(tree_blocks) do
+               local block = leaves
+               if i < 3 then
+                       block = tree
+               end
+               local pos = tree_pos + p
+               if chunk:get_pos_hash(pos) then
+                       chunk:add_block(pos, block)
                end
        end
 end
index 94c2a570a60e1c404aa5d5b9f9509e80bb6098cd..3ebb4e5263adef770901bca5dd33a6d7e24f71e5 100644 (file)
@@ -67,7 +67,7 @@ function Mesh:apply_vertices(vertices)
 end
 
 function Mesh:render(dtime)
-       local pos, size = self.pos, self.size
+       local pos, size, rotation = self.pos, self.size, 0
 
        if self.effect then
                if self.effect_lasts then
@@ -86,6 +86,8 @@ function Mesh:render(dtime)
                        size = size * math.pow(1 - self.effect_lasts / RenderEngine.mesh_effect_grow_time, 1)
                elseif self.effect == Mesh.EFFECT_FLYIN then
                        pos = pos - glm.vec3(0, RenderEngine.mesh_effect_flyin_offset * self.effect_lasts / RenderEngine.mesh_effect_flyin_time, 0)
+               elseif self.effect == Mesh.EFFECT_ROTATE then
+                       rotation = glfw.get_time() * RenderEngine.mesh_effect_rotate_speed * math.pi * 2
                end
        end
        
@@ -93,6 +95,7 @@ function Mesh:render(dtime)
        
        local model_matrix = 1
                * glm.translate(pos)
+               * glm.rotate(rotation, glm.vec3(0, 1, 0))
                * glm.scale(size)
        
        gl.uniform_matrix4f(gl.get_uniform_location(RenderEngine.shaders, "model"), true, model_matrix)