Player Object
This commit is contained in:
@@ -1,22 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar;
|
||||
|
||||
namespace VoxelIsometricRenderer
|
||||
{
|
||||
public static class PlayerObject
|
||||
{
|
||||
static int PositionX = 0;
|
||||
static int PositionY = 0;
|
||||
static int PositionZ = 0;
|
||||
static int BlockID = 0;
|
||||
static float PositionX = 0;
|
||||
static float PositionY = 0;
|
||||
static float PositionZ = 0;
|
||||
static int BlockposX = 5;
|
||||
static int BlockposY = 17;
|
||||
static int BlockposZ =5;
|
||||
static float PrecisePositionX = 0.0f;
|
||||
static float PrecisePositionY = 0.0f;
|
||||
static float PrecisePositionZ = 0.0f;
|
||||
static Rectangle CameraCentre = new Rectangle(0,0,100,100);
|
||||
static int[] LastPositions = new int[] { 0, -192 };
|
||||
static Rectangle PlayerPosition = new Rectangle(0,0,100,100);
|
||||
public static void Draw(Graphics g)
|
||||
{
|
||||
BlockRegistry.RenderBlock(g,BlockID, BlockposX, BlockposY, BlockposZ, 1);
|
||||
int[] Positions = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ,PositionX,PositionY,PositionZ);
|
||||
if (Positions[0] != LastPositions[0] || Positions[1] != LastPositions[1])
|
||||
{
|
||||
//MessageBox.Show(Positions[0] + "_" + Positions[1]);
|
||||
LastPositions = Positions;
|
||||
}
|
||||
PlayerPosition = new Rectangle(Positions[0] + (int)(Terrain4.width / (2 * TextureManager.RenderScale)), Positions[1] + (int)(Terrain4.height / (2 * TextureManager.RenderScale)), TextureManager.VoxelSize, TextureManager.VoxelSize);
|
||||
g.DrawRectangle(new Pen(Brushes.Blue), PlayerPosition);
|
||||
g.DrawRectangle(new Pen(Brushes.Red), CameraCentre);
|
||||
}
|
||||
public static void UpdateCamera()
|
||||
{
|
||||
if (!CameraCentre.IntersectsWith(PlayerPosition))
|
||||
{
|
||||
float YPosition = PositionY;
|
||||
float XPosition = PositionX;
|
||||
float ZPosition = PositionZ;
|
||||
int[] Positions = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ, PositionX, PositionY + 1, PositionZ);
|
||||
Rectangle NextPosition = new Rectangle(Positions[0] + (int)(Terrain4.width / (2 * TextureManager.RenderScale)), Positions[1] + (int)(Terrain4.height / (2 * TextureManager.RenderScale)), TextureManager.VoxelSize, TextureManager.VoxelSize);
|
||||
int[] PositionsX = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ, PositionX + 1, PositionY, PositionZ - 1);
|
||||
Rectangle NextPositionX = new Rectangle(PositionsX[0] + (int)(Terrain4.width / (2 * TextureManager.RenderScale)), PositionsX[1] + (int)(Terrain4.height / (2 * TextureManager.RenderScale)), TextureManager.VoxelSize, TextureManager.VoxelSize);
|
||||
if (LightingManager.Square(CameraCentre.Y - PlayerPosition.Y) > LightingManager.Square(CameraCentre.Y - NextPosition.Y) && !CameraCentre.Contains(CameraCentre.X, PlayerPosition.Y))
|
||||
{
|
||||
float Iterator = 0;
|
||||
while (!CameraCentre.Contains(CameraCentre.X,NextPosition.Y) && Iterator < 100)
|
||||
{
|
||||
Iterator+=0.1f;
|
||||
Positions = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ, PositionX, PositionY + Iterator, PositionZ);
|
||||
NextPosition = new Rectangle(Positions[0] + (int)(Terrain4.width / (2 * TextureManager.RenderScale)), Positions[1] + (int)(Terrain4.height / (2 * TextureManager.RenderScale)), TextureManager.VoxelSize, TextureManager.VoxelSize);
|
||||
}
|
||||
YPosition += Iterator;
|
||||
}
|
||||
else if (LightingManager.Square(CameraCentre.Y - PlayerPosition.Y) < LightingManager.Square(CameraCentre.Y - NextPosition.Y))
|
||||
{
|
||||
float Iterator = 0;
|
||||
while (!CameraCentre.Contains(CameraCentre.X, NextPosition.Y))
|
||||
{
|
||||
Iterator--;
|
||||
Positions = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ, PositionX, PositionY + Iterator, PositionZ);
|
||||
NextPosition = new Rectangle(Positions[0] + (int)(Terrain4.width / (2 * TextureManager.RenderScale)), Positions[1] + (int)(Terrain4.height / (2 * TextureManager.RenderScale)), TextureManager.VoxelSize, TextureManager.VoxelSize);
|
||||
}
|
||||
YPosition += Iterator;
|
||||
}
|
||||
if (LightingManager.Square(CameraCentre.X - PlayerPosition.X) < LightingManager.Square(CameraCentre.X - NextPositionX.X) && !CameraCentre.Contains(PlayerPosition.X, CameraCentre.Y))
|
||||
{
|
||||
float IteratorX = 0;
|
||||
float IteratorZ = 0;
|
||||
while (!CameraCentre.Contains(NextPositionX.X, CameraCentre.Y) && IteratorX > -2 && IteratorZ < 2)
|
||||
{
|
||||
IteratorX-=0.1f;
|
||||
IteratorZ+=0.1f;
|
||||
PositionsX = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ, PositionX + IteratorX, PositionY, PositionZ + IteratorZ);
|
||||
NextPositionX = new Rectangle(PositionsX[0] + (int)(Terrain4.width / (2 * TextureManager.RenderScale)), PositionsX[1] + (int)(Terrain4.height / (2 * TextureManager.RenderScale)), TextureManager.VoxelSize, TextureManager.VoxelSize);
|
||||
}
|
||||
XPosition += IteratorX;
|
||||
ZPosition += IteratorZ;
|
||||
}
|
||||
else if (PlayerPosition.X < CameraCentre.X)
|
||||
{
|
||||
float IteratorX = 0;
|
||||
float IteratorZ = 0;
|
||||
while (!CameraCentre.Contains(NextPositionX.X, CameraCentre.Y) && IteratorZ > -1 && IteratorX < 1)
|
||||
{
|
||||
IteratorX+=0.1f;
|
||||
IteratorZ-=0.1f;
|
||||
PositionsX = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ, PositionX + IteratorX, PositionY, PositionZ + IteratorZ);
|
||||
NextPositionX = new Rectangle(PositionsX[0] + (int)(Terrain4.width / (2 * TextureManager.RenderScale)), PositionsX[1] + (int)(Terrain4.height / (2 * TextureManager.RenderScale)), TextureManager.VoxelSize, TextureManager.VoxelSize);
|
||||
}
|
||||
XPosition += IteratorX;
|
||||
ZPosition += IteratorZ;
|
||||
}
|
||||
|
||||
PositionX = XPosition;
|
||||
PositionY = YPosition;
|
||||
PositionZ = ZPosition;
|
||||
}
|
||||
}
|
||||
public static void UpdateCameraCentre(int Width, int Height)
|
||||
{
|
||||
CameraCentre = new Rectangle((int)((Width/(2 * TextureManager.RenderScale)) - TextureManager.VoxelSize), (int)((Height/ (2 * TextureManager.RenderScale)) - (TextureManager.VoxelSize)), (int)(TextureManager.VoxelSize*2), (int)(TextureManager.VoxelSize*2));
|
||||
}
|
||||
public static void CreatePlayer(int[] Faces, int RenderType, BlockState blockState)
|
||||
{
|
||||
Voxel voxel = new Voxel(RenderType, Faces[0], Faces[1], Faces[2], Faces[3], Faces[4], Faces[5], blockState.hasBlocksLight());
|
||||
int index = VoxelRegistry.VoxelExists(voxel);
|
||||
if (index == -1)
|
||||
{
|
||||
index = VoxelRegistry.IndexVoxel(voxel);
|
||||
}
|
||||
Block newBlock = new Block(index, BlockstateRegistry.GetBlockstateIndex(blockState), -1);
|
||||
int x = BlockposX;
|
||||
int y = BlockposY;
|
||||
int z = BlockposZ;
|
||||
BlockID = BlockRegistry.CheckInBlock(newBlock, x, y, z);
|
||||
}
|
||||
public static float[] GetCameraPos()
|
||||
{
|
||||
return new float[] { PositionX, PositionY, PositionZ };
|
||||
}
|
||||
public static int[] GetPos()
|
||||
{
|
||||
return new int[] { PositionX, PositionY, PositionZ };
|
||||
return new int[] { BlockposX, BlockposY, BlockposZ };
|
||||
}
|
||||
public static float[] GetPresicePos()
|
||||
{
|
||||
@@ -24,9 +136,9 @@ namespace VoxelIsometricRenderer
|
||||
}
|
||||
public static void SetPos(int[] pos, bool Reoccure)
|
||||
{
|
||||
PositionX = pos[0];
|
||||
PositionY = pos[1];
|
||||
PositionZ = pos[2];
|
||||
BlockposX = pos[0];
|
||||
BlockposY = pos[1];
|
||||
BlockposZ = pos[2];
|
||||
if (Reoccure) SetPrecisePos(new float[] { pos[0], pos[1], pos[2] },false);
|
||||
}
|
||||
public static void SetPrecisePos(float[] pos, bool Reoccure)
|
||||
@@ -41,11 +153,11 @@ namespace VoxelIsometricRenderer
|
||||
{
|
||||
switch (Axis)
|
||||
{
|
||||
case 0: PositionX += Increment; break;
|
||||
case 1: PositionY += Increment; break;
|
||||
case 2: PositionZ += Increment; break;
|
||||
case 0: BlockposX += Increment; break;
|
||||
case 1: BlockposY += Increment; break;
|
||||
case 2: BlockposZ += Increment; break;
|
||||
}
|
||||
if (Reoccure) SetPrecisePos(new float[] { (float)PositionX, (float)PositionY, (float)PositionZ },false);
|
||||
if (Reoccure) SetPrecisePos(new float[] { (float)BlockposX, (float)BlockposY, (float)BlockposZ },false);
|
||||
}
|
||||
public static void IncrementPrecisePos(int Axis, float Increment, bool Reoccure)
|
||||
{
|
||||
@@ -61,11 +173,11 @@ namespace VoxelIsometricRenderer
|
||||
{
|
||||
switch (Axis)
|
||||
{
|
||||
case 0:PositionX = Pos; break;
|
||||
case 1: PositionY = Pos; break;
|
||||
case 2: PositionZ = Pos; break;
|
||||
case 0: BlockposX = Pos; break;
|
||||
case 1: BlockposY = Pos; break;
|
||||
case 2: BlockposZ = Pos; break;
|
||||
}
|
||||
if (Reoccure) SetPrecisePos(new float[] { PositionX, PositionY, PositionZ },false);
|
||||
if (Reoccure) SetPrecisePos(new float[] { BlockposX, BlockposY, BlockposZ },false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user