:)
This commit is contained in:
parent
8e222f39a9
commit
de7945038c
@ -42,7 +42,7 @@ void Array3d<T>::Set(int x, int y, int z, T type) {
|
||||
|
||||
template <class T>
|
||||
T Array3d<T>::Get(int x, int y, int z) const { return m_array[To1dIndex(x, y, z)]; }
|
||||
|
||||
|
||||
template <class T>
|
||||
void Array3d<T>::Reset(T type) {
|
||||
for (int i = 0; i < m_x * m_y * m_z; ++i)
|
||||
|
@ -16,12 +16,13 @@
|
||||
#define CHUNK_SIZE_Y 128
|
||||
#define CHUNK_SIZE_Z 16
|
||||
|
||||
#define WORLD_SIZE_X 8
|
||||
#define WORLD_SIZE_Y 8
|
||||
#define WORLD_SIZE_X 128
|
||||
#define WORLD_SIZE_Y 128
|
||||
|
||||
#define VIEW_DISTANCE 128
|
||||
#define FRAMES_RENDER_CHUNKS 2
|
||||
#define FRAMES_UPDATE_CHUNKS 2
|
||||
|
||||
#define VIEW_DISTANCE 128
|
||||
#define MAX_SELECTION_DISTANCE 5
|
||||
|
||||
typedef uint8_t BlockType;
|
||||
|
@ -311,7 +311,7 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
|
||||
if (m_player.GetPosition().y < -20.f)
|
||||
m_player = Player(Vector3f(CHUNK_SIZE_X * WORLD_SIZE_X / 2, CHUNK_SIZE_Y, CHUNK_SIZE_Z * WORLD_SIZE_X / 2)); // Respawn si le bonho- joueur tombe en bas du monde.
|
||||
m_player = Player(Vector3f(CHUNK_SIZE_X * WORLD_SIZE_X / 2, CHUNK_SIZE_Y + 1.7f, CHUNK_SIZE_Z * WORLD_SIZE_X / 2)); // Respawn si le bonho- joueur tombe en bas du monde.
|
||||
}
|
||||
|
||||
void Engine::KeyPressEvent(unsigned char key)
|
||||
@ -516,13 +516,14 @@ void Engine::UpdateWorld(int& generates, int& updates, int chx, int chy) {
|
||||
}
|
||||
|
||||
void Engine::GetBlockAtCursor(BlockType blockType) {
|
||||
Vector3f currentBlock = m_player.GetPosition();
|
||||
Vector3f currentPos = m_player.GetPosition();
|
||||
Vector3f currentBlock = currentPos;
|
||||
Vector3f ray = m_player.GetDirection();
|
||||
bool found = false;
|
||||
|
||||
if (m_block) return;
|
||||
|
||||
while ((m_player.GetPosition() - currentBlock).Length() <= MAX_SELECTION_DISTANCE && !found) {
|
||||
while ((currentPos - currentBlock).Length() <= MAX_SELECTION_DISTANCE && !found) {
|
||||
currentBlock += ray / 10.f;
|
||||
|
||||
BlockType bt = m_world.BlockAt(currentBlock);
|
||||
@ -534,18 +535,34 @@ void Engine::GetBlockAtCursor(BlockType blockType) {
|
||||
if (found) {
|
||||
if (blockType != BTYPE_AIR) {
|
||||
found = false;
|
||||
while ((m_player.GetPosition() - currentBlock).Length() >= .7f && !found) {
|
||||
while ((currentPos - currentBlock).Length() >= 1.7f && !found) {
|
||||
currentBlock -= ray / 10.f;
|
||||
|
||||
BlockType bt = m_world.BlockAt(currentBlock);
|
||||
|
||||
if (bt == BTYPE_AIR)
|
||||
found = true;
|
||||
if (bt == BTYPE_AIR) {
|
||||
int Bx = (int)currentBlock.x;
|
||||
int By = (int)currentBlock.y;
|
||||
int Bz = (int)currentBlock.z;
|
||||
|
||||
int Px = (int)currentPos.x;
|
||||
int PyA = (int)currentPos.y;
|
||||
int PyB = (int)(currentPos.y - .9f);
|
||||
int PyC = (int)(currentPos.y - 1.7f);
|
||||
int Pz = (int)currentPos.z;
|
||||
|
||||
if (!(Bx == Px &&
|
||||
(By == PyA ||
|
||||
By == PyB ||
|
||||
By == PyC) &&
|
||||
Bz == Pz))
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (found && (int)currentBlock.y < CHUNK_SIZE_Y) {
|
||||
int bx = (int)currentBlock.x % CHUNK_SIZE_X;
|
||||
int by = (int)currentBlock.y % CHUNK_SIZE_Y;
|
||||
int bz = (int)currentBlock.z % CHUNK_SIZE_Z;
|
||||
|
@ -59,7 +59,7 @@ private:
|
||||
Shader m_shader01;
|
||||
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
|
||||
|
||||
Player m_player = Player(Vector3f(CHUNK_SIZE_X * WORLD_SIZE_X / 2, CHUNK_SIZE_Y, CHUNK_SIZE_Z * WORLD_SIZE_X / 2));
|
||||
Player m_player = Player(Vector3f(CHUNK_SIZE_X * WORLD_SIZE_X / 2, CHUNK_SIZE_Y + 1.7f, CHUNK_SIZE_Z * WORLD_SIZE_X / 2));
|
||||
|
||||
bool m_keyW = false;
|
||||
bool m_keyA = false;
|
||||
|
@ -69,7 +69,7 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
bt1 = world.BlockAt(m_position.x, m_position.y + input.y, m_position.z);
|
||||
bt2 = world.BlockAt(m_position.x, m_position.y + input.y - 0.9f, m_position.z);
|
||||
bt3 = world.BlockAt(m_position.x, m_position.y + input.y - 1.7f, m_position.z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
if ((bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) && m_position.y < 129.7f) {
|
||||
bt1 = world.BlockAt(m_position.x, m_position.y + .3f, m_position.z);
|
||||
if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f;
|
||||
m_velocity.y = input.y = 0;
|
||||
|
@ -23,7 +23,6 @@ class World {
|
||||
|
||||
private:
|
||||
Array2d<Chunk*> m_chunks = Array2d<Chunk*>(WORLD_SIZE_X, WORLD_SIZE_Y);
|
||||
Array2d<Chunk*> m_buffer = Array2d<Chunk*>(WORLD_SIZE_X, WORLD_SIZE_Y);
|
||||
|
||||
unsigned int m_center[2] = {UINT16_MAX / 2, UINT16_MAX / 2};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user