TOUT FONCTIONNE!

This commit is contained in:
MarcEricMartel 2021-11-16 20:48:52 -05:00
parent aa1d19d93d
commit b12e5599be
8 changed files with 124 additions and 303 deletions

View File

@ -166,6 +166,9 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp17</LanguageStandard>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -185,6 +188,9 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp17</LanguageStandard>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@ -40,6 +40,10 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v
sound->setVolume(volume);
}
void Audio::PlaySong(const char* music) {
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
}
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }

View File

@ -22,6 +22,8 @@ public:
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
void PlaySong(const char* music);
void ToggleMusicState();
void PauseEngine();

View File

@ -47,87 +47,48 @@ void Engine::Init()
// Objet de musique!
m_audio.ToggleMusicState();
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_copychunk.SetBlock(x, y, z, BTYPE_GRASS);
m_copychunk.SetBlock(5, 32, 15, BTYPE_GRASS);
m_copychunk.SetBlock(5, 33, 15, BTYPE_GRASS);
m_copychunk.SetBlock(5, 34, 15, BTYPE_GRASS);
m_copychunk.SetBlock(6, 34, 15, BTYPE_GRASS);
m_copychunk.SetBlock(7, 34, 15, BTYPE_GRASS);
m_copychunk.SetBlock(7, 33, 15, BTYPE_GRASS);
m_copychunk.SetBlock(7, 32, 15, BTYPE_GRASS);
m_copychunk.SetBlock(8, 32, 3, BTYPE_GRASS);
m_copychunk.SetBlock(8, 33, 4, BTYPE_GRASS);
m_copychunk.SetBlock(8, 34, 5, BTYPE_GRASS);
m_copychunk.SetBlock(8, 35, 6, BTYPE_GRASS);
m_copychunk.SetBlock(11, 32, 5, BTYPE_GRASS);
m_copychunk.SetBlock(11, 33, 5, BTYPE_GRASS);
m_copychunk.SetBlock(11, 34, 5, BTYPE_GRASS);
m_copychunk.SetBlock(11, 35, 5, BTYPE_GRASS);
m_copychunk.SetBlock(12, 32, 5, BTYPE_GRASS);
m_copychunk.SetBlock(12, 33, 5, BTYPE_GRASS);
m_copychunk.SetBlock(12, 34, 5, BTYPE_GRASS);
m_copychunk.SetBlock(12, 35, 5, BTYPE_GRASS);
m_copychunk.SetBlock(13, 32, 5, BTYPE_GRASS);
m_copychunk.SetBlock(13, 33, 5, BTYPE_GRASS);
m_copychunk.SetBlock(13, 34, 5, BTYPE_GRASS);
m_copychunk.SetBlock(13, 35, 5, BTYPE_GRASS);
m_copychunk.SetBlock(14, 32, 5, BTYPE_GRASS);
m_copychunk.SetBlock(14, 33, 5, BTYPE_GRASS);
m_copychunk.SetBlock(14, 34, 5, BTYPE_GRASS);
m_copychunk.SetBlock(14, 35, 5, BTYPE_GRASS);
// Init Chunks
for (int chx = 0; chx < VIEW_DISTANCE; ++chx)
for (int chy = 0; chy < VIEW_DISTANCE; ++chy)
m_world.GetChunks().Set(chx, chy, &m_copychunk);
m_world.GetChunks().Set(chx, chy, new Chunk(chx, chy));
// Init Chunks
//for (int chx = 0; chx < VIEW_DISTANCE; ++chx)
// for (int chy = 0; chy < VIEW_DISTANCE; ++chy)
// m_world.GetChunks().Set(chx, chy, new Chunk(chx, chy));
// Génération Chunks.
for (int chx = 0; chx < VIEW_DISTANCE; ++chx)
for (int chy = 0; chy < VIEW_DISTANCE; ++chy) {
// // Génération Chunks.
// for (int chx = 0; chx < VIEW_DISTANCE; ++chx)
// for (int chy = 0; chy < VIEW_DISTANCE; ++chy) {
// 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, ((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);
// m_world.GetChunks().Get(chx, chy)->SetBlock(5, 34, 15, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(6, 34, 15, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(7, 34, 15, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(7, 33, 15, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(7, 32, 15, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(8, 32, 3, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(8, 33, 4, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(8, 34, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(8, 35, 6, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(11, 32, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(11, 33, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(11, 34, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(11, 35, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(12, 32, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(12, 33, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(12, 34, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(12, 35, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(13, 32, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(13, 33, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(13, 34, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(13, 35, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(14, 32, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(14, 33, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(14, 34, 5, BTYPE_GRASS);
// m_world.GetChunks().Get(chx, chy)->SetBlock(14, 35, 5, BTYPE_GRASS);
// }
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, ((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);
m_world.GetChunks().Get(chx, chy)->SetBlock(5, 34, 15, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(6, 34, 15, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(7, 34, 15, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(7, 33, 15, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(7, 32, 15, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(8, 32, 3, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(8, 33, 4, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(8, 34, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(8, 35, 6, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(11, 32, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(11, 33, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(11, 34, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(11, 35, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(12, 32, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(12, 33, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(12, 34, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(12, 35, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(13, 32, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(13, 33, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(13, 34, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(13, 35, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(14, 32, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(14, 33, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(14, 34, 5, BTYPE_GRASS);
m_world.GetChunks().Get(chx, chy)->SetBlock(14, 35, 5, BTYPE_GRASS);
}
// Gestion de souris.
CenterMouse();
@ -204,7 +165,7 @@ void Engine::DrawHud(float elapsedTime) {
ss << " Position : " << m_player.GetPosition();
PrintText(10, 30, ss.str());
ss.str("");
ss << " Delta : " << m_player.GetPOV();
ss << " CamPos : " << m_player.GetPOV();
PrintText(10, 40, ss.str());
// Affichage du crosshair
m_textureCrosshair.Bind();
@ -301,7 +262,7 @@ void Engine::Render(float elapsedTime) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if (m_player.GetPosition().y < -10.f) m_player = Player(Vector3f(64, 34, 64));
if (m_player.GetPosition().y < -10.f) m_player = Player(Vector3f(64, 34, 64)); // Respawn si le bonho- joueur tombe en bas du monde.
}
void Engine::KeyPressEvent(unsigned char key)

View File

@ -61,8 +61,6 @@ private:
bool m_keylshift = false;
bool m_keySpace = false;
};
#endif // ENGINE_H__

View File

@ -2,7 +2,6 @@
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
m_velocity = Vector3f(0, 0, 0);
m_dbljump = 0;
m_airborne = true;
}
@ -20,186 +19,51 @@ void Player::TurnTopBottom(float value) {
Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime) {
static float yrotrad = 0;
static float xrotrad = 0;
static float dashtimeout = 0;
Vector3f delta = Vector3f(0, 0, 0);
m_direction = Vector3f(cos(m_rotY / 57.2957795056f) * cos(m_rotX / 57.2957795056f),
-sin(m_rotX / 57.2957795056f),
sin(m_rotY / 57.2957795056f) * cos(m_rotX / 57.2957795056f));
float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
float xrotrad = (m_rotX / 57.2957795056f);
if ((jump || dash) && !m_airborne) {
delta.y += jump ? m_jumpforce : 0.1f;
m_direction = Vector3f(cos(yrotrad) * cos(xrotrad),
-sin(xrotrad),
sin(yrotrad) * cos(xrotrad));
if (front) {
delta.x += float(sin(yrotrad)) * elapsedTime * 10.f;
delta.z += float(-cos(yrotrad)) * elapsedTime * 10.f;
}
else if (back) {
delta.x -= float(-sin(yrotrad)) * elapsedTime * -10.f;
delta.z -= float(cos(yrotrad)) * elapsedTime * -10.f;
}
if (left) {
delta.x += float(-cos(yrotrad)) * elapsedTime * 10.f;
delta.z += float(-sin(yrotrad)) * elapsedTime * 10.f;
}
else if (right) {
delta.x -= float(cos(yrotrad)) * elapsedTime * -10.f;
delta.z -= float(sin(yrotrad)) * elapsedTime * -10.f;
}
delta.Normalize();
delta.x *= .6f;
delta.z *= .6f;
if (jump && !m_airborne) {
delta.y += .32f;
m_airborne = true;
}
if (dashtimeout > 0.f) { // Gestion du timeout de dash pour ne pas pouvoir spammer le dash.
dash = false;
dashtimeout -= elapsedTime;
}
else dashtimeout = 0;
if (dash) dashtimeout = 2;
if ((!m_airborne && (left || right || front || back)) ||
(dash && !(left || right || front || back))) {
yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
xrotrad = (m_rotX / 57.2957795056f);
if (dash) {
delta.x += float(sin(yrotrad)) * elapsedTime * 20.f;
delta.z += float(-cos(yrotrad)) * elapsedTime * 20.f;
}
}
if (!m_airborne) {
if (front) {
delta.x += float(sin(yrotrad)) * elapsedTime * 10.f;
delta.z += float(-cos(yrotrad)) * elapsedTime * 10.f;
}
else if (back) {
delta.x -= float(-sin(yrotrad)) * elapsedTime * -10.f;
delta.z -= float(cos(yrotrad)) * elapsedTime * -10.f;
}
if (left) {
delta.x += float(-cos(yrotrad)) * elapsedTime * 10.f;
delta.z += float(-sin(yrotrad)) * elapsedTime * 10.f;
}
else if (right) {
delta.x -= float(cos(yrotrad)) * elapsedTime * -10.f;
delta.z -= float(sin(yrotrad)) * elapsedTime * -10.f;
}
}
return delta;
}
//
//Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime) {
// static float accWS = 0;
// static float accAD = 0;
// static float yrotrad = 0;
// static float xrotrad = 0;
// static float dashtimeout = 0;
//
// Vector3f movepos = m_velocity;
//
// m_direction = Vector3f(cos(m_rotY / 57.2957795056f) * cos(m_rotX / 57.2957795056f),
// -sin(m_rotX / 57.2957795056f),
// sin(m_rotY / 57.2957795056f) * cos(m_rotX / 57.2957795056f));
//
// if (dashtimeout > 0.f) { // Gestion du timeout de dash pour ne pas pouvoir spammer le dash.
// dash = false;
// dashtimeout -= elapsedTime;
// }
// else dashtimeout = 0;
// if (dash) dashtimeout = 2;
//
// if (m_airborne && !jump) m_airborne = false; // Anti-rebondissement du saut, pour pouvoir rebondir.
//
// if (m_dbljump >= 2) jump = false;
//
// if ((jump || dash) && !m_airborne ) {
// m_velocity.y += jump? m_jumpforce: 0.1f;
// movepos.y += m_velocity.y;
// m_airborne = true;
// m_dbljump++;
// }
//
// if ((m_dbljump < 1 && ( left || right || front || back)) ||
// (dash && !(left || right || front || back)) ) {
// yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
// xrotrad = (m_rotX / 57.2957795056f);
// if (dash) accWS = m_topspeed; // Pour avoir un boost de vitesse vers l'avant si le dash est appuyé seul.
// }
//
// if (front) {
// if (m_dbljump == 0)
// if (accWS < m_topspeed) accWS += elapsedTime * 30; else accWS = m_topspeed;
// if (dash) accWS *= accWS > 0.f ? 3.f : -1.f;
// m_velocity.x = float(sin(yrotrad)) * elapsedTime * accWS;
// movepos.x += m_velocity.x;
// m_velocity.z = float(-cos(yrotrad)) * elapsedTime * accWS;
// movepos.z += m_velocity.z;
// }
// else if (back) {
// if (m_dbljump == 0)
// if (accWS > -m_topspeed) accWS -= elapsedTime * 30; else accWS = -m_topspeed;
// if (dash) accWS *= accWS < 0.f? 3.f: -1.f;
// m_velocity.x = float(-sin(yrotrad)) * elapsedTime * -accWS;
// movepos.x += m_velocity.x;
// m_velocity.z = float(cos(yrotrad)) * elapsedTime * -accWS;
// movepos.z += m_velocity.z;
// }
// else if (accWS != 0) {
// accWS = accWS > 0 ? accWS - elapsedTime * (m_position.y > 0.1f ? 10 : 120)
// : accWS + elapsedTime * (m_position.y > 0.1f ? 10 : 120);
//
// m_velocity.x = float(sin(yrotrad)) * elapsedTime * accWS;
// movepos.x += m_velocity.x;
// m_velocity.z = float(-cos(yrotrad)) * elapsedTime * accWS;
// movepos.z += m_velocity.z;
// if (accWS < 1 && accWS > -1) accWS = 0;
// }
//
// if (left) {
// if (m_dbljump == 0)
// if (accAD < m_topspeed) accAD += elapsedTime * 30; else accAD = m_topspeed;
// if (dash) accAD *= accAD > 0.f? 3.f: -1.f;
// m_velocity.x = float(-cos(yrotrad)) * elapsedTime * accAD;
// movepos.x += m_velocity.x;
// m_velocity.z = float(-sin(yrotrad)) * elapsedTime * accAD;
// movepos.z += m_velocity.z;
// }
// else if (right) {
// if (m_dbljump == 0)
// if (accAD > -m_topspeed) accAD -= elapsedTime * 30; else accAD = -m_topspeed;
// if (dash) accAD *= accAD < 0.f ? 3.f : -1.f;
// m_velocity.x = float(cos(yrotrad)) * elapsedTime * -accAD;
// movepos.x += m_velocity.x;
// m_velocity.z = float(sin(yrotrad)) * elapsedTime * -accAD;
// movepos.z += m_velocity.z;
// }
// else if (accAD != 0) {
// accAD = accAD > 0 ? accAD - elapsedTime * (m_position.y > 0.1f ? 10 : 120)
// : accAD + elapsedTime * (m_position.y > 0.1f ? 10 : 120);
//
// m_velocity.x = float(-cos(yrotrad)) * elapsedTime * accAD;
// movepos.x += m_velocity.x;
// m_velocity.z = float(-sin(yrotrad)) * elapsedTime * accAD;
// movepos.z += m_velocity.z;
// if (accAD < 1.f && accAD > -1.f) accAD = 0;
// }
//
// // Gestion de si le personnage va en diagonale, qu'il n'aille pas plus vite que s'il allait en ligne droite.
// if (abs(accAD) + abs(accWS) > sqrtf(exp2f(m_topspeed) * 2)) {
// accWS *= 0.8f;
// accAD *= 0.8f;
// }
//
// return movepos;
//}
void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
/* Gestion de collisions */
/* Gestion de collisions */
BlockType bt1, bt2, bt3;
if (m_velocity.x * m_velocity.x + m_velocity.z * m_velocity.z >= .005f) {
m_velocity.x *= 0.9f;
m_velocity.z *= 0.9f;
}
if (!m_airborne) {
m_velocity.x = input.x ? m_velocity.x + input.x * 4.f * elapsedTime : -.1f * m_velocity.x * elapsedTime;
m_velocity.z = input.z ? m_velocity.z + input.z * 4.f * elapsedTime : -.1f * m_velocity.z * elapsedTime;
}
else {
m_velocity.x += -.1f * m_velocity.x * elapsedTime;
m_velocity.z += -.1f * m_velocity.x * 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);
@ -212,54 +76,80 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
else {
if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime;
bt3 = world.BlockAt(m_position.x, m_position.y + m_velocity.y - 1.7f, m_position.z);
bt1 = world.BlockAt(m_position.x, m_position.y + .3f, m_position.z);
if (bt3 != BTYPE_AIR) {
m_velocity.y = 0;
m_airborne = false;
}
else if (bt1 != BTYPE_AIR) {
m_velocity.y = -.1f;
}
else m_airborne = true;
}
bt1 = world.BlockAt(m_position.x + input.x, m_position.y, m_position.z);
bt2 = world.BlockAt(m_position.x + input.x, m_position.y - 0.9f, m_position.z);
bt3 = world.BlockAt(m_position.x + input.x, m_position.y - 1.7f, m_position.z);
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
input.x = 0;
m_velocity.x = 0;
input.x = m_velocity.x = 0;
m_velocity.z *= .5f;
}
bt1 = world.BlockAt(m_position.x, m_position.y, m_position.z + input.z);
bt2 = world.BlockAt(m_position.x, m_position.y - 0.9f, m_position.z + input.z);
bt3 = world.BlockAt(m_position.x, m_position.y - 1.7f, m_position.z + input.z);
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
input.z = 0;
m_velocity.z = 0;
input.z = m_velocity.z = 0;
m_velocity.x *= .5f;
}
/* Fin gestion de collisions */
/* Gestion de la friction */
if (!m_airborne) {
m_velocity.x += input.x * 2.f * elapsedTime;
m_velocity.z += input.z * 2.f * elapsedTime;
if (input.x == 0.f)
m_velocity.x *= .6f;
if (input.z == 0.f)
m_velocity.z *= .6f;
}
else {
m_velocity.x += input.x * .4f * elapsedTime; // Techniquement contre les lois de la physique, mais c'est beaucoup moins chiant pour grimper sur les blocs.
m_velocity.z += input.z * .4f * elapsedTime;
m_velocity.x *= .99f;
m_velocity.z *= .99f;
}
/* Fin gestion de la friction */
float vy = m_velocity.y;
m_velocity.y = 1.f; // Padding pour limiter le x et z lors du Normalize().
if (m_velocity.Length() >= 1.f) m_velocity.Normalize(); // Limiteur de vitesse en x/z.
m_velocity.y = 0;
if (m_velocity.Length() < .005f) m_velocity.Zero(); // Threshold en x/z.
m_velocity.y = vy;
m_position += m_velocity;
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));
if (bobbingtime <= 360.f) bobbingtime += elapsedTime * 20.f; else bobbingtime = 0;
m_POV = m_position.y;
m_POV += m_airborne ? 0 : (sin(bobbingtime) - 0.5f) * (abs(m_velocity.x) + abs(m_velocity.z)) * .2f;
}
void Player::ApplyTransformation(Transformation& transformation, bool rel) const {
transformation.ApplyRotation(-m_rotX, 1, 0, 0);
transformation.ApplyRotation(-m_rotY, 0, 1, 0);
if (rel) transformation.ApplyTranslation(-m_position);
if (rel) transformation.ApplyTranslation(-m_position.x,-m_POV,-m_position.z);
}
Vector3f Player::GetPosition() const { return m_position; }
Vector3f Player::GetVelocity() const { return m_velocity; }
Vector3f Player::GetPOV() const
{
return m_POV;
}
Vector3f Player::GetPOV() const { return Vector3f(m_position.x, m_POV, m_position.z); }
Vector3f Player::GetDirection() const { return m_direction; }

View File

@ -21,18 +21,14 @@ public:
private:
Vector3f m_position;
Vector3f m_POV;
Vector3f m_velocity;
Vector3f m_direction;
float m_rotX = 0;
float m_rotY = 0;
float m_topspeed = 20;
float m_jumpforce = 0.3f;
float m_POV;
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__

View File

@ -25,41 +25,5 @@ private:
int m_center[2] = {0, 0};
};
//
//template <class T>
//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 <class T>
//Chunk* World::ChunkAt(const Vector3<T>& pos) const { return ChunkAt(pos.x, pos.y, pos.z); }
//
//template <class T>
//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 <class T>
//BlockType World::BlockAt(const Vector3<T>& pos, BlockType defaultBlockType) const {
// return BlockAt(pos.x, pos.y, pos.z);
//}
#endif
#endif // WORLD_H__