SQC-06 et une partie du SQC-09

This commit is contained in:
Rynort 2023-10-02 17:09:03 -04:00
parent 8e40f17b75
commit 6668127f15
6 changed files with 333 additions and 97 deletions

View File

@ -65,5 +65,6 @@ enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BT
#define SHADER_PATH "./media/shaders/"
#define AUDIO_PATH "./media/audio/"
#define CHUNK_PATH "./media/chunks/"
#define MENU_ITEM_PATH "./media/menu_items/"
#endif // DEFINE_H__

View File

@ -14,7 +14,199 @@ Engine::~Engine() {
m_world.GetChunks().Get(x, y)->~Chunk();
}
void Engine::DrawMenu()
{
static const int sTitle = 400;
static const int sButton = 225;
glDisable(GL_LIGHTING);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, Width(), 0, Height(), -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
MenuBGTexture.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();
if (m_gamestate != GameState::OPTIONS)
{
MenuTitleTexture.Bind();
glTranslated(200, 300, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 200);
glTexCoord2f(1, 0);
glVertex2i(sTitle, 200);
glTexCoord2f(1, 1);
glVertex2i(sTitle, 300);
glTexCoord2f(0, 1);
glVertex2i(0, 300);
glEnd();
MenuStartTexture.Bind();
glTranslated(80, -225, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 100);
glTexCoord2f(1, 0);
glVertex2i(sButton, 100);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();
/*MenuResumeTexture.Bind();
glTranslated(0, -100, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 125);
glTexCoord2f(1, 0);
glVertex2i(sButton, 125);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();*/
/*MenuOptionsTexture.Bind();
glTranslated(0, -100, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 125);
glTexCoord2f(1, 0);
glVertex2i(sButton, 125);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();*/
MenuQuitTexture.Bind();
glTranslated(0, -100, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 100);
glTexCoord2f(1, 0);
glVertex2i(sButton, 100);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();
}
else
{
/*MenuOptionsTexture.Bind();
glTranslated(200, 0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(1, 0);
glVertex2i(sTitle, 0);
glTexCoord2f(1, 1);
glVertex2i(sTitle, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();
WireFrameTexture.Bind();
glTranslated(0, 300, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 125);
glTexCoord2f(1, 0);
glVertex2i(sButton, 125);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();
OnOffBtnTexture.Bind();
glTranslated(200, 0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 125);
glTexCoord2f(1, 0);
glVertex2i(sButton, 125);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();
glTranslated(-400, -300, 0);
MusicTexture.Bind();
glTranslated(200, 200, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 125);
glTexCoord2f(1, 0);
glVertex2i(sButton, 125);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();
OnOffBtnTexture.Bind();
glTranslated(200, 0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 125);
glTexCoord2f(1, 0);
glVertex2i(sButton, 125);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();
BackBtnTexture.Bind();
glTranslated(-375, 175, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 140);
glTexCoord2f(1, 0);
glVertex2i(sButton, 140);
glTexCoord2f(1, 1);
glVertex2i(sButton, 200);
glTexCoord2f(0, 1);
glVertex2i(0, 200);
glEnd();*/
}
glEnable(GL_LIGHTING);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
ShowCursor();
}
void Engine::Init() {
m_gamestate = GameState::MAIN_MENU;
GLenum glewErr = glewInit();
if (glewErr != GLEW_OK) {
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
@ -63,6 +255,11 @@ void Engine::LoadResource() {
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png");
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp");
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp");
LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.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");
@ -185,97 +382,108 @@ void Engine::PrintText(unsigned int x, unsigned int y, const std::string& t) {
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
void Engine::Render(float elapsedTime) {
//static float gameTime = elapsedTime;
static float pollTime = 0;
static float bulletTime = 0;
static BlockType bloc = 1;
if (elapsedTime > 0.1f) return;
//gameTime += elapsedTime;
pollTime += elapsedTime;
Transformation all;
Transformation skybox;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Transformations initiales
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (m_gamestate == GameState::PLAY)
{
//static float gameTime = elapsedTime;
static float pollTime = 0;
static float bulletTime = 0;
static BlockType bloc = 1;
if (bulletTime > 0.f) bulletTime -= elapsedTime;
if (bulletTime < 0.f) bulletTime = 0.f;
if (elapsedTime > 0.1f) return;
if (pollTime >= .005f) {
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ées du joueur et
// son vecteur de vélocité (pour l'effet Doppler)
pollTime = 0;
}
//gameTime += elapsedTime;
pollTime += elapsedTime;
m_player.ApplyTransformation(all);
Transformation all;
Transformation skybox;
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!).
if (m_mouseWU) bloc++;
else if (m_mouseWD) bloc--;
if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST équipe l'arme.
m_mouseWU = m_mouseWD = false;
// Transformations initiales
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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;
if (bulletTime > 0.f) bulletTime -= elapsedTime;
if (bulletTime < 0.f) bulletTime = 0.f;
if (pollTime >= .005f) {
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ées du joueur et
// son vecteur de vélocité (pour l'effet Doppler)
pollTime = 0;
}
m_player.ApplyTransformation(all);
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!).
if (m_mouseWU) bloc++;
else if (m_mouseWD) bloc--;
if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST équipe l'arme.
m_mouseWU = m_mouseWD = false;
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è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 (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premiè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);
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_blockinfo);
if (m_isSkybox) m_skybox.Render(skybox);
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
DrawHud(elapsedTime, bloc);
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
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(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde.
fell = false;
}
}
else if (m_mouseR)
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player, m_block);
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_blockinfo);
if (m_isSkybox) m_skybox.Render(skybox);
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
{
DrawMenu();
}
else if (m_gamestate == GameState::QUIT)
Stop();
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
DrawHud(elapsedTime, bloc);
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
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(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde.
fell = false;
}
}
void Engine::KeyPressEvent(unsigned char key) {
@ -390,27 +598,40 @@ void Engine::MouseMoveEvent(int x, int y) {
if (x == (Width() / 2) && y == (Height() / 2))
return;
CenterMouse();
//CenterMouse();
}
void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
switch (button) {
case MOUSE_BUTTON_LEFT:
m_mouseL = true;
break;
case MOUSE_BUTTON_RIGHT:
m_mouseR = true;
break;
case MOUSE_BUTTON_MIDDLE:
m_mouseC = true;
break;
case MOUSE_BUTTON_WHEEL_UP:
m_mouseWU = true;
break;
case MOUSE_BUTTON_WHEEL_DOWN:
m_mouseWD = true;
break;
case MOUSE_BUTTON_NONE: break;
m_mousemx = x;
m_mousemy = y;
if (m_gamestate == GameState::PLAY)
{
switch (button) {
case MOUSE_BUTTON_LEFT:
m_mouseL = true;
break;
case MOUSE_BUTTON_RIGHT:
m_mouseR = true;
break;
case MOUSE_BUTTON_MIDDLE:
m_mouseC = true;
break;
case MOUSE_BUTTON_WHEEL_UP:
m_mouseWU = true;
break;
case MOUSE_BUTTON_WHEEL_DOWN:
m_mouseWD = true;
break;
case MOUSE_BUTTON_NONE: break;
}
}
else if (m_gamestate == GameState::MAIN_MENU)
{
if ((m_mousemx >= 285 && m_mousemx <= 490) && (m_mousemy >= 150 && m_mousemy <= 250))
m_gamestate = GameState::PLAY;
if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 300 && m_mousemy <= 400))
m_gamestate = GameState::QUIT;
}
}

View File

@ -19,6 +19,7 @@ class Engine : public OpenglContext {
public:
Engine();
virtual ~Engine();
virtual void DrawMenu();
virtual void Init();
virtual void DeInit();
virtual void LoadResource();
@ -51,6 +52,7 @@ private:
Texture m_textureFont;
Texture m_textureCrosshair;
Skybox m_skybox;
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
@ -61,6 +63,15 @@ private:
Bullet* m_bullets[MAX_BULLETS];
//Menu
enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
GameState m_gamestate;
Texture MenuTitleTexture;
Texture MenuBGTexture;
Texture MenuStartTexture;
Texture MenuQuitTexture;
Texture MenuOptionsTexture;
bool m_keyW = false;
bool m_keyA = false;
bool m_keyS = false;
@ -72,6 +83,9 @@ private:
bool m_mouseC = false;
bool m_mouseWU = false;
bool m_mouseWD = false;
//Pour trouver ou est la souris
float m_mousemx = 0;
float m_mousemy = 0;
bool m_block = false;
bool m_flash = true;

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB