Merge branch 'master' into SQC-09
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
#include "engine.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "transformation.h"
|
||||
#include "player.h"
|
||||
|
||||
Engine::Engine() { }
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <queue>
|
||||
|
||||
Engine::~Engine() {
|
||||
|
||||
|
||||
// Define a structure to represent notifications
|
||||
struct Notification {
|
||||
std::string message;
|
||||
float displayStartTime = 0.0f;
|
||||
};
|
||||
|
||||
// Use a queue to manage notifications
|
||||
//std::queue<Notification> notificationQueue;
|
||||
// Use a vector to manage notifications
|
||||
std::vector<Notification> notifications;
|
||||
|
||||
Engine::Engine() {}
|
||||
|
||||
Engine::~Engine() {
|
||||
m_world.CleanUpWorld(m_renderCount, true);
|
||||
for (int x = 0; x < WORLD_SIZE_X; ++x)
|
||||
for (int y = 0; y < WORLD_SIZE_Y; ++y)
|
||||
@@ -214,33 +228,51 @@ void Engine::Init() {
|
||||
}
|
||||
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
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);
|
||||
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
glDisable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
//
|
||||
// Objet de skybox avec sa propre texture et son propre shader!
|
||||
m_skybox.Init(0.2f);
|
||||
|
||||
// Objet de musique!
|
||||
m_audio.ToggleMusicState();
|
||||
//m_audio.ToggleMusicState();
|
||||
|
||||
// Array pour les balles.
|
||||
for (int x = 0; x < MAX_BULLETS; ++x)
|
||||
m_bullets[x] = nullptr;
|
||||
|
||||
uint64_t seed = SEED;
|
||||
std::string playname = "La Chienne <20> Jacques";
|
||||
if (NETWORK_TEST) { // Test connexion r<>seau.
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(SRV_ADDR, playname)) {
|
||||
// setup jeu en r<>seau.
|
||||
std::cout << "ID re<72>u du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
std::cout << "Seed re<72>u du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
||||
seed = m_conn.getSeed();
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de cr<63>ation de socket." << std::endl;
|
||||
}
|
||||
|
||||
m_world.SetSeed(seed);
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
|
||||
@@ -249,12 +281,14 @@ void Engine::Init() {
|
||||
HideCursor();
|
||||
}
|
||||
|
||||
void Engine::DeInit() { }
|
||||
void Engine::DeInit() {}
|
||||
|
||||
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(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
|
||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
||||
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
|
||||
|
||||
LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
|
||||
LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png");
|
||||
LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png");
|
||||
@@ -294,102 +328,327 @@ void Engine::LoadResource() {
|
||||
|
||||
void Engine::UnloadResource() {}
|
||||
|
||||
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);
|
||||
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();
|
||||
void Engine::SystemNotification(std::string systemLog) {
|
||||
std::string message = "";
|
||||
|
||||
// Bind de la texture pour le font
|
||||
message = systemLog;
|
||||
|
||||
DisplayNotification(message);
|
||||
}
|
||||
void Engine::KillNotification(Player killer, Player killed) {
|
||||
std::string message = "";
|
||||
|
||||
message = killed.GetUsername() + " killed by -> " + killer.GetUsername();
|
||||
|
||||
DisplayNotification(message);
|
||||
}
|
||||
|
||||
|
||||
void Engine::DisplayNotification(std::string message) {
|
||||
|
||||
if (message.length() > 45) {
|
||||
message = message.substr(0, 45);
|
||||
}
|
||||
// Create a new notification and add it to the queue
|
||||
Notification newNotification;
|
||||
newNotification.message = message;
|
||||
newNotification.displayStartTime = m_time;
|
||||
|
||||
notifications.push_back(newNotification);
|
||||
}
|
||||
|
||||
// Add a method to process the notification queue
|
||||
void Engine::ProcessNotificationQueue() {
|
||||
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 <20> 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());
|
||||
float scale = GetScale();
|
||||
unsigned int xOffset = Width() - Width() * 0.26;
|
||||
unsigned int yOffset = Height() - (Height() / 2.2);
|
||||
|
||||
// Iterate through the notifications and display them
|
||||
for (auto it = notifications.begin(); it != notifications.end(); ) {
|
||||
float timeSinceDisplay = m_time - it->displayStartTime;
|
||||
|
||||
// Display the notification message with vertical offset
|
||||
unsigned int y = yOffset - (static_cast<unsigned int>(scale * 20) * (it - notifications.begin()));
|
||||
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();
|
||||
|
||||
|
||||
|
||||
PrintText(xOffset, y, scale, it->message);
|
||||
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
// Check if it's time to remove the notification (display for 2 seconds)
|
||||
if (timeSinceDisplay >= 4.0f) {
|
||||
it = notifications.erase(it); // Remove the notification
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Engine::DisplayCrosshair() {
|
||||
m_textureCrosshair.Bind();
|
||||
static const int crossSize = 32;
|
||||
glLoadIdentity();
|
||||
glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(crossSize, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(crossSize, crossSize);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, crossSize);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(crossSize, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(crossSize, crossSize);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, crossSize);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void Engine::DisplayCurrentItem() {
|
||||
}
|
||||
|
||||
void Engine::DisplayHud(int timer) {
|
||||
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<72>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 <20>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());
|
||||
|
||||
//Countdown
|
||||
ss.str("");
|
||||
ss << "Time: " << (int)(timer / 60) << ":" << std::setw(2) << std::setfill('0') << timer % 60;
|
||||
PrintText(Width() - Width() * 0.15, Height() - (Height() / 19.2), 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 <20> 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();
|
||||
|
||||
int timer = GetCountdown(elapsedTime);
|
||||
|
||||
// Appel de la fonction pour l'affichage de notifications
|
||||
if (m_keyK) {
|
||||
SystemNotification(m_messageNotification);
|
||||
m_keyK = false;
|
||||
}
|
||||
if (m_keyL) {
|
||||
|
||||
KillNotification(m_player, m_player);
|
||||
m_keyL = false;
|
||||
}
|
||||
|
||||
if (m_displayInfo) {
|
||||
DisplayInfo(elapsedTime, bloc);
|
||||
}
|
||||
|
||||
if (m_displayHud) {
|
||||
DisplayHud(timer);
|
||||
}
|
||||
|
||||
if (m_displayCrosshair) {
|
||||
DisplayCrosshair();
|
||||
}
|
||||
|
||||
// Reset du blend function
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
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();
|
||||
glTranslated(x, y, 0);
|
||||
|
||||
for (unsigned int i = 0; i < t.length(); ++i) {
|
||||
float left = (float)((t[i] - 32) % 16) / 16.f;
|
||||
float top = (float)((t[i] - 32) / 16) / 16.f;
|
||||
top += .5f;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(left, 1.f - top - .0625f);
|
||||
glVertex2f(0, 0);
|
||||
glTexCoord2f(left + .0625f, 1.f - top - .0625f);
|
||||
glVertex2f(12, 0);
|
||||
glTexCoord2f(left + .0625f, 1.f - top);
|
||||
glVertex2f(12, 12);
|
||||
glTexCoord2f(left, 1.f - top);
|
||||
glVertex2f(0, 12);
|
||||
glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0);
|
||||
glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(12 * scale, 0);
|
||||
glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(12 * scale, 12 * scale);
|
||||
glTexCoord2f(left, 1.f - top); glVertex2f(0, 12 * scale);
|
||||
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::GetCountdown(float elapsedTime) {
|
||||
if (m_resetcountdown)
|
||||
{
|
||||
m_countdown = m_time + COUNTDOWN;
|
||||
m_resetcountdown = false;
|
||||
}
|
||||
if (m_countdown < m_time)
|
||||
Stop();
|
||||
if(!m_stopcountdown)
|
||||
m_time += elapsedTime;
|
||||
return m_countdown - (int)m_time;
|
||||
}
|
||||
|
||||
void Engine::Render(float elapsedTime) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
if (m_gamestate == GameState::PLAY)
|
||||
{
|
||||
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 pollTime = 0;
|
||||
static irrklang::ISound* step; // Pour les sons de pas.
|
||||
static float pollTime = 0;
|
||||
static float bulletTime = 0;
|
||||
static BlockType bloc = 1;
|
||||
|
||||
@@ -400,6 +659,7 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
Transformation all;
|
||||
Transformation skybox;
|
||||
Vector3f vstep;
|
||||
|
||||
// Transformations initiales
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -408,12 +668,26 @@ void Engine::Render(float elapsedTime) {
|
||||
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<6E>es du joueur et
|
||||
// son vecteur de v<>locit<69> (pour l'effet Doppler)
|
||||
pollTime = 0;
|
||||
static bool leftright = false;
|
||||
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);
|
||||
switch (snd) {
|
||||
case Player::Sound::STEP:
|
||||
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);
|
||||
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);
|
||||
leftright = !leftright;
|
||||
break;
|
||||
case Player::Sound::FALL:
|
||||
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), 1.f);
|
||||
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_player.ApplyTransformation(all);
|
||||
|
||||
@@ -423,121 +697,123 @@ void Engine::Render(float elapsedTime) {
|
||||
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 <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;
|
||||
|
||||
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;
|
||||
if (m_mouseL) {
|
||||
if (bloc != BTYPE_LAST)
|
||||
m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), 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.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
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 (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_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
||||
{
|
||||
DrawMenu();
|
||||
}
|
||||
else if (m_gamestate == GameState::QUIT)
|
||||
Stop();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::KeyPressEvent(unsigned char key) {
|
||||
switch (key) {
|
||||
case 36: // ESC
|
||||
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
|
||||
case 0: // A - Gauche
|
||||
if (!m_keyA) {
|
||||
//std::cout << "A " << std::endl;
|
||||
m_keyA = true;
|
||||
}
|
||||
break;
|
||||
case 18: // S
|
||||
if (!m_keyS) {
|
||||
//std::cout << "S " << std::endl;
|
||||
m_keyS = true;
|
||||
}
|
||||
break;
|
||||
case 3: // D
|
||||
case 3: // D - Droite
|
||||
if (!m_keyD) {
|
||||
//std::cout << "D " << std::endl;
|
||||
m_keyD = true;
|
||||
}
|
||||
break;
|
||||
case 38: // Left Shift
|
||||
if (!m_keylshift) {
|
||||
//std::cout << "Dash!" << std::endl;
|
||||
m_keylshift = true;
|
||||
case 18: // S - Reculer
|
||||
if (!m_keyS) {
|
||||
m_keyS = true;
|
||||
}
|
||||
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) {
|
||||
//std::cout << "Jump! " << std::endl;
|
||||
m_keySpace = true;
|
||||
}
|
||||
break;
|
||||
case 94: // F10 - Plein <20>cran
|
||||
IsFullscreen() ? SetFullscreen(false) : SetFullscreen(true);
|
||||
//SetFullscreen(!IsFullscreen());
|
||||
break;
|
||||
case 2: // C - Ignorer
|
||||
break;
|
||||
case 5: // F - Ignorer
|
||||
case 24: // Y - Ignorer
|
||||
case 255: // Fn - Ignorer
|
||||
break;
|
||||
case 10: // K - Debugging DisplayNotification()
|
||||
m_keyK = true;
|
||||
m_messageNotification = "notifications systeme peuvent <20>tre affich<63>";
|
||||
break;
|
||||
case 11: // L - Debugging DisplayNotification()
|
||||
m_keyL = true;
|
||||
break;
|
||||
case 6: // G - Ignorer
|
||||
break;
|
||||
case 12: // M - Ignorer
|
||||
break;
|
||||
case 7: // H - Ignorer
|
||||
break;
|
||||
case 8: // I - Ignorer
|
||||
break;
|
||||
case 17: // R - Ignorer
|
||||
break;
|
||||
case 19: // T - Ignorer
|
||||
break;
|
||||
case 24: // Y - Ignorer
|
||||
break;
|
||||
case 255: // Fn - Ignorer
|
||||
break;
|
||||
default:
|
||||
std::cout << "Unhandled key: " << (int)key << std::endl;
|
||||
}
|
||||
@@ -545,44 +821,61 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
|
||||
void Engine::KeyReleaseEvent(unsigned char 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;
|
||||
break;
|
||||
case 12:
|
||||
case 6: // G - Toggle Stop Countdown
|
||||
m_stopcountdown = !m_stopcountdown;
|
||||
std::cout << "STOP COUNTDOWN " << (m_stopcountdown ? "enabled" : "disabled") << std::endl;
|
||||
break;
|
||||
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 10: // K
|
||||
m_keyK = false;
|
||||
break;
|
||||
case 11: // L - Debugging DisplayNotification()
|
||||
m_keyL = false;
|
||||
break;
|
||||
case 12: // M - Toggle music
|
||||
m_audio.ToggleMusicState();
|
||||
break;
|
||||
case 17:
|
||||
case 17: // R - Toggle skybox
|
||||
m_isSkybox = !m_isSkybox;
|
||||
break;
|
||||
case 24: // Y
|
||||
case 18: // S - Stop reculer
|
||||
m_keyS = false;
|
||||
break;
|
||||
case 19: // T -Reset countdown
|
||||
m_resetcountdown = true;
|
||||
std::cout << "RESET COUNTDOWN" << std::endl;
|
||||
break;
|
||||
case 22: // W - Stop avancer
|
||||
m_keyW = false;
|
||||
break;
|
||||
case 24: // Y - Wireframe
|
||||
m_wireframe = !m_wireframe;
|
||||
if (m_wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
break;
|
||||
case 22: // W
|
||||
//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;
|
||||
case 57: // Espace - Stop sauter
|
||||
m_keySpace = false;
|
||||
break;
|
||||
}
|
||||
@@ -592,9 +885,9 @@ void Engine::MouseMoveEvent(int x, int y) {
|
||||
m_player.TurnLeftRight(x - (Width() / 2));
|
||||
m_player.TurnTopBottom(y - (Height() / 2));
|
||||
|
||||
// Centrer la souris seulement si elle n'est pas d<>j<EFBFBD> centr<74>e
|
||||
// Il est n<>cessaire de faire la v<>rification pour <20>viter de tomber
|
||||
// dans une boucle infinie o<> l'appel <20> CenterMouse g<>n<EFBFBD>re un
|
||||
// Centrer la souris seulement si elle n'est pas d<>j<EFBFBD> centr<74>e
|
||||
// Il est n<>cessaire de faire la v<>rification pour <20>viter de tomber
|
||||
// dans une boucle infinie o<> l'appel <20> CenterMouse g<>n<EFBFBD>re un
|
||||
// MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre
|
||||
// MouseMoveEvent, etc
|
||||
if (x == (Width() / 2) && y == (Height() / 2))
|
||||
@@ -659,10 +952,9 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool stopOnError) {
|
||||
texture.Load(filename);
|
||||
if (!texture.IsValid())
|
||||
{
|
||||
bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError) {
|
||||
texture.Load(filename, useMipmaps);
|
||||
if (!texture.IsValid()) {
|
||||
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
|
||||
if (stopOnError)
|
||||
Stop();
|
||||
|
Reference in New Issue
Block a user