On l'a eu!
This commit is contained in:
parent
b712c950c6
commit
a054a7bff1
@ -20,8 +20,8 @@
|
|||||||
#define SRV_ADDR "127.0.0.1"
|
#define SRV_ADDR "127.0.0.1"
|
||||||
#define COUNTDOWN 300
|
#define COUNTDOWN 300
|
||||||
|
|
||||||
#define BASE_WIDTH 1920
|
#define BASE_WIDTH 640
|
||||||
#define BASE_HEIGHT 1080
|
#define BASE_HEIGHT 480
|
||||||
|
|
||||||
#define TEXTURE_PATH "./media/textures/"
|
#define TEXTURE_PATH "./media/textures/"
|
||||||
#define SHADER_PATH "./media/shaders/"
|
#define SHADER_PATH "./media/shaders/"
|
||||||
|
@ -34,10 +34,10 @@ void Engine::DrawMenu()
|
|||||||
static const int sButton = 225;
|
static const int sButton = 225;
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
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);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_STENCIL_TEST);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -57,7 +57,10 @@ void Engine::DrawMenu()
|
|||||||
glTexCoord2f(0, 1);
|
glTexCoord2f(0, 1);
|
||||||
glVertex2i(0, 600);
|
glVertex2i(0, 600);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
if (m_gamestate != GameState::OPTIONS)
|
if (m_gamestate != GameState::OPTIONS)
|
||||||
{
|
{
|
||||||
@ -209,7 +212,7 @@ void Engine::DrawMenu()
|
|||||||
glEnd();*/
|
glEnd();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
//glEnable(GL_LIGHTING);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
@ -220,7 +223,6 @@ void Engine::DrawMenu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Engine::Init() {
|
void Engine::Init() {
|
||||||
m_gamestate = GameState::MAIN_MENU;
|
|
||||||
GLenum glewErr = glewInit();
|
GLenum glewErr = glewInit();
|
||||||
if (glewErr != GLEW_OK) {
|
if (glewErr != GLEW_OK) {
|
||||||
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
||||||
@ -245,6 +247,7 @@ void Engine::Init() {
|
|||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Objet de skybox avec sa propre texture et son propre shader!
|
// Objet de skybox avec sa propre texture et son propre shader!
|
||||||
m_skybox.Init(0.2f);
|
m_skybox.Init(0.2f);
|
||||||
@ -287,7 +290,7 @@ void Engine::LoadResource() {
|
|||||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
|
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
|
||||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
||||||
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
|
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", true);
|
||||||
|
|
||||||
LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
|
LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
|
||||||
LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png");
|
LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png");
|
||||||
@ -385,8 +388,6 @@ void Engine::ProcessNotificationQueue() {
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PrintText(xOffset, y, scale, it->message);
|
PrintText(xOffset, y, scale, it->message);
|
||||||
|
|
||||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||||
@ -433,6 +434,7 @@ void Engine::DisplayCrosshair() {
|
|||||||
void Engine::DisplayCurrentItem() {
|
void Engine::DisplayCurrentItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Engine::DisplayHud(int timer) {
|
void Engine::DisplayHud(int timer) {
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -487,7 +489,7 @@ void Engine::DisplayHud(int timer) {
|
|||||||
glTexCoord2f(1, 1); glVertex2i(0, itemHeight);
|
glTexCoord2f(1, 1); glVertex2i(0, itemHeight);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
//glDisable(GL_BLEND);
|
||||||
|
|
||||||
// Username
|
// Username
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
@ -549,6 +551,7 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
|||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
glBlendEquation(GL_FUNC_ADD);
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
@ -644,11 +647,12 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
if (m_gamestate == GameState::PLAY)
|
if (m_gamestate == GameState::PLAY)
|
||||||
{
|
{
|
||||||
|
HideCursor();
|
||||||
CenterMouse(); //D<>placement de centermouse dans l'action de jouer
|
CenterMouse(); //D<>placement de centermouse dans l'action de jouer
|
||||||
|
|
||||||
//static float gameTime = elapsedTime;
|
//static float gameTime = elapsedTime;
|
||||||
static irrklang::ISound* step; // Pour les sons de pas.
|
static irrklang::ISound* step; // Pour les sons de pas.
|
||||||
static float pollTime = 0;
|
static float pollTime = 0;
|
||||||
static float bulletTime = 0;
|
static float bulletTime = 0;
|
||||||
static BlockType bloc = 1;
|
static BlockType bloc = 1;
|
||||||
|
|
||||||
@ -659,7 +663,7 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
Transformation all;
|
Transformation all;
|
||||||
Transformation skybox;
|
Transformation skybox;
|
||||||
Vector3f vstep;
|
Vector3f vstep;
|
||||||
|
|
||||||
// Transformations initiales
|
// Transformations initiales
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@ -668,26 +672,26 @@ void Engine::Render(float elapsedTime) {
|
|||||||
if (bulletTime > 0.f) bulletTime -= elapsedTime;
|
if (bulletTime > 0.f) bulletTime -= elapsedTime;
|
||||||
if (bulletTime < 0.f) bulletTime = 0.f;
|
if (bulletTime < 0.f) bulletTime = 0.f;
|
||||||
|
|
||||||
static bool leftright = false;
|
static bool leftright = false;
|
||||||
if (pollTime >= .005f) {
|
if (pollTime >= .005f) {
|
||||||
Player::Sound snd = 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);
|
Player::Sound snd = 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);
|
||||||
switch (snd) {
|
switch (snd) {
|
||||||
case Player::Sound::STEP:
|
case Player::Sound::STEP:
|
||||||
if (leftright)
|
if (leftright)
|
||||||
vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x);
|
vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x);
|
||||||
else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x);
|
else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x);
|
||||||
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), .8f);
|
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), .8f);
|
||||||
leftright = !leftright;
|
leftright = !leftright;
|
||||||
break;
|
break;
|
||||||
case Player::Sound::FALL:
|
case Player::Sound::FALL:
|
||||||
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), 1.f);
|
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), 1.f);
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
pollTime = 0;
|
||||||
}
|
}
|
||||||
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)
|
|
||||||
pollTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_player.ApplyTransformation(all);
|
m_player.ApplyTransformation(all);
|
||||||
|
|
||||||
@ -700,57 +704,64 @@ void Engine::Render(float elapsedTime) {
|
|||||||
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST <20>quipe l'arme.
|
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST <20>quipe l'arme.
|
||||||
m_mouseWU = m_mouseWD = false;
|
m_mouseWU = m_mouseWD = false;
|
||||||
|
|
||||||
if (m_mouseL) {
|
if (m_mouseL) {
|
||||||
if (bloc != BTYPE_LAST)
|
if (bloc != BTYPE_LAST)
|
||||||
m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
||||||
else if (bulletTime <= 0.f) {
|
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").
|
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]) {
|
if (!m_bullets[x]) {
|
||||||
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||||
break;
|
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.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||||
|
}
|
||||||
|
bulletTime = .1f;
|
||||||
|
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "windowsaccount.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<6D>re balle de l'array.
|
|
||||||
m_bullets[0]->~Bullet();
|
|
||||||
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
|
||||||
}
|
|
||||||
bulletTime = .1f;
|
|
||||||
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "windowsaccount.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.GetPosition(), m_player.GetDirection(), 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, elapsedTime)) {
|
||||||
|
m_bullets[x]->~Bullet();
|
||||||
|
m_bullets[x] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||||
|
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||||
|
m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||||
|
|
||||||
|
if (m_isSkybox) m_skybox.Render(skybox);
|
||||||
|
|
||||||
|
ProcessNotificationQueue();
|
||||||
|
DrawHud(elapsedTime, bloc);
|
||||||
|
|
||||||
|
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)
|
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
||||||
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
{
|
||||||
|
DrawMenu();
|
||||||
for (int x = 0; x < MAX_BULLETS; ++x) // Array de bullets en jeu.
|
|
||||||
if (m_bullets[x])
|
|
||||||
if (m_bullets[x]->Update(&m_world, elapsedTime)) {
|
|
||||||
m_bullets[x]->~Bullet();
|
|
||||||
m_bullets[x] = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
|
||||||
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
|
||||||
m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo);
|
|
||||||
|
|
||||||
if (m_isSkybox) m_skybox.Render(skybox);
|
|
||||||
|
|
||||||
ProcessNotificationQueue();
|
|
||||||
DrawHud(elapsedTime, bloc);
|
|
||||||
|
|
||||||
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_gamestate == GameState::QUIT)
|
||||||
|
Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::KeyPressEvent(unsigned char key) {
|
void Engine::KeyPressEvent(unsigned char key) {
|
||||||
@ -776,7 +787,8 @@ void Engine::KeyPressEvent(unsigned char key) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 36: // ESC - Quitter
|
case 36: // ESC - Quitter
|
||||||
Stop();
|
m_gamestate = GameState::MAIN_MENU;
|
||||||
|
//Stop();
|
||||||
break;
|
break;
|
||||||
case 57: // Space - Sauter
|
case 57: // Space - Sauter
|
||||||
if (!m_keySpace) {
|
if (!m_keySpace) {
|
||||||
|
@ -80,7 +80,7 @@ private:
|
|||||||
|
|
||||||
//Menu
|
//Menu
|
||||||
enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
||||||
GameState m_gamestate;
|
GameState m_gamestate = GameState::MAIN_MENU;
|
||||||
Texture MenuTitleTexture;
|
Texture MenuTitleTexture;
|
||||||
Texture MenuBGTexture;
|
Texture MenuBGTexture;
|
||||||
Texture MenuStartTexture;
|
Texture MenuStartTexture;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user