diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj
index e88b06c..d2a7654 100644
--- a/SQCSim2021/SQCSim2021.vcxproj
+++ b/SQCSim2021/SQCSim2021.vcxproj
@@ -68,13 +68,13 @@
Application
true
Unicode
- ClangCL
+ v142
Application
true
Unicode
- ClangCL
+ v142
Application
diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp
index 6815f1d..16c2c34 100644
--- a/SQCSim2021/engine.cpp
+++ b/SQCSim2021/engine.cpp
@@ -96,7 +96,7 @@ void Engine::Init()
// for (int x = 0; x < CHUNK_SIZE_X; ++x)
// for (int z = 0; z < CHUNK_SIZE_Z; ++z)
// for (int y = 0; y < 32; ++y)
- // m_world.GetChunks().Get(chx, chy)->SetBlock(x, y, z, BTYPE_GRASS);
+ // m_world.GetChunks().Get(chx, chy)->SetBlock(x, y, z, ((chx + chy) % (BTYPE_LAST - 1)) + 1);
// m_world.GetChunks().Get(chx, chy)->SetBlock(5, 32, 15, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(5, 33, 15, BTYPE_GRASS);
@@ -126,8 +126,6 @@ void Engine::Init()
// m_world.GetChunks().Get(chx, chy)->SetBlock(14, 34, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(14, 35, 5, BTYPE_GRASS);
- // //m_world.GetChunks().Get(chx, chy)->SetBlock(8, chx + 32, 8, BTYPE_DIRT);
-
// }
@@ -302,6 +300,8 @@ void Engine::Render(float elapsedTime) {
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
+ if (m_player.GetPosition().y < -10.f) m_player = Player(Vector3f(64, 64, 64));
}
void Engine::KeyPressEvent(unsigned char key)
diff --git a/SQCSim2021/player.cpp b/SQCSim2021/player.cpp
index 2ce8e4b..7919547 100644
--- a/SQCSim2021/player.cpp
+++ b/SQCSim2021/player.cpp
@@ -30,11 +30,12 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
-sin(m_rotX / 57.2957795056f),
sin(m_rotY / 57.2957795056f) * cos(m_rotX / 57.2957795056f));
- if (m_airborne && !jump) m_airborne = false; // Anti-rebondissement du saut, pour pouvoir rebondir.
+ //if (m_airborne && !jump) m_airborne = false; // Anti-rebondissement du saut, pour pouvoir rebondir.
if ((jump || dash) && !m_airborne) {
delta.y += jump ? m_jumpforce : 0.01f;
m_airborne = true;
+ //m_jumped = true;
m_dbljump++;
}
@@ -201,7 +202,7 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
if (!m_airborne) m_position.y = (int)m_position.y + .7f;
m_airborne = false;
}
- else {
+ else if (m_airborne) {
if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime;
m_airborne = true;
}
@@ -223,14 +224,13 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
/* Fin gestion de collisions */
m_position += input;
- m_POV = input;
- m_position.y += m_velocity.y;
+ if (m_airborne) m_position.y += m_velocity.y;
- //static float bobbingtime = 0; // Gestion de la caméra
- //if (bobbingtime <= 360.f) bobbingtime += elapsedTime * m_topspeed / 2; else bobbingtime = 0;
- //m_POV.x = m_position.x;
- //m_POV.z = m_position.z;
- //m_POV.y = m_position.y - 1.7f + m_airborne ? 0 : ((sin(bobbingtime) - 0.5f) * (abs(m_velocity.x * 40) + abs(m_velocity.z * 40)) / (10.f * m_topspeed));
+ static float bobbingtime = 0; // Gestion de la caméra
+ if (bobbingtime <= 360.f) bobbingtime += elapsedTime * m_topspeed / 2; else bobbingtime = 0;
+ m_POV.x = m_position.x;
+ m_POV.z = m_position.z;
+ m_POV.y = m_position.y - 1.7f + m_airborne ? 0 : ((sin(bobbingtime) - 0.5f) * (abs(m_velocity.x * 40) + abs(m_velocity.z * 40)) / (10.f * m_topspeed));
}
void Player::ApplyTransformation(Transformation& transformation, bool rel) const {
diff --git a/SQCSim2021/player.h b/SQCSim2021/player.h
index 0ec5ccf..8797d6f 100644
--- a/SQCSim2021/player.h
+++ b/SQCSim2021/player.h
@@ -31,6 +31,7 @@ private:
float m_jumpforce = 0.3f;
bool m_airborne;
+ bool m_jumped;
int m_dbljump; // Peut sauter ou dasher tant que la variable est en dessous de 2.
};
#endif //_PLAYER_H__
diff --git a/SQCSim2021/world.cpp b/SQCSim2021/world.cpp
index ef86ad3..22eda96 100644
--- a/SQCSim2021/world.cpp
+++ b/SQCSim2021/world.cpp
@@ -5,3 +5,34 @@ World::World(){}
World::~World(){}
Array2d& World::GetChunks() { return m_chunks; }
+
+Chunk* World::ChunkAt(float x, float y, float z) const {
+ int cx = (int)x / CHUNK_SIZE_X;
+ int cz = (int)z / CHUNK_SIZE_Z;
+
+ if (cx >= VIEW_DISTANCE || // L'array en ce moment est de VIEW_DISTANCE par VIEW_DISTANCE.
+ cz >= VIEW_DISTANCE ||
+ cx < 0 || cz < 0)
+ return 0;
+
+ return m_chunks.Get(cx, cz);
+}
+
+Chunk* World::ChunkAt(const Vector3f& pos) const { return ChunkAt(pos.x, pos.y, pos.z); }
+
+BlockType World::BlockAt(float x, float y, float z, BlockType defaultBlockType) const {
+ Chunk* c = ChunkAt(x, y, z);
+
+ if (!c)
+ return defaultBlockType;
+
+ int bx = (int)x % CHUNK_SIZE_X;
+ int by = (int)y % CHUNK_SIZE_Y;
+ int bz = (int)z % CHUNK_SIZE_Z;
+
+ return c->GetBlock(bx, by, bz);
+}
+
+BlockType World::BlockAt(const Vector3f& pos, BlockType defaultBlockType) const {
+ return BlockAt(pos.x, pos.y, pos.z, defaultBlockType);
+}
diff --git a/SQCSim2021/world.h b/SQCSim2021/world.h
index 19be21e..6a03554 100644
--- a/SQCSim2021/world.h
+++ b/SQCSim2021/world.h
@@ -13,45 +13,53 @@ class World {
Array2d& GetChunks();
- template
- Chunk* World::ChunkAt(T x, T y, T z) const {
- int cx = (int)x / CHUNK_SIZE_X;
- int cz = (int)z / CHUNK_SIZE_Z;
-
- if (cx >= VIEW_DISTANCE || // L'array en ce moment est de VIEW_DISTANCE par VIEW_DISTANCE.
- cz >= VIEW_DISTANCE ||
- cx < 0 || cz < 0)
- return 0;
+ Chunk* ChunkAt(float x, float y, float z) const;
+ Chunk* ChunkAt(const Vector3f& pos) const;
- return m_chunks.Get(cx, cz);
- }
-
- template
- Chunk* World::ChunkAt(const Vector3& pos) const { return ChunkAt(pos.x, pos.y, pos.z); }
-
- template
- BlockType World::BlockAt(T x, T y, T z, BlockType defaultBlockType = BTYPE_AIR) const {
- Chunk* c = ChunkAt(x, y, z);
-
- if (!c)
- return defaultBlockType;
-
- int bx = (int)x % CHUNK_SIZE_X;
- int by = (int)y % CHUNK_SIZE_Y;
- int bz = (int)z % CHUNK_SIZE_Z;
-
- return c->GetBlock(bx, by, bz);
- }
-
- template
- BlockType World::BlockAt(Vector3& pos, BlockType defaultBlockType = BTYPE_AIR) const {
- return BlockAt(pos.x, pos.y, pos.z);
- }
+
+ BlockType BlockAt(float x, float y, float z, BlockType defaultBlockType = BTYPE_AIR) const;
+ BlockType BlockAt(const Vector3f& pos, BlockType defaultBlockType = BTYPE_AIR) const;
private:
Array2d m_chunks = Array2d(VIEW_DISTANCE, VIEW_DISTANCE);
int m_center[2] = {0, 0};
};
+//
+//template
+//Chunk* World::ChunkAt(T x, T y, T z) const {
+// int cx = (int)x / CHUNK_SIZE_X;
+// int cz = (int)z / CHUNK_SIZE_Z;
+//
+// if (cx >= VIEW_DISTANCE || // L'array en ce moment est de VIEW_DISTANCE par VIEW_DISTANCE.
+// cz >= VIEW_DISTANCE ||
+// cx < 0 || cz < 0)
+// return 0;
+//
+// return m_chunks.Get(cx, cz);
+//}
+//
+//template
+//Chunk* World::ChunkAt(const Vector3& pos) const { return ChunkAt(pos.x, pos.y, pos.z); }
+//
+//template
+//BlockType World::BlockAt(T x, T y, T z, BlockType defaultBlockType) const {
+// Chunk* c = ChunkAt(x, y, z);
+//
+// if (!c)
+// return defaultBlockType;
+//
+// int bx = (int)x % CHUNK_SIZE_X;
+// int by = (int)y % CHUNK_SIZE_Y;
+// int bz = (int)z % CHUNK_SIZE_Z;
+//
+// return c->GetBlock(bx, by, bz);
+//}
+//
+//template
+//BlockType World::BlockAt(const Vector3& pos, BlockType defaultBlockType) const {
+// return BlockAt(pos.x, pos.y, pos.z);
+//}
+
#endif