This commit is contained in:
MarcEricMartel
2021-12-07 18:59:50 -05:00
parent 078cb33c27
commit 8e2169420e
16 changed files with 204 additions and 36 deletions

View File

@@ -8,7 +8,7 @@ Engine::Engine() { }
Engine::~Engine() {
m_world.CleanUpWorld(m_renderCount, true);
for (int x = 0; x < WORLD_SIZE_X; ++x) // Les destructeurs de Chunks ont de la mis<69>re, je les aide un peu!
for (int x = 0; x < WORLD_SIZE_X; ++x)
for (int y = 0; y < WORLD_SIZE_Y; ++y)
if (m_world.GetChunks().Get(x, y))
m_world.GetChunks().Get(x, y)->~Chunk();
@@ -45,6 +45,10 @@ void Engine::Init() {
// Objet de musique!
m_audio.ToggleMusicState();
// Array pour les balles.
for (int x = 0; x < MAX_BULLETS; ++x)
m_bullets[x] = nullptr;
// Init Chunks
m_world.GetChunks().Reset(nullptr);
@@ -93,7 +97,7 @@ void Engine::LoadResource() {
void Engine::UnloadResource() {}
void Engine::DrawHud(float elapsedTime) {
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
// Setter le blend function , tout ce qui sera noir sera transparent
glDisable(GL_STENCIL_TEST);
glColor4f(1.f, 1.f, 1.f, 1.f);
@@ -124,6 +128,12 @@ void Engine::DrawHud(float elapsedTime) {
ss.str("");
ss << " Position : " << m_player.GetPosition();
PrintText(10, 30, ss.str());
ss.str("");
ss << " Block : ";
if (bloc == BTYPE_LAST)
ss << "Weapon.";
else ss << (int)bloc;
PrintText(10, 40, ss.str());
m_textureCrosshair.Bind();
static const int crossSize = 32;
glLoadIdentity();
@@ -173,19 +183,26 @@ int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
void Engine::Render(float elapsedTime) {
static float gameTime = elapsedTime;
static float bulletTime = 0;
static BlockType bloc = 1;
if (elapsedTime > 0.1f) return;
gameTime += elapsedTime;
Transformation all;
Transformation skybox;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Transformations initiales
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, m_keylshift, elapsedTime), m_world, elapsedTime);
if (bulletTime > 0.f) bulletTime -= elapsedTime;
if (bulletTime < 0.f) bulletTime = 0.f;
m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), m_world, elapsedTime, &m_audio);
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn<6E>es du joueur et
// son vecteur de v<>locit<69> (pour l'effet Doppler)
m_player.ApplyTransformation(all);
@@ -193,34 +210,64 @@ void Engine::Render(float elapsedTime) {
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
static BlockType bloc = 1;
if (m_mouseWU) bloc++;
else if (m_mouseWD) bloc--;
if (bloc == BTYPE_LAST)
bloc = BTYPE_DIRT;
else if (bloc == BTYPE_AIR)
bloc = BTYPE_LAST - 1;
if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST <20>quipe l'arme.
m_mouseWU = m_mouseWD = false;
if (m_mouseL)
m_world.ChangeBlockAtCursor(bloc, m_player, m_block);
if (m_mouseL) {
if (bloc != BTYPE_LAST)
m_world.ChangeBlockAtCursor(bloc, m_player, m_block);
else if (bulletTime <= 0.f) {
for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
if (!m_bullets[x]) {
m_bullets[x] = new Bullet(m_player);
break;
}
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premi<6D>re balle de l'array.
m_bullets[0]->~Bullet();
m_bullets[0] = new Bullet(m_player);
}
bulletTime = .1f;
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, .5f);
if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
glClearColor(.8f, .8f, .8f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 1.f);
return;
}
}
}
else if (m_mouseR)
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player, m_block);
m_world.Update(m_renderCount, m_badHitCount, m_player, all, m_shader01, m_textureAtlas, m_perlin, m_blockinfo);
for (int x = 0; x < MAX_BULLETS; ++x) // Array de bullets en jeu.
if (m_bullets[x])
if (m_bullets[x]->Update(&m_world, all, elapsedTime)) {
m_bullets[x]->~Bullet();
m_bullets[x] = nullptr;
}
m_world.Update(m_renderCount, m_bullets, m_player, all, m_shader01, m_textureAtlas, m_perlin, m_blockinfo);
if (m_isSkybox) m_skybox.Render(skybox);
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
DrawHud(elapsedTime);
DrawHud(elapsedTime, bloc);
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if (m_player.GetPosition().y < -20.f)
static bool fell = false;
if (m_player.GetPosition().y < 1.7f && !fell) {
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), 1.f);
fell = true;
}
else if (m_player.GetPosition().y < -20.f) {
m_player = Player(Vector3f(0, CHUNK_SIZE_Y + 1.8f, 0)); // Respawn si le bonho- joueur tombe en bas du monde.
fell = false;
}
}
void Engine::KeyPressEvent(unsigned char key) {
@@ -267,6 +314,7 @@ void Engine::KeyPressEvent(unsigned char key) {
m_keySpace = true;
}
break;
case 5: // F - Ignorer
case 24: // Y - Ignorer
case 255: // Fn - Ignorer
case 12: // M - Ignorer
@@ -279,6 +327,9 @@ void Engine::KeyPressEvent(unsigned char key) {
void Engine::KeyReleaseEvent(unsigned char key) {
switch (key) {
case 5:
m_flash = !m_flash;
break;
case 12:
m_audio.ToggleMusicState();
break;