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

@@ -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;