added block breaking
This commit is contained in:
40
Player.cs
Normal file
40
Player.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using OpenTK.Mathematics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Voxel
|
||||
{
|
||||
public class Player
|
||||
{
|
||||
public Vector3 Position;
|
||||
|
||||
private World _world;
|
||||
|
||||
public Player(World world, Vector3 startPos)
|
||||
{
|
||||
_world = world;
|
||||
}
|
||||
|
||||
public void BreakBlock()
|
||||
{
|
||||
var (hit, x, y, z) = _world.Raycast(5f); // max 5 blocks
|
||||
if (hit != Blocks.Air)
|
||||
{
|
||||
_world.SetBlock(x, y, z, Blocks.Air);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
Camera.Update(deltaTime);
|
||||
|
||||
if (Input.GetKey(OpenTK.Windowing.GraphicsLibraryFramework.Keys.Space))
|
||||
{
|
||||
BreakBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user