This commit is contained in:
MarcEricMartel 2021-11-27 14:14:05 -05:00
parent 8e222f39a9
commit de7945038c
6 changed files with 31 additions and 14 deletions

View File

@ -16,12 +16,13 @@
#define CHUNK_SIZE_Y 128 #define CHUNK_SIZE_Y 128
#define CHUNK_SIZE_Z 16 #define CHUNK_SIZE_Z 16
#define WORLD_SIZE_X 8 #define WORLD_SIZE_X 128
#define WORLD_SIZE_Y 8 #define WORLD_SIZE_Y 128
#define VIEW_DISTANCE 128
#define FRAMES_RENDER_CHUNKS 2 #define FRAMES_RENDER_CHUNKS 2
#define FRAMES_UPDATE_CHUNKS 2 #define FRAMES_UPDATE_CHUNKS 2
#define VIEW_DISTANCE 128
#define MAX_SELECTION_DISTANCE 5 #define MAX_SELECTION_DISTANCE 5
typedef uint8_t BlockType; typedef uint8_t BlockType;

View File

@ -311,7 +311,7 @@ void Engine::Render(float elapsedTime) {
if (m_player.GetPosition().y < -20.f) 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) 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) { void Engine::GetBlockAtCursor(BlockType blockType) {
Vector3f currentBlock = m_player.GetPosition(); Vector3f currentPos = m_player.GetPosition();
Vector3f currentBlock = currentPos;
Vector3f ray = m_player.GetDirection(); Vector3f ray = m_player.GetDirection();
bool found = false; bool found = false;
if (m_block) return; 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; currentBlock += ray / 10.f;
BlockType bt = m_world.BlockAt(currentBlock); BlockType bt = m_world.BlockAt(currentBlock);
@ -534,18 +535,34 @@ void Engine::GetBlockAtCursor(BlockType blockType) {
if (found) { if (found) {
if (blockType != BTYPE_AIR) { if (blockType != BTYPE_AIR) {
found = false; found = false;
while ((m_player.GetPosition() - currentBlock).Length() >= .7f && !found) { while ((currentPos - currentBlock).Length() >= 1.7f && !found) {
currentBlock -= ray / 10.f; currentBlock -= ray / 10.f;
BlockType bt = m_world.BlockAt(currentBlock); BlockType bt = m_world.BlockAt(currentBlock);
if (bt == BTYPE_AIR) 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; found = true;
} }
} }
} }
}
if (found) { if (found && (int)currentBlock.y < CHUNK_SIZE_Y) {
int bx = (int)currentBlock.x % CHUNK_SIZE_X; int bx = (int)currentBlock.x % CHUNK_SIZE_X;
int by = (int)currentBlock.y % CHUNK_SIZE_Y; int by = (int)currentBlock.y % CHUNK_SIZE_Y;
int bz = (int)currentBlock.z % CHUNK_SIZE_Z; int bz = (int)currentBlock.z % CHUNK_SIZE_Z;

View File

@ -59,7 +59,7 @@ private:
Shader m_shader01; Shader m_shader01;
Audio m_audio = Audio(AUDIO_PATH "music01.wav"); 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_keyW = false;
bool m_keyA = false; bool m_keyA = false;

View File

@ -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); 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); 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); 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); 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; if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f;
m_velocity.y = input.y = 0; m_velocity.y = input.y = 0;

View File

@ -23,7 +23,6 @@ class World {
private: private:
Array2d<Chunk*> m_chunks = Array2d<Chunk*>(WORLD_SIZE_X, WORLD_SIZE_Y); 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}; unsigned int m_center[2] = {UINT16_MAX / 2, UINT16_MAX / 2};
}; };