@@ -280,7 +280,6 @@ void Engine::Init() {
}
uint64_t seed = SEED ;
char ch ;
glDisable ( GL_FRAMEBUFFER_SRGB ) ;
glEnable ( GL_DEPTH_TEST ) ;
@@ -314,50 +313,53 @@ void Engine::Init() {
m_whoosh [ x ] = nullptr ;
}
std : : cout < < " Jouer en ligne? [o/N] " ;
std : : cin > > ch ;
std : : cout < < std : : endl ;
char * ch = new char [ 2 ] ;
if ( ch = = ' o ' | | ch = = ' O ' ) {
char * input = new char [ 3 2 ] ;
std : : string playname , srvname ;
std : : cout < < " Jouer en ligne? [o/N] " ;
std : : cin . getline ( ch , 2) ;
std : : cout < < std : : endl ;
while ( playname . size ( ) < 1 ) {
std : : cout < < " Veuillez entrer un nom de joueur: " ;
std : : cin . ignore ( ) ;
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 ( * ch = = ' o ' | | * ch = = ' O ' ) {
char * input = new char [ 32 ] ;
std : : string playname , srvname ;
if ( ! m_conn . Init ( ) ) {
if ( ! m_conn . Connect ( srvname . c_str ( ) , playname ) ) {
// setup jeu en reseau.
std : : cout < < " ID recu du serveur: " < < std : : to_str ing ( 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 ;
while ( playname . size ( ) < 1 ) {
std : : cout < < " Veuillez entrer un nom de joueur: " ;
std : : cin . ignore ( ) ;
std : : cin . getl ine ( 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 ( ) ) {
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 ) ;
@@ -913,8 +915,8 @@ void Engine::Render(float elapsedTime) {
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ;
m_time_SplashScreen + = elapsedTime ;
if ( m_time_SplashScreen < 2 )
DrawSplachScreen ( ) ;
if ( m_time_SplashScreen < 2 )
DrawSplachScreen ( ) ;
else if ( m_gamestate = = GameState : : PLAY )
{
HideCursor ( ) ;
@@ -950,11 +952,11 @@ void Engine::Render(float elapsedTime) {
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 ( ) , false , .8f ) ;
m_audio . Create3DAudioObj ( step , AUDIO_PATH " step.wav " , vstep , m_player . GetVelocity ( ) , false , .8f ) ;
leftright = ! leftright ;
break ;
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 ;
default : break ;
}
@@ -995,32 +997,32 @@ void Engine::Render(float elapsedTime) {
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 ) ;
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 ] ) {
for ( int b = 0 ; b < BULLET_UPDATES_PER_FRAME ; + + b ) {
if ( m_bullets [ x ] - > Update ( & m_world , elapsedTime , BULLET_UPDATES_PER_FRAME ) ) {
m_bullets [ x ] - > ~ Bullet ( ) ;
if ( m_whoosh [ x ] )
m_whoosh [ x ] - > drop ( ) ;
m_bullets [ x ] = nullptr ;
m_whoosh [ x ] = nullptr ;
break ;
}
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 ( ) ) ;
}
else {
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 ( ) ) ;
for ( int x = 0 ; x < MAX_BULLETS ; + + x ) { // Array de bullets en jeu.
if ( m_bullets [ x ] ) {
for ( int b = 0 ; b < BULLET_UPDATES_PER_FRAME ; + + b ) {
if ( m_bullets [ x ] - > Update ( & m_world , elapsedTime , BULLET_UPDATES_PER_FRAME ) ) {
m_bullets [ x ] - > ~ Bullet ( ) ;
if ( m_whoosh [ x ] )
m_whoosh [ x ] - > drop ( ) ;
m_bullets [ x ] = nullptr ;
m_whoosh [ x ] = nullptr ;
break ;
}
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 ( ) ) ;
}
else {
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_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 ) ;
@@ -1034,7 +1036,7 @@ void Engine::Render(float elapsedTime) {
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 ( ) , false , 1.f ) ;
m_audio . Create3DAudioObj ( m_scream , AUDIO_PATH " scream.wav " , m_player . GetPOV ( ) , m_player . GetVelocity ( ) , false , 1.f ) ;
fell = true ;
}
else if ( m_player . GetPosition ( ) . y < - 20.f ) {
@@ -1181,7 +1183,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
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").
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 ;
}
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.