Merge branch 'master' into sqc7_server
This commit is contained in:
commit
b7ca0253ca
@ -14,7 +14,7 @@ Audio::Audio(const char * music) {
|
|||||||
m_engine->setRolloffFactor(1);
|
m_engine->setRolloffFactor(1);
|
||||||
m_engine->setDefault3DSoundMinDistance(1);
|
m_engine->setDefault3DSoundMinDistance(1);
|
||||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||||
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
m_music = m_engine->play2D(music, false, true, true, irrklang::ESM_STREAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio::~Audio() {
|
Audio::~Audio() {
|
||||||
@ -40,9 +40,9 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v
|
|||||||
sound->setVolume(volume);
|
sound->setVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::PlaySong(const char* music) {
|
//void Audio::PlaySong(const char* music) {
|
||||||
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
// m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING);
|
||||||
}
|
//}
|
||||||
|
|
||||||
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
|
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
|
|
||||||
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
|
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
|
||||||
|
|
||||||
void PlaySong(const char* music);
|
//void PlaySong(const char* music);
|
||||||
|
|
||||||
void ToggleMusicState();
|
void ToggleMusicState();
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@
|
|||||||
#define VIEW_DISTANCE 256
|
#define VIEW_DISTANCE 256
|
||||||
#define TEXTURE_SIZE 128
|
#define TEXTURE_SIZE 128
|
||||||
#define MAX_BULLETS 64
|
#define MAX_BULLETS 64
|
||||||
|
|
||||||
|
#define BASE_WIDTH 640
|
||||||
|
#define BASE_HEIGHT 480
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "transformation.h"
|
#include "transformation.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
Engine::Engine() { }
|
Engine::Engine() {}
|
||||||
|
|
||||||
Engine::~Engine() {
|
Engine::~Engine() {
|
||||||
m_world.CleanUpWorld(m_renderCount, true);
|
m_world.CleanUpWorld(m_renderCount, true);
|
||||||
@ -21,24 +21,25 @@ void Engine::Init() {
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
//glDisable(GL_FRAMEBUFFER_SRGB);
|
||||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
//glEnable(GL_DEPTH_TEST);
|
||||||
|
//glEnable(GL_STENCIL_TEST);
|
||||||
|
//glEnable(GL_POINT_SMOOTH);
|
||||||
|
//glEnable(GL_BLEND);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
|
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_STENCIL_TEST);
|
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
glEnable(GL_POINT_SMOOTH);
|
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||||
glEnable(GL_CULL_FACE);
|
//glDisable(GL_BLEND);
|
||||||
|
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable(GL_BLEND);
|
//glBlendEquation(GL_FUNC_SUBTRACT);
|
||||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
//
|
||||||
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);
|
||||||
|
|
||||||
@ -57,12 +58,14 @@ void Engine::Init() {
|
|||||||
HideCursor();
|
HideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::DeInit() { }
|
void Engine::DeInit() {}
|
||||||
|
|
||||||
void Engine::LoadResource() {
|
void Engine::LoadResource() {
|
||||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png");
|
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp");
|
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
|
||||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp");
|
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
||||||
|
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
|
||||||
|
|
||||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
||||||
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
||||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
||||||
@ -97,91 +100,200 @@ void Engine::LoadResource() {
|
|||||||
|
|
||||||
void Engine::UnloadResource() {}
|
void Engine::UnloadResource() {}
|
||||||
|
|
||||||
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
void Engine::DisplayCrosshair() {
|
||||||
// Setter le blend function , tout ce qui sera noir sera transparent
|
|
||||||
glDisable(GL_STENCIL_TEST);
|
|
||||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
||||||
glBlendEquation(GL_FUNC_ADD);
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
|
||||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
// Bind de la texture pour le font
|
|
||||||
m_textureFont.Bind();
|
|
||||||
std::ostringstream ss;
|
|
||||||
ss << " Fps : " << GetFps(elapsedTime);
|
|
||||||
PrintText(10, Height() - 25, ss.str());
|
|
||||||
ss.str("");
|
|
||||||
ss << " Rendered Chunks : " << m_renderCount;
|
|
||||||
PrintText(10, Height() - 35, ss.str());
|
|
||||||
ss.str("");
|
|
||||||
ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted();
|
|
||||||
PrintText(10, Height() - 45, ss.str());
|
|
||||||
ss.str("");
|
|
||||||
ss << " Velocity : " << m_player.GetVelocity(); // IMPORTANT : on utilise l ’ operateur << pour afficher la position
|
|
||||||
PrintText(10, 10, ss.str());
|
|
||||||
ss.str("");
|
|
||||||
ss << " Direction : " << m_player.GetDirection();
|
|
||||||
PrintText(10, 20, ss.str());
|
|
||||||
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();
|
m_textureCrosshair.Bind();
|
||||||
static const int crossSize = 32;
|
static const int crossSize = 32;
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
|
glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2f(0, 0);
|
glTexCoord2f(0, 0);
|
||||||
glVertex2i(0, 0);
|
glVertex2i(0, 0);
|
||||||
glTexCoord2f(1, 0);
|
glTexCoord2f(1, 0);
|
||||||
glVertex2i(crossSize, 0);
|
glVertex2i(crossSize, 0);
|
||||||
glTexCoord2f(1, 1);
|
glTexCoord2f(1, 1);
|
||||||
glVertex2i(crossSize, crossSize);
|
glVertex2i(crossSize, crossSize);
|
||||||
glTexCoord2f(0, 1);
|
glTexCoord2f(0, 1);
|
||||||
glVertex2i(0, crossSize);
|
glVertex2i(0, crossSize);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::DisplayCurrentItem() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::DisplayHud() {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
glLoadIdentity();
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
// Barre HP
|
||||||
|
float fBarWidth = Width() / 4;
|
||||||
|
float fBarHeight = Height() / 25;
|
||||||
|
float fPosX = Width() / 20;
|
||||||
|
float fPosY = Height() - (Height() - (fBarHeight * 4));
|
||||||
|
float playerHp = m_player.GetHP();
|
||||||
|
float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f;
|
||||||
|
|
||||||
|
// Arrière-plan (Barre HP)
|
||||||
|
glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex2f(fPosX, fPosY - fBarHeight); // Bas-Gauche
|
||||||
|
glVertex2f(fPosX + fBarWidth, fPosY - fBarHeight); // Bas-Droite
|
||||||
|
glVertex2f(fPosX + fBarWidth, fPosY); // Haut-Droite
|
||||||
|
glVertex2f(fPosX, fPosY); // Haut-Gauche
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
//TODO: Associer avec méchanique de vie du joueur
|
||||||
|
|
||||||
|
// Barre HP
|
||||||
|
glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex2f(fPosX, fPosY - fBarHeight); // Bas-Gauche
|
||||||
|
glVertex2f(fPosX + fBarWidth * playerHp, fPosY - fBarHeight); // Bas-Droite
|
||||||
|
glVertex2f(fPosX + fBarWidth * playerHp, fPosY); // Haut-Droite
|
||||||
|
glVertex2f(fPosX, fPosY); // Haut-Gauche
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Barre équip
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
|
||||||
|
m_textureGun.Bind();
|
||||||
|
|
||||||
|
float margin = Width() * 0.05;
|
||||||
|
float itemWidth = Width() * 0.33;
|
||||||
|
float itemHeight = itemWidth / 2.208;
|
||||||
|
float startX = Width() - itemWidth - margin;
|
||||||
|
float startY = margin;
|
||||||
|
|
||||||
|
glTranslated(startX, startY, 0);
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(1, 0); glVertex2i(0, 0);
|
||||||
|
glTexCoord2f(0, 0); glVertex2i(itemWidth, 0);
|
||||||
|
glTexCoord2f(0, 1); glVertex2i(itemWidth, itemHeight);
|
||||||
|
glTexCoord2f(1, 1); glVertex2i(0, itemHeight);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
// Username
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
|
float scale = GetScale();
|
||||||
|
m_textureFont.Bind();
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << m_player.GetUsername();
|
||||||
|
PrintText(fPosX, fPosY, scale, ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||||
|
// Bind de la texture pour le font
|
||||||
|
m_textureFont.Bind();
|
||||||
|
std::ostringstream ss;
|
||||||
|
|
||||||
|
float scale = GetScale();
|
||||||
|
unsigned int x = Width() / 25;
|
||||||
|
|
||||||
|
ss << " Fps : " << GetFps(elapsedTime);
|
||||||
|
PrintText(x, Height() - (Height() / 19.2), scale, ss.str());
|
||||||
|
ss.str("");
|
||||||
|
ss << " Rendered Chunks : " << m_renderCount;
|
||||||
|
PrintText(x, Height() - (Height() / 13.7), scale, ss.str());
|
||||||
|
ss.str("");
|
||||||
|
ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted();
|
||||||
|
PrintText(x, Height() - (Height() / 10.7), scale, ss.str());
|
||||||
|
ss.str("");
|
||||||
|
ss << " Velocity : " << m_player.GetVelocity(); // IMPORTANT : on utilise l ’ operateur << pour afficher la position
|
||||||
|
PrintText(x, Height() / 48, scale, ss.str());
|
||||||
|
ss.str("");
|
||||||
|
ss << " Direction : " << m_player.GetDirection();
|
||||||
|
PrintText(x, Height() / 24, scale, ss.str());
|
||||||
|
ss.str("");
|
||||||
|
ss << " Position : " << m_player.GetPosition();
|
||||||
|
PrintText(x, Height() / 16, scale, ss.str());
|
||||||
|
ss.str("");
|
||||||
|
ss << " Block : ";
|
||||||
|
|
||||||
|
if (bloc == BTYPE_LAST)
|
||||||
|
ss << "Weapon.";
|
||||||
|
else ss << (int)bloc;
|
||||||
|
|
||||||
|
PrintText(x, Height() / 12, scale, ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
||||||
|
// Setter le blend function, tout ce qui sera noir sera transparent
|
||||||
|
glDisable(GL_STENCIL_TEST);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
glLoadIdentity();
|
||||||
|
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
|
||||||
|
if (m_displayInfo) {
|
||||||
|
DisplayInfo(elapsedTime, bloc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_displayHud) {
|
||||||
|
DisplayHud();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_displayCrosshair) {
|
||||||
|
DisplayCrosshair();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset du blend function
|
||||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::PrintText(unsigned int x, unsigned int y, const std::string& t) {
|
void Engine::PrintText(float x, float y, float scale, const std::string& t) {
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslated(x, y, 0);
|
glTranslated(x, y, 0);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < t.length(); ++i) {
|
for (unsigned int i = 0; i < t.length(); ++i) {
|
||||||
float left = (float)((t[i] - 32) % 16) / 16.f;
|
float left = (float)((t[i] - 32) % 16) / 16.f;
|
||||||
float top = (float)((t[i] - 32) / 16) / 16.f;
|
float top = (float)((t[i] - 32) / 16) / 16.f;
|
||||||
top += .5f;
|
top += .5f;
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2f(left, 1.f - top - .0625f);
|
glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0);
|
||||||
glVertex2f(0, 0);
|
glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(12 * scale, 0);
|
||||||
glTexCoord2f(left + .0625f, 1.f - top - .0625f);
|
glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(12 * scale, 12 * scale);
|
||||||
glVertex2f(12, 0);
|
glTexCoord2f(left, 1.f - top); glVertex2f(0, 12 * scale);
|
||||||
glTexCoord2f(left + .0625f, 1.f - top);
|
|
||||||
glVertex2f(12, 12);
|
|
||||||
glTexCoord2f(left, 1.f - top);
|
|
||||||
glVertex2f(0, 12);
|
|
||||||
glEnd();
|
glEnd();
|
||||||
glTranslated(8, 0, 0);
|
|
||||||
|
glTranslated(8 * scale, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Engine::GetScale() const {
|
||||||
|
float widthRatio = Width() / BASE_WIDTH;
|
||||||
|
float heightRatio = Height() / BASE_HEIGHT;
|
||||||
|
|
||||||
|
return (widthRatio + heightRatio) / 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
||||||
|
|
||||||
void Engine::Render(float elapsedTime) {
|
void Engine::Render(float elapsedTime) {
|
||||||
@ -207,16 +319,16 @@ void Engine::Render(float elapsedTime) {
|
|||||||
if (bulletTime < 0.f) bulletTime = 0.f;
|
if (bulletTime < 0.f) bulletTime = 0.f;
|
||||||
|
|
||||||
if (pollTime >= .005f) {
|
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_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
|
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)
|
// son vecteur de vélocité (pour l'effet Doppler)
|
||||||
pollTime = 0;
|
pollTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_player.ApplyTransformation(all);
|
m_player.ApplyTransformation(all);
|
||||||
|
|
||||||
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
|
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!).
|
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
|
||||||
|
|
||||||
if (m_mouseWU) bloc++;
|
if (m_mouseWU) bloc++;
|
||||||
else if (m_mouseWD) bloc--;
|
else if (m_mouseWD) bloc--;
|
||||||
@ -238,7 +350,7 @@ void Engine::Render(float elapsedTime) {
|
|||||||
m_bullets[0] = new Bullet(m_player);
|
m_bullets[0] = new Bullet(m_player);
|
||||||
}
|
}
|
||||||
bulletTime = .1f;
|
bulletTime = .1f;
|
||||||
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, .5f);
|
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.
|
if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
|
||||||
glClearColor(.8f, .8f, .8f, 1.f);
|
glClearColor(.8f, .8f, .8f, 1.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
@ -261,11 +373,7 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
if (m_isSkybox) m_skybox.Render(skybox);
|
if (m_isSkybox) m_skybox.Render(skybox);
|
||||||
|
|
||||||
if (m_wireframe)
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
||||||
DrawHud(elapsedTime, bloc);
|
DrawHud(elapsedTime, bloc);
|
||||||
if (m_wireframe)
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
||||||
|
|
||||||
static bool fell = false;
|
static bool fell = false;
|
||||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
if (m_player.GetPosition().y < 1.7f && !fell) {
|
||||||
@ -280,54 +388,54 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
void Engine::KeyPressEvent(unsigned char key) {
|
void Engine::KeyPressEvent(unsigned char key) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 36: // ESC
|
case 0: // A - Gauche
|
||||||
Stop();
|
|
||||||
break;
|
|
||||||
case 94: // F10
|
|
||||||
SetFullscreen(!IsFullscreen());
|
|
||||||
break;
|
|
||||||
case 22: // W
|
|
||||||
if (!m_keyW) {
|
|
||||||
// std::cout << "W " << std::endl;
|
|
||||||
m_keyW = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0: // A
|
|
||||||
if (!m_keyA) {
|
if (!m_keyA) {
|
||||||
//std::cout << "A " << std::endl;
|
|
||||||
m_keyA = true;
|
m_keyA = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 18: // S
|
case 3: // D - Droite
|
||||||
if (!m_keyS) {
|
|
||||||
//std::cout << "S " << std::endl;
|
|
||||||
m_keyS = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3: // D
|
|
||||||
if (!m_keyD) {
|
if (!m_keyD) {
|
||||||
//std::cout << "D " << std::endl;
|
|
||||||
m_keyD = true;
|
m_keyD = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 38: // Left Shift
|
case 18: // S - Reculer
|
||||||
if (!m_keylshift) {
|
if (!m_keyS) {
|
||||||
//std::cout << "Dash!" << std::endl;
|
m_keyS = true;
|
||||||
m_keylshift = true;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 57: // Space
|
case 22: // W - Avancer
|
||||||
|
if (!m_keyW) {
|
||||||
|
m_keyW = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 36: // ESC - Quitter
|
||||||
|
Stop();
|
||||||
|
break;
|
||||||
|
case 57: // Space - Sauter
|
||||||
if (!m_keySpace) {
|
if (!m_keySpace) {
|
||||||
//std::cout << "Jump! " << std::endl;
|
|
||||||
m_keySpace = true;
|
m_keySpace = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 94: // F10 - Plein écran
|
||||||
|
IsFullscreen() ? SetFullscreen(false) : SetFullscreen(true);
|
||||||
|
//SetFullscreen(!IsFullscreen());
|
||||||
|
break;
|
||||||
|
case 2: // C - Ignorer
|
||||||
|
break;
|
||||||
case 5: // F - Ignorer
|
case 5: // F - Ignorer
|
||||||
case 24: // Y - Ignorer
|
break;
|
||||||
case 255: // Fn - Ignorer
|
|
||||||
case 12: // M - Ignorer
|
case 12: // M - Ignorer
|
||||||
|
break;
|
||||||
|
case 7: // H - Ignorer
|
||||||
|
break;
|
||||||
|
case 8: // I - Ignorer
|
||||||
|
break;
|
||||||
case 17: // R - Ignorer
|
case 17: // R - Ignorer
|
||||||
break;
|
break;
|
||||||
|
case 24: // Y - Ignorer
|
||||||
|
break;
|
||||||
|
case 255: // Fn - Ignorer
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::cout << "Unhandled key: " << (int)key << std::endl;
|
std::cout << "Unhandled key: " << (int)key << std::endl;
|
||||||
}
|
}
|
||||||
@ -335,44 +443,47 @@ void Engine::KeyPressEvent(unsigned char key) {
|
|||||||
|
|
||||||
void Engine::KeyReleaseEvent(unsigned char key) {
|
void Engine::KeyReleaseEvent(unsigned char key) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 5:
|
case 0: // A - Stop gauche
|
||||||
|
m_keyA = false;
|
||||||
|
break;
|
||||||
|
case 2: // C - Toggle crosshair
|
||||||
|
m_displayCrosshair = !m_displayCrosshair;
|
||||||
|
std::cout << "DISPLAY CROSSHAIR " << (m_displayCrosshair ? "enabled" : "disabled") << std::endl;
|
||||||
|
break;
|
||||||
|
case 3: // D - Stop droite
|
||||||
|
m_keyD = false;
|
||||||
|
break;
|
||||||
|
case 5: // F - Toggle flash
|
||||||
m_flash = !m_flash;
|
m_flash = !m_flash;
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 7: // H - Toggle HUD
|
||||||
|
m_displayHud = !m_displayHud;
|
||||||
|
std::cout << "DISPLAY HUD " << (m_displayHud ? "enabled" : "disabled") << std::endl;
|
||||||
|
break;
|
||||||
|
case 8: // I - Toggle render data
|
||||||
|
m_displayInfo = !m_displayInfo;
|
||||||
|
std::cout << "DISPLAY INFO " << (m_displayInfo ? "enabled" : "disabled") << std::endl;
|
||||||
|
break;
|
||||||
|
case 12: // M - Toggle music
|
||||||
m_audio.ToggleMusicState();
|
m_audio.ToggleMusicState();
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17: // R - Toggle skybox
|
||||||
m_isSkybox = !m_isSkybox;
|
m_isSkybox = !m_isSkybox;
|
||||||
break;
|
break;
|
||||||
case 24: // Y
|
case 18: // S - Stop reculer
|
||||||
|
m_keyS = false;
|
||||||
|
break;
|
||||||
|
case 22: // W - Stop avancer
|
||||||
|
m_keyW = false;
|
||||||
|
break;
|
||||||
|
case 24: // Y - Wireframe
|
||||||
m_wireframe = !m_wireframe;
|
m_wireframe = !m_wireframe;
|
||||||
if (m_wireframe)
|
if (m_wireframe)
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
else
|
else
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
break;
|
break;
|
||||||
case 22: // W
|
case 57: // Espace - Stop sauter
|
||||||
//std::cout << "rW " << std::endl;
|
|
||||||
m_keyW = false;
|
|
||||||
break;
|
|
||||||
case 0: // A
|
|
||||||
//std::cout << "rA " << std::endl;
|
|
||||||
m_keyA = false;
|
|
||||||
break;
|
|
||||||
case 18: // S
|
|
||||||
//std::cout << "rS " << std::endl;
|
|
||||||
m_keyS = false;
|
|
||||||
break;
|
|
||||||
case 3: // D
|
|
||||||
//std::cout << "rD " << std::endl;
|
|
||||||
m_keyD = false;
|
|
||||||
break;
|
|
||||||
case 38: // Left Shift
|
|
||||||
//std::cout << "rLS " << std::endl;
|
|
||||||
m_keylshift = false;
|
|
||||||
break;
|
|
||||||
case 57: // Espace
|
|
||||||
//std::cout << "rSpace " << std::endl;
|
|
||||||
m_keySpace = false;
|
m_keySpace = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -437,10 +548,9 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool stopOnError) {
|
bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError) {
|
||||||
texture.Load(filename);
|
texture.Load(filename, useMipmaps);
|
||||||
if (!texture.IsValid())
|
if (!texture.IsValid()) {
|
||||||
{
|
|
||||||
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
|
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
|
||||||
if (stopOnError)
|
if (stopOnError)
|
||||||
Stop();
|
Stop();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef ENGINE_H__
|
#ifndef ENGINE_H__
|
||||||
#define ENGINE_H__
|
#define ENGINE_H__
|
||||||
|
|
||||||
#include "define.h"
|
#include "define.h"
|
||||||
#include "openglcontext.h"
|
#include "openglcontext.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
@ -31,15 +32,18 @@ public:
|
|||||||
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
|
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool LoadTexture(Texture& texture, const std::string& filename, bool stopOnError = true);
|
float GetScale() const;
|
||||||
void DrawHud(float elapsedTime, BlockType bloc);
|
|
||||||
void PrintText(unsigned int x, unsigned int y, const std::string& t);
|
|
||||||
int GetFps(float elapsedTime) const;
|
int GetFps(float elapsedTime) const;
|
||||||
|
|
||||||
bool m_wireframe = false;
|
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
|
||||||
bool m_isSkybox = true;
|
|
||||||
|
|
||||||
int m_renderCount = 0;
|
void DisplayCrosshair();
|
||||||
|
void DisplayCurrentItem();
|
||||||
|
void DisplayHud();
|
||||||
|
void DisplayInfo(float elapsedTime, BlockType bloc);
|
||||||
|
void DrawHud(float elapsedTime, BlockType bloc);
|
||||||
|
void PrintText(float x, float y, float scale, const std::string& t);
|
||||||
|
|
||||||
Shader m_shader01;
|
Shader m_shader01;
|
||||||
BlockInfo* m_blockinfo[BTYPE_LAST];
|
BlockInfo* m_blockinfo[BTYPE_LAST];
|
||||||
@ -50,9 +54,10 @@ private:
|
|||||||
Texture m_textureSkybox;
|
Texture m_textureSkybox;
|
||||||
Texture m_textureFont;
|
Texture m_textureFont;
|
||||||
Texture m_textureCrosshair;
|
Texture m_textureCrosshair;
|
||||||
|
Texture m_textureGun;
|
||||||
|
|
||||||
Skybox m_skybox;
|
Skybox m_skybox;
|
||||||
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
|
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
||||||
|
|
||||||
irrklang::ISound* m_powpow;
|
irrklang::ISound* m_powpow;
|
||||||
irrklang::ISound* m_scream;
|
irrklang::ISound* m_scream;
|
||||||
@ -61,21 +66,28 @@ private:
|
|||||||
|
|
||||||
Bullet* m_bullets[MAX_BULLETS];
|
Bullet* m_bullets[MAX_BULLETS];
|
||||||
|
|
||||||
|
float m_scale;
|
||||||
|
|
||||||
|
int m_renderCount = 0;
|
||||||
|
|
||||||
|
bool m_wireframe = false;
|
||||||
|
bool m_isSkybox = true;
|
||||||
|
bool m_block = false;
|
||||||
|
bool m_flash = true;
|
||||||
|
bool m_displayCrosshair = true;
|
||||||
|
bool m_displayHud = true;
|
||||||
|
bool m_displayInfo = false;
|
||||||
|
|
||||||
bool m_keyW = false;
|
bool m_keyW = false;
|
||||||
bool m_keyA = false;
|
bool m_keyA = false;
|
||||||
bool m_keyS = false;
|
bool m_keyS = false;
|
||||||
bool m_keyD = false;
|
bool m_keyD = false;
|
||||||
bool m_keylshift = false;
|
|
||||||
bool m_keySpace = false;
|
bool m_keySpace = false;
|
||||||
bool m_mouseL = false;
|
bool m_mouseL = false;
|
||||||
bool m_mouseR = false;
|
bool m_mouseR = false;
|
||||||
bool m_mouseC = false;
|
bool m_mouseC = false;
|
||||||
bool m_mouseWU = false;
|
bool m_mouseWU = false;
|
||||||
bool m_mouseWD = false;
|
bool m_mouseWD = false;
|
||||||
|
|
||||||
bool m_block = false;
|
|
||||||
bool m_flash = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // ENGINE_H__
|
#endif // ENGINE_H__
|
||||||
|
@ -5,5 +5,5 @@
|
|||||||
int main() {
|
int main() {
|
||||||
Engine engine;
|
Engine engine;
|
||||||
engine.SetMaxFps(60);
|
engine.SetMaxFps(60);
|
||||||
engine.Start("Syndicat Quebecois de la Construction Simulator 2023", 640, 480, false);
|
engine.Start("Syndicat Quebecois de la Construction Simulator 2023", BASE_WIDTH, BASE_HEIGHT, false);
|
||||||
}
|
}
|
||||||
|
BIN
SQCSim2021/media/audio/notify.wav
Normal file
BIN
SQCSim2021/media/audio/notify.wav
Normal file
Binary file not shown.
BIN
SQCSim2021/media/audio/start.wav
Normal file
BIN
SQCSim2021/media/audio/start.wav
Normal file
Binary file not shown.
BIN
SQCSim2021/media/audio/windowsaccount.wav
Normal file
BIN
SQCSim2021/media/audio/windowsaccount.wav
Normal file
Binary file not shown.
BIN
SQCSim2021/media/textures/gun01.png
Normal file
BIN
SQCSim2021/media/textures/gun01.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
@ -4,6 +4,8 @@
|
|||||||
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
|
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_velocity = Vector3f(0, 0, 0);
|
||||||
m_airborne = true;
|
m_airborne = true;
|
||||||
|
m_hp = 0.75f; //TODO: Remettre à 1.0f
|
||||||
|
m_username = "Zelda Bee-Bop";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::TurnLeftRight(float value) {
|
void Player::TurnLeftRight(float value) {
|
||||||
@ -197,6 +199,10 @@ Vector3f Player::GetPOV() const { return Vector3f(GetPosition().x, m_POV, GetPos
|
|||||||
|
|
||||||
Vector3f Player::GetDirection() const { return m_direction; }
|
Vector3f Player::GetDirection() const { return m_direction; }
|
||||||
|
|
||||||
|
std::string Player::GetUsername() const { return m_username; }
|
||||||
|
|
||||||
|
float Player::GetHP() const { return m_hp; }
|
||||||
|
|
||||||
void Player::Teleport(int& x, int& z) {
|
void Player::Teleport(int& x, int& z) {
|
||||||
m_position.x -= x * CHUNK_SIZE_X;
|
m_position.x -= x * CHUNK_SIZE_X;
|
||||||
m_position.z -= z * CHUNK_SIZE_Z;
|
m_position.z -= z * CHUNK_SIZE_Z;
|
||||||
|
@ -20,6 +20,8 @@ public:
|
|||||||
Vector3f GetDirection() const;
|
Vector3f GetDirection() const;
|
||||||
Vector3f GetVelocity() const;
|
Vector3f GetVelocity() const;
|
||||||
Vector3f GetPOV() const;
|
Vector3f GetPOV() const;
|
||||||
|
std::string GetUsername() const;
|
||||||
|
float GetHP() const;
|
||||||
void Teleport(int& x, int& z);
|
void Teleport(int& x, int& z);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -27,10 +29,14 @@ private:
|
|||||||
Vector3f m_velocity;
|
Vector3f m_velocity;
|
||||||
Vector3f m_direction;
|
Vector3f m_direction;
|
||||||
|
|
||||||
|
std::string m_username;
|
||||||
|
|
||||||
float m_rotX = 0;
|
float m_rotX = 0;
|
||||||
float m_rotY = 0;
|
float m_rotY = 0;
|
||||||
float m_POV;
|
float m_POV;
|
||||||
|
|
||||||
|
float m_hp;
|
||||||
|
|
||||||
bool m_airborne;
|
bool m_airborne;
|
||||||
};
|
};
|
||||||
#endif //_PLAYER_H__
|
#endif //_PLAYER_H__
|
||||||
|
@ -13,8 +13,7 @@ Texture::~Texture()
|
|||||||
glDeleteTextures(1, &m_textureId);
|
glDeleteTextures(1, &m_textureId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Texture::Load(const std::string& filename, bool useMipMaps)
|
||||||
bool Texture::Load(const std::string& filename)
|
|
||||||
{
|
{
|
||||||
// Initialize Devil only once:
|
// Initialize Devil only once:
|
||||||
static bool alreadyInitialized = false;
|
static bool alreadyInitialized = false;
|
||||||
@ -42,8 +41,14 @@ bool Texture::Load(const std::string& filename)
|
|||||||
glGenTextures(1, &m_textureId);
|
glGenTextures(1, &m_textureId);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||||
|
|
||||||
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
|
if (useMipMaps) {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
}
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
ilDeleteImages(1, &texid);
|
ilDeleteImages(1, &texid);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ public:
|
|||||||
Texture(const std::string& filename = "");
|
Texture(const std::string& filename = "");
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
bool Load(const std::string& filename);
|
bool Load(const std::string& filename, bool useMipMaps = true);
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
void Bind() const;
|
void Bind() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user