Merge branch 'master' into SQC-15_paquets

This commit is contained in:
MarcEricMartel 2023-11-13 16:51:27 -05:00
commit 71852738c1
4 changed files with 89 additions and 3 deletions

View File

@ -16,6 +16,9 @@ void World::SetSeed(uint64_t seed) {
m_seed = seed;
}
Chunk* World::ChunkAt(float x, float y, float z) const {
int cx = (int)x / CHUNK_SIZE_X;
int cz = (int)z / CHUNK_SIZE_Z;
@ -31,6 +34,24 @@ Chunk* World::ChunkAt(float x, float y, float z) const {
Chunk* World::ChunkAt(const Vector3f& pos) const { return ChunkAt(pos.x, pos.y, pos.z); }
void World::RemoveChunk(int nbReduit)
{
for (int x = 0; x < WORLD_SIZE_X; ++x)
for (int y = 0; y < WORLD_SIZE_Y; ++y)
{
if (x < nbReduit)
m_chunks.Remove(x,y);
if (y < nbReduit)
m_chunks.Remove(x, y);
if (y > WORLD_SIZE_Y - nbReduit)
m_chunks.Remove(x, y);
if (x > WORLD_SIZE_X - nbReduit)
m_chunks.Remove(x, y);
}
}
BlockType World::BlockAt(float x, float y, float z, BlockType defaultBlockType) const {
Chunk* c = ChunkAt(x, y, z);

View File

@ -28,6 +28,8 @@ public:
Chunk* ChunkAt(float x, float y, float z) const;
Chunk* ChunkAt(const Vector3f& pos) const;
void RemoveChunk(int nbReduit);
BlockType BlockAt(float x, float y, float z, BlockType defaultBlockType = BTYPE_AIR) const;
BlockType BlockAt(const Vector3f& pos, BlockType defaultBlockType = BTYPE_AIR) const;

View File

@ -275,6 +275,45 @@ void Engine::DrawMenu()
ShowCursor();
}
void Engine::DrawPause()
{
static const int sTitle = 400;
static const int sButton = 225;
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, Width(), 0, Height(), -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
PauseBGTexture.Bind();
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(1, 0);
glVertex2i(800, 0);
glTexCoord2f(1, 1);
glVertex2i(800, 600);
glTexCoord2f(0, 1);
glVertex2i(0, 600);
glEnd();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
ShowCursor();
}
void Engine::Init() {
@ -397,10 +436,12 @@ void Engine::LoadResource() {
LoadTexture(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
LoadTexture(PauseBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png");
LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png");
LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png");
LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png");
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
@ -890,7 +931,11 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
glPushMatrix();
int timer = GetCountdown(elapsedTime);
for (int i = 1; i < WORLD_SIZE_X; i++)
{
if (timer <= COUNTDOWN - m_timerReductionChunk * i)
m_world.RemoveChunk(m_nbReductionChunk * i);
}
if (m_keyK) {
SystemNotification(m_messageNotification);
m_keyK = false;
@ -960,6 +1005,8 @@ int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
int Engine::GetCountdown(float elapsedTime) {
if (m_resetcountdown)
{
m_nbReductionChunk = 4;
m_timerReductionChunk = 30;
m_countdown = m_time + COUNTDOWN;
m_resetcountdown = false;
}
@ -1088,6 +1135,7 @@ void Engine::Render(float elapsedTime) {
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
if (m_isSkybox) m_skybox.Render(skybox);
DrawHud(elapsedTime, bloc);
@ -1177,6 +1225,10 @@ void Engine::Render(float elapsedTime) {
DrawMenu();
}
}
else if (m_gamestate == GameState::PAUSE)
{
DrawPause();
}
else if (m_gamestate == GameState::QUIT)
Stop();
}
@ -1204,7 +1256,14 @@ void Engine::KeyPressEvent(unsigned char key) {
}
break;
case 36: // ESC - Quitter
m_gamestate = GameState::MAIN_MENU;
if (m_gamestate == GameState::PLAY)
{
m_gamestate = GameState::PAUSE;
}
else if (m_gamestate == GameState::PAUSE)
{
m_gamestate = GameState::PLAY;
}
//Stop();
break;
case 57: // Space - Sauter

View File

@ -28,6 +28,7 @@ public:
Engine();
virtual ~Engine();
virtual void DrawMenu();
virtual void DrawPause();
virtual void DrawSplachScreen();
virtual void Init();
virtual void DeInit();
@ -94,13 +95,14 @@ private:
std::chrono::high_resolution_clock::time_point m_startTime;
//Menu
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE };
GameState m_gamestate = GameState::MAIN_MENU;
Texture MenuTitleTexture;
Texture MenuBGTexture;
Texture MenuStartTexture;
Texture MenuQuitTexture;
Texture MenuOptionsTexture;
Texture PauseBGTexture;
Texture SplachScreenTexture;
float m_scale;
@ -113,6 +115,8 @@ private:
int m_renderCount = 0;
int m_countdown = COUNTDOWN;
int m_nbReductionChunk = 4;
int m_timerReductionChunk = 30;
bool m_damage = false;