added block breaking
This commit is contained in:
32
Window.cs
32
Window.cs
@@ -1,5 +1,6 @@
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Windowing.Common;
|
||||
using OpenTK.Windowing.Common.Input;
|
||||
using OpenTK.Windowing.Desktop;
|
||||
|
||||
namespace Voxel
|
||||
@@ -8,14 +9,10 @@ namespace Voxel
|
||||
{
|
||||
public readonly int Width = width;
|
||||
public readonly int Height = height;
|
||||
public Player Player;
|
||||
public uint frames = 0;
|
||||
public double timeElapsed = 0;
|
||||
|
||||
// testing
|
||||
public Chunk Chunk;
|
||||
private Dictionary<int, bool> _cache = new Dictionary<int, bool>();
|
||||
private bool chunkEmpty = false;
|
||||
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnUpdateFrame(e);
|
||||
@@ -25,30 +22,10 @@ namespace Voxel
|
||||
Close();
|
||||
}
|
||||
|
||||
RemoveRandomBlocks();
|
||||
}
|
||||
|
||||
private void RemoveRandomBlocks()
|
||||
{
|
||||
if (Chunk != null && !chunkEmpty)
|
||||
if (Player != null)
|
||||
{
|
||||
Random rng = new Random();
|
||||
|
||||
int GetNum()
|
||||
{
|
||||
int max = 4096;
|
||||
int num = rng.Next(max);
|
||||
if (_cache.ContainsKey(num)) return GetNum();
|
||||
_cache[num] = true;
|
||||
if (_cache.Count == max) chunkEmpty = true;
|
||||
return num;
|
||||
}
|
||||
|
||||
Chunk.SetBlockIndex(GetNum(), Blocks.Air);
|
||||
Player.Update((float)e.Time);
|
||||
}
|
||||
|
||||
Renderer.ClearFaces();
|
||||
Renderer.AddFaces(Chunk.GetChunkMesh().Faces);
|
||||
}
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
@@ -93,6 +70,7 @@ namespace Voxel
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
|
||||
|
||||
CursorState = CursorState.Grabbed;
|
||||
Cursor = MouseCursor.Default;
|
||||
VSync = VSyncMode.On;
|
||||
|
||||
Camera.UpdateProjection(Width, Height);
|
||||
|
||||
Reference in New Issue
Block a user