Dead Screen

Dead Screen (missing the sync to the Server)
This commit is contained in:
Noah
2022-05-15 20:58:58 +02:00
parent 7ccaebaf06
commit 0292debae7
10 changed files with 730 additions and 25 deletions
+16 -5
View File
@@ -27,6 +27,7 @@ public class Player : MonoBehaviour
private Vector3 lastPosition = new Vector3();
private Quaternion lastRotation = new Quaternion();
//network
private Client client = null;
@@ -37,8 +38,7 @@ public class Player : MonoBehaviour
//lock the cursor
Cursor.lockState = CursorLockMode.Locked;
camera = GetComponentInChildren<Camera>();
transform.position = new Vector3((byte)transform.position.x,
world.GetHeight((byte)transform.position.x, (byte)transform.position.z) + 2, (byte)transform.position.z);
transform.position = GetDefaultPlayerPosition();
}
private void Jump()
@@ -96,9 +96,9 @@ public class Player : MonoBehaviour
rotX -= mouseY * 1.4f;
rotX = Mathf.Clamp(rotX, -90, 90);
camera.transform.localRotation = Quaternion.Euler(rotX, 0, 0);
camera.transform.localRotation = Quaternion.Euler(rotX * Time.timeScale, 0, 0);
transform.Rotate(0, mouseX, 0);
transform.Rotate(0, mouseX * Time.timeScale, 0);
//send destroy block request to server
if (Input.GetMouseButtonDown(0))
@@ -116,9 +116,14 @@ public class Player : MonoBehaviour
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
{
hit.point -= camera.transform.forward / 10;
client.EditBlock(hit.point, 4);
client.EditBlock(hit.point, 5);
}
}
if (transform.position.y < 0)
{
world.ShowDeadScreen();
}
}
private void CalculateVelocity()
@@ -289,5 +294,11 @@ public class Player : MonoBehaviour
this.rotation = rotation;
}
}
public Vector3 GetDefaultPlayerPosition()
{
return new Vector3((byte)transform.position.x,
world.GetHeight((byte)transform.position.x, (byte)transform.position.z) + 2, (byte)transform.position.z);
}
}
+46 -6
View File
@@ -2,6 +2,9 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class World : MonoBehaviour
{
@@ -17,6 +20,9 @@ public class World : MonoBehaviour
private Queue<Player.PlayerRotationsUpdateData> playersRotationsToUpdate =
new Queue<Player.PlayerRotationsUpdateData>();
[SerializeField] private Player player;
[SerializeField] private GameObject deadScreen;
//chunks
private Chunk[,] chunks;
private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>();
@@ -217,15 +223,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
@@ -282,4 +298,28 @@ 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);
}
}