Random world gen

This commit is contained in:
brausjonas
2022-05-15 19:58:14 +02:00
parent 7ccaebaf06
commit 0a0340d316
5 changed files with 42 additions and 17 deletions
@@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net;
using System.Net.Sockets;
@@ -17,7 +19,7 @@ public class Client
private UdpClient client;
private int port;
private Thread receiveThread;
public Client(string hostname, int port, World world, string name)
{
this.port = port;
@@ -27,7 +29,7 @@ public class Client
//setup client
client = new UdpClient();
client.DontFragment = false;
if (IPAddress.TryParse(hostname, out IPAddress address))
{
address = IPAddress.Parse(hostname);
@@ -48,7 +50,7 @@ public class Client
{
sendList.Add(b);
}
Send(sendList.ToArray());
IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 8051);
byte[] data = client.Receive(ref endPoint);
@@ -257,6 +259,7 @@ public class Client
{
client.Send(data, data.Length);
}
public void Disconnect()
{
+30 -6
View File
@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class World : MonoBehaviour
{
@@ -17,6 +18,8 @@ public class World : MonoBehaviour
private Queue<Player.PlayerRotationsUpdateData> playersRotationsToUpdate =
new Queue<Player.PlayerRotationsUpdateData>();
private bool backToMenuRequest = false;
//chunks
private Chunk[,] chunks;
private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>();
@@ -91,6 +94,12 @@ public class World : MonoBehaviour
g.transform.rotation = data.rotation;
}
}
//go bock to menu
if (backToMenuRequest)
{
SceneManager.LoadScene("Scenes/Login", LoadSceneMode.Single);
}
}
//enqueue player position update to list
@@ -217,15 +226,25 @@ public class World : MonoBehaviour
return blockData[blockID].textures;
}
//get the perlin noise height
//get the height
public byte GetHeight(int x, int z)
{
float scale = 0.025f;
byte perlinHeight = 10;
byte groundHeight = 10;
int xChunk = x / Data.chunkWidth;
int zChunk = z / Data.chunkWidth;
byte height = (byte)(Mathf.PerlinNoise((x) * scale + 0.1f, (z) * scale + 0.1f) * perlinHeight + groundHeight);
return height;
int xInChunk = x - (xChunk * Data.chunkWidth);
int zInChunk = z - (zChunk * Data.chunkWidth);
Chunk c = chunks[xChunk, zChunk];
for (int y = 0; y < Data.chunkHeight; y++)
{
if (c.blocks[xInChunk, y, zInChunk] == 0)
{
return (byte)(y - 1);
}
}
return 250;
}
//edit a block in local chunk storage
@@ -270,6 +289,11 @@ public class World : MonoBehaviour
}
public void BackToMenu()
{
SceneManager.LoadScene("Scenes/Login", LoadSceneMode.Single);
}
public Client GetClient()
{
return client;