diff --git a/SQCSim2021/array3d.h b/SQCSim2021/array3d.h index 1b4d13f..97603ef 100644 --- a/SQCSim2021/array3d.h +++ b/SQCSim2021/array3d.h @@ -42,7 +42,7 @@ void Array3d::Set(int x, int y, int z, T type) { template T Array3d::Get(int x, int y, int z) const { return m_array[To1dIndex(x, y, z)]; } - + template void Array3d::Reset(T type) { for (int i = 0; i < m_x * m_y * m_z; ++i) diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index 3848707..ad3e097 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -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; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 99af690..1bbfbf0 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -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; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index a5b4ddd..93df26d 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -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; diff --git a/SQCSim2021/player.cpp b/SQCSim2021/player.cpp index 7d064e7..9e8c846 100644 --- a/SQCSim2021/player.cpp +++ b/SQCSim2021/player.cpp @@ -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; diff --git a/SQCSim2021/world.h b/SQCSim2021/world.h index 7d27412..69c8689 100644 --- a/SQCSim2021/world.h +++ b/SQCSim2021/world.h @@ -23,7 +23,6 @@ class World { private: Array2d m_chunks = Array2d(WORLD_SIZE_X, WORLD_SIZE_Y); - Array2d m_buffer = Array2d(WORLD_SIZE_X, WORLD_SIZE_Y); unsigned int m_center[2] = {UINT16_MAX / 2, UINT16_MAX / 2}; };