This commit is contained in:
Noah
2022-05-15 21:00:56 +02:00
7 changed files with 115 additions and 72 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()
{
+13 -66
View File
@@ -4,8 +4,6 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class World : MonoBehaviour
{
//basic
@@ -20,9 +18,8 @@ public class World : MonoBehaviour
private Queue<Player.PlayerRotationsUpdateData> playersRotationsToUpdate =
new Queue<Player.PlayerRotationsUpdateData>();
[SerializeField] private Player player;
[SerializeField] private GameObject deadScreen;
private bool backToMenuRequest = false;
//chunks
private Chunk[,] chunks;
private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>();
@@ -97,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
@@ -144,43 +147,6 @@ public class World : MonoBehaviour
}
}
//return the ID of a block
public byte GetBlockID(Vector3 positionInWorld)
{
byte height = GetHeight((int)positionInWorld.x, (int)positionInWorld.z);
//world pass
if (positionInWorld.x < 0 || positionInWorld.y < 0 || positionInWorld.z < 0 ||
positionInWorld.x >= worldSize * Data.chunkWidth || positionInWorld.y > height ||
positionInWorld.z >= worldSize * Data.chunkWidth)
{
return 0;
}
//chunk pass
if ((int)positionInWorld.y == height)
{
return 3;
}
if ((int)positionInWorld.y == 0)
{
return 1;
}
if ((int)positionInWorld.y > height - 3)
{
return 2;
}
if ((int)positionInWorld.y < height)
{
return 4;
}
return 0;
}
//returns if a block is on the position
public bool CheckBlock(Vector3 positionInWorld)
{
@@ -286,6 +252,11 @@ public class World : MonoBehaviour
}
public void BackToMenu()
{
SceneManager.LoadScene("Scenes/Login", LoadSceneMode.Single);
}
public Client GetClient()
{
return client;
@@ -298,28 +269,4 @@ public class World : MonoBehaviour
public string name;
public byte[] textures = new byte[6];
}
public void ShowDeadScreen()
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
deadScreen.SetActive(true);
Time.timeScale = 0;
}
public void RespawnButton()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Confined;
Time.timeScale = 1;
player.transform.position = player.GetDefaultPlayerPosition();
deadScreen.SetActive(false);
}
public void QuitButton()
{
client.Disconnect();
SceneManager.LoadScene("Login");
deadScreen.SetActive(false);
}
}