@@ -82,7 +82,7 @@ void Engine::DrawMenu()
static const int sButton = 225 ;
static const int sButton = 225 ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_DEPTH_TEST ) ;
glDisable ( GL_DEPTH_TEST ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDisable ( GL_STENCIL_TEST ) ;
@@ -280,10 +280,9 @@ void Engine::Init() {
}
}
uint64_t seed = SEED ;
uint64_t seed = SEED ;
char ch ;
glDisable ( GL_FRAMEBUFFER_SRGB ) ;
glDisable ( GL_FRAMEBUFFER_SRGB ) ;
glEnable ( GL_DEPTH_TEST ) ;
glEnable ( GL_DEPTH_TEST ) ;
glEnable ( GL_STENCIL_TEST ) ;
glEnable ( GL_STENCIL_TEST ) ;
glEnable ( GL_POINT_SMOOTH ) ;
glEnable ( GL_POINT_SMOOTH ) ;
glEnable ( GL_BLEND ) ;
glEnable ( GL_BLEND ) ;
@@ -300,7 +299,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 ) ;
@@ -314,50 +313,53 @@ void Engine::Init() {
m_whoosh [ x ] = nullptr ;
m_whoosh [ x ] = nullptr ;
}
}
std : : cout < < " Jouer en ligne? [o/N] " ;
char * ch = new char [ 2 ] ;
std : : cin > > ch ;
std : : cout < < std : : endl ;
if ( ch = = ' o ' | | ch = = ' O ' ) {
std : : cout < < " Jouer en ligne? [o/N] " ;
char * input = new char [ 3 2 ] ;
std : : cin . getline ( ch , 2) ;
std : : string playname , srvname ;
std : : cout < < std : : endl ;
while ( playname . size ( ) < 1 ) {
if ( * ch = = ' o ' | | * ch = = ' O ' ) {
std : : cout < < " Veuillez entrer un nom de joueur: " ;
char * input = new char [ 32 ] ;
std : : cin . ignore ( ) ;
std : : string playname , srvname ;
std : : cin . getline ( input , 32 ) ;
std : : cout < < std : : endl ;
playname = input ;
if ( playname . size ( ) < 1 | | playname . size ( ) > 32 )
std : : puts ( " Nom invalide. " ) ;
}
while ( srvname . size ( ) < 1 ) {
std : : cout < < " Veuillez entrer une adresse de serveur: " ;
std : : cin . getline ( input , 32 ) ;
std : : cout < < std : : endl ;
srvname = input ;
if ( srvname . size ( ) < 1 | | srvname . size ( ) > 32 )
std : : puts ( " Adresse serveur invalide. " ) ;
}
delete [ ] input ;
if ( ! m_conn . Init ( ) ) {
while ( playname . size ( ) < 1 ) {
if ( ! m_conn . Connect ( srvname . c_str ( ) , playname ) ) {
std : : cout < < " Veuillez entrer un nom de joueur: " ;
// setup jeu en reseau.
std : : cin . ignore ( ) ;
std : : cout < < " ID recu du serveur: " < < std : : to_str ing ( m_conn . getId ( ) ) < < " ! " < < std : : endl ;
std : : cin . getl ine ( input , 32 ) ;
std : : cout < < " Seed recu du serveur: " < < std : : to_string ( m_conn . getSeed ( ) ) < < " ! " < < std : : endl ;
std : : cout < < std : : endl ;
m_player = Player ( m_conn . getOrigin ( ) . position ) ;
playname = input ;
if ( playname . size ( ) < 1 | | playname . size ( ) > 32 )
for ( auto & [ key , player ] : m_conn . m_players )
std : : puts ( " Nom invalide. " ) ;
m_players [ key ] = new RemotePlayer ( player ) ;
seed = m_conn . getSeed ( ) ;
m_networkgame = true ;
}
else std : : cout < < " Erreur de connexion. " < < std : : endl ;
}
else std : : cout < < " Erreur de creation de socket. " < < std : : endl ;
}
}
while ( srvname . size ( ) < 1 ) {
std : : cout < < " Veuillez entrer une adresse de serveur: " ;
std : : cin . getline ( input , 32 ) ;
std : : cout < < std : : endl ;
srvname = input ;
if ( srvname . size ( ) < 1 | | srvname . size ( ) > 32 )
std : : puts ( " Adresse serveur invalide. " ) ;
}
delete [ ] input ;
if ( ! m_conn . Init ( ) ) {
if ( ! m_conn . Connect ( srvname . c_str ( ) , playname ) ) {
// setup jeu en reseau.
std : : cout < < " ID recu du serveur: " < < std : : to_string ( m_conn . getId ( ) ) < < " ! " < < std : : endl ;
std : : cout < < " Seed recu du serveur: " < < std : : to_string ( m_conn . getSeed ( ) ) < < " ! " < < std : : endl ;
m_player = Player ( m_conn . getOrigin ( ) . position ) ;
for ( auto & [ key , player ] : m_conn . m_players )
m_players [ key ] = new RemotePlayer ( player ) ;
seed = m_conn . getSeed ( ) ;
m_networkgame = true ;
}
else std : : cout < < " Erreur de connexion. " < < std : : endl ;
}
else std : : cout < < " Erreur de creation de socket. " < < std : : endl ;
}
delete [ ] ch ;
m_world . SetSeed ( seed ) ;
m_world . SetSeed ( seed ) ;
@@ -749,8 +751,8 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glBegin ( GL_QUADS ) ;
glBegin ( GL_QUADS ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( fBackPosX , fBackPosY ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( fBackPosX , fBackPosY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( fBackWidth , fBackPosY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( fBackWidth , fBackPosY ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( fBackWidth , fBackHeight ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( fBackWidth , fBackHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( fBackPosX , fBackHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( fBackPosX , fBackHeight ) ;
glEnd ( ) ;
glEnd ( ) ;
float centerX = ( Width ( ) / 2.0f ) ;
float centerX = ( Width ( ) / 2.0f ) ;
@@ -761,9 +763,9 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
// Solo game indicator
// Solo game indicator
m_textureTitle . Bind ( ) ;
m_textureTitle . Bind ( ) ;
glBegin ( GL_QUADS ) ;
glBegin ( GL_QUADS ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( centerX , centerY ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( centerX , centerY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( titleWidth , centerY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( titleWidth , centerY ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( titleWidth , titleHeight ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( titleWidth , titleHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( centerX , titleHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( centerX , titleHeight ) ;
glEnd ( ) ;
glEnd ( ) ;
@@ -777,9 +779,9 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glColor4f ( 1.0f , 1.0f , 1.0f , 0.5f ) ;
glColor4f ( 1.0f , 1.0f , 1.0f , 0.5f ) ;
glBegin ( GL_QUADS ) ;
glBegin ( GL_QUADS ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( fPosX , soloPosY ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( fPosX , soloPosY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( fPosXWidth , soloPosY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( fPosXWidth , soloPosY ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( fPosXWidth , soloHeight ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( fPosXWidth , soloHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( fPosX , soloHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( fPosX , soloHeight ) ;
glEnd ( ) ;
glEnd ( ) ;
@@ -789,9 +791,9 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glBegin ( GL_QUADS ) ;
glBegin ( GL_QUADS ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( fPosX , multiPosY ) ;
glTexCoord2f ( 0.0f , 0.0f ) ; glVertex2f ( fPosX , multiPosY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( fPosXWidth , multiPosY ) ;
glTexCoord2f ( 1.0f , 0.0f ) ; glVertex2f ( fPosXWidth , multiPosY ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( fPosXWidth , multiHeight ) ;
glTexCoord2f ( 1.0f , 1.0f ) ; glVertex2f ( fPosXWidth , multiHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( fPosX , multiHeight ) ;
glTexCoord2f ( 0.0f , 1.0f ) ; glVertex2f ( fPosX , multiHeight ) ;
glEnd ( ) ;
glEnd ( ) ;
// TODO: Add SOLO / MULTIPLAYER text with font
// TODO: Add SOLO / MULTIPLAYER text with font
@@ -913,8 +915,8 @@ void Engine::Render(float elapsedTime) {
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 ) ;
m_time_SplashScreen + = elapsedTime ;
m_time_SplashScreen + = elapsedTime ;
if ( m_time_SplashScreen < 2 )
if ( m_time_SplashScreen < 2 )
DrawSplachScreen ( ) ;
DrawSplachScreen ( ) ;
else if ( m_gamestate = = GameState : : PLAY )
else if ( m_gamestate = = GameState : : PLAY )
{
{
HideCursor ( ) ;
HideCursor ( ) ;
@@ -950,11 +952,11 @@ void Engine::Render(float elapsedTime) {
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 ( ) , false , .8f ) ;
m_audio . Create3DAudioObj ( step , AUDIO_PATH " step.wav " , vstep , m_player . GetVelocity ( ) , false , .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 ( ) , false , 1.f ) ;
m_audio . Create3DAudioObj ( step , AUDIO_PATH " hit.wav " , m_player . GetPosition ( ) , m_player . GetVelocity ( ) , false , 1.f ) ;
break ;
break ;
default : break ;
default : break ;
}
}
@@ -995,32 +997,32 @@ void Engine::Render(float elapsedTime) {
glClearColor ( 0.f , 0.f , 0.f , 1.f ) ;
glClearColor ( 0.f , 0.f , 0.f , 1.f ) ;
return ;
return ;
}
}
}
}
}
}
else if ( m_mouseR )
else if ( m_mouseR )
m_world . ChangeBlockAtCursor ( BTYPE_AIR , m_player . GetPosition ( ) , m_player . GetDirection ( ) , m_block ) ;
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.
for ( int x = 0 ; x < MAX_BULLETS ; + + x ) { // Array de bullets en jeu.
if ( m_bullets [ x ] ) {
if ( m_bullets [ x ] ) {
for ( int b = 0 ; b < BULLET_UPDATES_PER_FRAME ; + + b ) {
for ( int b = 0 ; b < BULLET_UPDATES_PER_FRAME ; + + b ) {
if ( m_bullets [ x ] - > Update ( & m_world , elapsedTime , BULLET_UPDATES_PER_FRAME ) ) {
if ( m_bullets [ x ] - > Update ( & m_world , elapsedTime , BULLET_UPDATES_PER_FRAME ) ) {
m_bullets [ x ] - > ~ Bullet ( ) ;
m_bullets [ x ] - > ~ Bullet ( ) ;
if ( m_whoosh [ x ] )
if ( m_whoosh [ x ] )
m_whoosh [ x ] - > drop ( ) ;
m_whoosh [ x ] - > drop ( ) ;
m_bullets [ x ] = nullptr ;
m_bullets [ x ] = nullptr ;
m_whoosh [ x ] = nullptr ;
m_whoosh [ x ] = nullptr ;
break ;
break ;
}
}
else if ( ! m_whoosh [ x ] ) {
else if ( ! m_whoosh [ x ] ) {
m_whoosh [ x ] = m_audio . Create3DAudioObj ( m_whoosh [ x ] , AUDIO_PATH " noise.wav " , m_bullets [ x ] - > getPos ( ) , m_bullets [ x ] - > getVel ( ) , true , ( m_bullets [ x ] - > getPos ( ) - m_player . GetPosition ( ) ) . Length ( ) ) ;
m_whoosh [ x ] = m_audio . Create3DAudioObj ( m_whoosh [ x ] , AUDIO_PATH " noise.wav " , m_bullets [ x ] - > getPos ( ) , m_bullets [ x ] - > getVel ( ) , true , ( m_bullets [ x ] - > getPos ( ) - m_player . GetPosition ( ) ) . Length ( ) ) ;
}
}
else {
else {
Vector3f pos = m_bullets [ x ] - > getPos ( ) , vel = m_bullets [ x ] - > getVel ( ) ;
Vector3f pos = m_bullets [ x ] - > getPos ( ) , vel = m_bullets [ x ] - > getVel ( ) ;
m_audio . Render3DAudioObj ( m_whoosh [ x ] , pos , vel , 5 - ( m_bullets [ x ] - > getPos ( ) - m_player . GetPosition ( ) ) . Length ( ) ) ;
m_audio . Render3DAudioObj ( m_whoosh [ x ] , pos , vel , 5 - ( m_bullets [ x ] - > getPos ( ) - m_player . GetPosition ( ) ) . Length ( ) ) ;
}
}
}
}
}
}
}
}
m_renderer . RenderWorld ( & m_world , m_renderCount , m_player . GetPosition ( ) , m_player . GetDirection ( ) , all , m_shader01 , m_textureAtlas ) ;
m_renderer . 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_world . Update ( m_bullets , m_player . GetPosition ( ) , m_blockinfo ) ;
@@ -1034,7 +1036,7 @@ void Engine::Render(float elapsedTime) {
static bool fell = false ;
static bool fell = false ;
if ( m_player . GetPosition ( ) . y < 1.7f & & ! fell ) {
if ( m_player . GetPosition ( ) . y < 1.7f & & ! fell ) {
m_audio . Create3DAudioObj ( m_scream , AUDIO_PATH " scream.wav " , m_player . GetPOV ( ) , m_player . GetVelocity ( ) , false , 1.f ) ;
m_audio . Create3DAudioObj ( m_scream , AUDIO_PATH " scream.wav " , m_player . GetPOV ( ) , m_player . GetVelocity ( ) , false , 1.f ) ;
fell = true ;
fell = true ;
}
}
else if ( m_player . GetPosition ( ) . y < - 20.f ) {
else if ( m_player . GetPosition ( ) . y < - 20.f ) {
@@ -1181,7 +1183,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
case 15 :
case 15 :
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 ( ) - Vector3f ( 1.f , 0.f , 1.f ) , Vector3f ( 1.f , 0.f , 1.f ) ) ;
m_bullets [ x ] = new Bullet ( m_player . GetPOV ( ) - Vector3f ( 1.f , 0.f , 1.f ) , Vector3f ( 1.f , 0.f , 1.f ) ) ;
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.
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.