Merge branch 'main' of https://github.com/jonasbraus/Minecraft
This commit is contained in:
@@ -254,6 +254,11 @@ public class Client
|
|||||||
Send(new byte[] { 3, (byte)chunk.x, (byte)chunk.z, xInChunk, yInChunk, zInChunk, blockID });
|
Send(new byte[] { 3, (byte)chunk.x, (byte)chunk.z, xInChunk, yInChunk, zInChunk, blockID });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendDeadMessage()
|
||||||
|
{
|
||||||
|
Send(new byte[]{10});
|
||||||
|
}
|
||||||
|
|
||||||
//default send method
|
//default send method
|
||||||
private void Send(byte[] data)
|
private void Send(byte[] data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -177,7 +177,10 @@ public class Player : MonoBehaviour
|
|||||||
|
|
||||||
if (transform.position.y < 0)
|
if (transform.position.y < 0)
|
||||||
{
|
{
|
||||||
world.ShowDeadScreen();
|
if(Time.timeScale > 0)
|
||||||
|
{
|
||||||
|
world.ShowDeadScreen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.Escape))
|
if (Input.GetKeyDown(KeyCode.Escape))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
@@ -154,9 +155,9 @@ public class World : MonoBehaviour
|
|||||||
//returns if a block is on the position
|
//returns if a block is on the position
|
||||||
public bool CheckBlock(Vector3 positionInWorld)
|
public bool CheckBlock(Vector3 positionInWorld)
|
||||||
{
|
{
|
||||||
if (positionInWorld.x < -1 || positionInWorld.z < -1 ||
|
if (positionInWorld.x < 0 || positionInWorld.z < 0 ||
|
||||||
positionInWorld.x > worldSize * Data.chunkWidth ||
|
positionInWorld.x >= worldSize * Data.chunkWidth ||
|
||||||
positionInWorld.z > worldSize * Data.chunkWidth)
|
positionInWorld.z >= worldSize * Data.chunkWidth)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -255,12 +256,6 @@ public class World : MonoBehaviour
|
|||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void BackToMenu()
|
|
||||||
{
|
|
||||||
SceneManager.LoadScene("Scenes/Login", LoadSceneMode.Single);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Client GetClient()
|
public Client GetClient()
|
||||||
{
|
{
|
||||||
return client;
|
return client;
|
||||||
@@ -277,6 +272,7 @@ public class World : MonoBehaviour
|
|||||||
|
|
||||||
public void ShowDeadScreen()
|
public void ShowDeadScreen()
|
||||||
{
|
{
|
||||||
|
client.SendDeadMessage();
|
||||||
Cursor.visible = true;
|
Cursor.visible = true;
|
||||||
Cursor.lockState = CursorLockMode.None;
|
Cursor.lockState = CursorLockMode.None;
|
||||||
deadScreen.SetActive(true);
|
deadScreen.SetActive(true);
|
||||||
@@ -310,6 +306,7 @@ public class World : MonoBehaviour
|
|||||||
|
|
||||||
public void QuitButton()
|
public void QuitButton()
|
||||||
{
|
{
|
||||||
|
Time.timeScale = 1;
|
||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
SceneManager.LoadScene("Login");
|
SceneManager.LoadScene("Login");
|
||||||
deadScreen.SetActive(false);
|
deadScreen.SetActive(false);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public class Server
|
|||||||
//[0] = 7: player position update
|
//[0] = 7: player position update
|
||||||
//[0] = 8: player rotation update
|
//[0] = 8: player rotation update
|
||||||
//[0] = 9: Save the World
|
//[0] = 9: Save the World
|
||||||
|
//[0] = 10: Player died
|
||||||
|
|
||||||
private void Receive()
|
private void Receive()
|
||||||
{
|
{
|
||||||
@@ -249,6 +250,12 @@ public class Server
|
|||||||
{
|
{
|
||||||
world.SaveWorld();
|
world.SaveWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//player died
|
||||||
|
if (data[0] == 10)
|
||||||
|
{
|
||||||
|
Console.WriteLine(playerNames[GetPlayerID(endPoint)] + " died! \n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user