Skip to content

Commit d5cc852

Browse files
author
Vyacheslav
committed
Added simpliest world generator
1 parent 92184c3 commit d5cc852

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using UnityEngine;
3+
4+
namespace VoxelGame.Voxel
5+
{
6+
public class SinGenerator : IGenerator
7+
{
8+
public void GenerateMap(Vector3Int position, ref byte[,,] map)
9+
{
10+
if (map == null)
11+
return;
12+
13+
int lengthX = map.GetLength(0);
14+
int lengthY = map.GetLength(1);
15+
int lengthZ = map.GetLength(2);
16+
17+
if (lengthX == 0 || lengthY == 0 || lengthZ == 0)
18+
return;
19+
20+
float waveScale = 0.1f;
21+
float waveHeight = 0.05f;
22+
float waveYOffset = 0.25f;
23+
24+
for (int x = 0; x < lengthX; x++)
25+
for (int z = 0; z < lengthZ; z++)
26+
for (int y = 0; y < lengthY; y++)
27+
{
28+
float h = ((Mathf.Sin((position.x + x) * waveScale) + Mathf.Cos((position.z + z) * waveScale) + 2) * waveHeight + waveYOffset) * VoxelData.chunkHeight;
29+
30+
map[x, y, z] = y < h ? Voxels.STONE : Voxels.AIR;
31+
}
32+
}
33+
34+
public void GenerateChunkStructures(Vector2Int coords, ref byte[,,] map)
35+
{
36+
// no structures
37+
}
38+
}
39+
}

VoxelGame_UnityProject/Assets/VoxelGame/Voxel/Scripts/Generators/SinGenerator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)