diff --git a/SDL#4/.vscode/c_cpp_properties.json b/SDL#4/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..3778e32 --- /dev/null +++ b/SDL#4/.vscode/c_cpp_properties.json @@ -0,0 +1,86 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "/usr/include", + "/usr/include/SDL2", + "/usr/local/include", + "${workspaceRoot}" + ], + "defines": [], + "intelliSenseMode": "clang-x64", + "browse": { + "path": [ + "/usr/include", + "/usr/local/include", + "${workspaceRoot}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + }, + "macFrameworkPath": [ + "/System/Library/Frameworks", + "/Library/Frameworks" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17" + }, + { + "name": "Linux", + "includePath": [ + "/usr/include/c++/5.4.0", + "/usr/include/x86_64-linux-gnu/c++/5.4.0", + "/usr/local/include", + "/usr/include", + "/usr/include/x86_64-linux-gnu", + "${workspaceRoot}", + "/usr/include/linux", + "/usr/include/linux", + "/usr/include/SDL2" + ], + "defines": [], + "intelliSenseMode": "clang-x64", + "browse": { + "path": [ + "/usr/include/c++/5.4.0", + "/usr/include/x86_64-linux-gnu/c++/5.4.0", + "/usr/local/include", + "/usr/include", + "/usr/include/x86_64-linux-gnu", + "${workspaceRoot}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + }, + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17" + }, + { + "name": "Win32", + "includePath": [ + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include", + "${workspaceRoot}" + ], + "defines": [ + "_DEBUG", + "UNICODE" + ], + "intelliSenseMode": "msvc-x64", + "browse": { + "path": [ + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", + "${workspaceRoot}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + }, + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/SDL#4/.vscode/settings.json b/SDL#4/.vscode/settings.json new file mode 100644 index 0000000..394516d --- /dev/null +++ b/SDL#4/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "iostream": "cpp", + "ctime": "cpp" + } +} \ No newline at end of file diff --git a/SDL#4/main.h b/SDL#4/main.h index 8f6bc4f..ec62fab 100644 --- a/SDL#4/main.h +++ b/SDL#4/main.h @@ -13,7 +13,7 @@ class xSprite; #include "xSDL.h" // Librairie perso #include "xMario.h" // Elements utiles au jeu - + #include "xSDL.cpp" // Librairie perso #include "xMario.cpp" // Elements utiles au jeu diff --git a/SDL#4/xMario/xMarioMario.cpp b/SDL#4/xMario/xMarioMario.cpp index 8559104..d24a4a8 100644 --- a/SDL#4/xMario/xMarioMario.cpp +++ b/SDL#4/xMario/xMarioMario.cpp @@ -102,7 +102,7 @@ void xMarioMario::spreadTurn(){ _pos = "TL"; return; } - + /* (1.2) HAUT - DROITE */ @@ -138,14 +138,14 @@ void xMarioMario::spreadTurn(){ // _pos = "BC"; return; } - - + + /* (2.1) BAS - GAUCHE */ }else if( left ){ // bl if( _pos != "BL" ){ return; } - + /* (2.2) BAS - DROITE */ @@ -172,8 +172,8 @@ void xMarioMario::spreadTurn(){ _pos = "NR"; return; } - - + + /* (3.1) NORMAL - GAUCHE */ }else if( left ){ // nl if( _pos != "NL" ){ @@ -186,7 +186,7 @@ void xMarioMario::spreadTurn(){ _pos = "NL"; return; } - + /* (3.2) NORMAL - DROITE */ diff --git a/SDL#4/xSDL/xManager.cpp b/SDL#4/xSDL/xManager.cpp index 1228cc0..fc66fc8 100644 --- a/SDL#4/xSDL/xManager.cpp +++ b/SDL#4/xSDL/xManager.cpp @@ -21,7 +21,7 @@ xManager::xManager(const char *t, int w, int h){ SDL_WINDOWPOS_CENTERED, w, h, - SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL + SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL ); // Gestion erreur @@ -180,7 +180,7 @@ bool xManager::hit(xSprite* current, int movex, int movey){ || (a.x+a.w > _winrect.x+_winrect.w ) // Inclus a gauche || (a.y < _winrect.y ) // Inclus en haut || (a.y+a.h > _winrect.y+_winrect.h ) // Inclus en bas - ){ + ){ // Si on tombe, on meurt if( a.y+a.h > _winrect.y+_winrect.h ) state = 2; @@ -236,7 +236,7 @@ bool xManager::hit(xSprite* current, int movex, int movey){ =========================================================*/ bool xManager::hit(string current, int movex, int movey){ if( !this->status() ) return true; - + _mutex_hit.try_lock(); /* (1) On recupere le SDL_Rect destination du sprite courant */ @@ -251,17 +251,17 @@ bool xManager::hit(string current, int movex, int movey){ // Retour du resultat _mutex_hit.unlock(); - return this->hit(sprite, movex, movey); + return this->hit(sprite, movex, movey); } -/* [GET] Renvoie le sprite +/* [GET] Renvoie le sprite =========================================================*/ xSprite *xManager::get(string index){ if( !this->status() ) return NULL; - + // On cherche la texture avec l'index for( int i = 0 ; i < _indexes.size() ; i++ ) @@ -361,10 +361,10 @@ void xManager::manageFps(const int fps){ if( !this->status() ) return; /* (1) Definition de fps */ - if( fps != 0 ) + if( fps != 0 ) _fpstime = 1000/fps; - if( _lasttick == 0 ) + if( _lasttick == 0 ) _lasttick = SDL_GetTicks()-_fpstime; /* (2) Utilisation en fin de boucle */ @@ -372,7 +372,7 @@ void xManager::manageFps(const int fps){ // 1 > Si trop rapide, on attends if( SDL_GetTicks()-_lasttick < _fpstime ) SDL_Delay( _fpstime - (SDL_GetTicks()-_lasttick) ); - + // On enregistre le temps actuel _lasttick = SDL_GetTicks(); } @@ -474,6 +474,6 @@ void xManager::manageEvents(SDL_Event *event){ void xManager::debug(){ for( int i = 0 ; i < _sprites.size() ; i++ ){ cerr << "INDEX: " << _indexes[i] << " AT " << i << endl; - cerr << " (" << (*_sprites[i]->dst()).x <<","<<(*_sprites[i]->dst()).y<<") -> (" << (*_sprites[i]->dst()).w << ", " << (*_sprites[i]->dst()).h << ")" << endl; + cerr << " (" << (*_sprites[i]->dst()).x <<","<<(*_sprites[i]->dst()).y<<") -> (" << (*_sprites[i]->dst()).w << ", " << (*_sprites[i]->dst()).h << ")" << endl; } } \ No newline at end of file diff --git a/SDL#4/xSDL/xManager.h b/SDL#4/xSDL/xManager.h index 6b50ae1..08659b0 100644 --- a/SDL#4/xSDL/xManager.h +++ b/SDL#4/xSDL/xManager.h @@ -40,7 +40,7 @@ // 0 -> Boucle infinie // 1 -> Arret jeu // 2 -> mort - + // DEBUG void debug(); diff --git a/SDL#4/xSDL/xSprite.cpp b/SDL#4/xSDL/xSprite.cpp index 8c0e4a6..07172bd 100644 --- a/SDL#4/xSDL/xSprite.cpp +++ b/SDL#4/xSDL/xSprite.cpp @@ -32,7 +32,7 @@ xSprite::xSprite(xManager *m, const int rgb[]){ // On recupere la couleur Uint32 color = SDL_MapRGBA( surf->format, rgb[0], rgb[1], rgb[2], rgb[3]); - + // On cree la texture a partir de la surface _texture = SDL_CreateTextureFromSurface(_manager->renderer(), surf); @@ -50,7 +50,7 @@ xSprite::xSprite(xManager *m, const int rgb[]){ =========================================================*/ xSprite::xSprite(xManager *m, const char *url){ _type = "basic"; - + _manager = m; _texture = NULL; @@ -66,7 +66,7 @@ xSprite::xSprite(xManager *m, const char *url){ =========================================================*/ xSprite::xSprite(xManager *m, SDL_Texture *t){ _type = "basic"; - + _manager = m; _texture = t; @@ -87,7 +87,7 @@ void xSprite::setTexture(const int rgb[]){ // On recupere la couleur Uint32 color = SDL_MapRGBA( surf->format, rgb[0], rgb[1], rgb[2], rgb[3]); - + // On cree la texture a partir de la surface _texture = SDL_CreateTextureFromSurface(_manager->renderer(), surf); @@ -118,7 +118,7 @@ void xSprite::setTexture(const char *url){ =========================================================*/ void xSprite::setTexture(SDL_Texture *t){ _type = "basic"; - + _texture = NULL; _texture = t; @@ -140,7 +140,7 @@ vector xSprite::move(int x, int y){ vector result(2, 0); - + /* (1) Variables utiles */ int incrx = x; @@ -169,7 +169,7 @@ vector xSprite::move(int x, int y){ _mutex_move.unlock(); return result; } - + /* (4) Sinon, on decremente les deplacements 'alternativement' */ @@ -195,7 +195,7 @@ vector xSprite::move(int x, int y){ // } } - // retour + // retour _mutex_move.unlock(); return result; } @@ -211,7 +211,7 @@ void xSprite::onCollide(vector from, xSprite* by){ // if( from[0] == 0 && from[1] == 0 ) // return; - + // cerr << _type << " collided with " << by->_type << " from "; // if( from[0] != 0 ) @@ -263,7 +263,7 @@ void xSprite::dimensions(SDL_Rect r){ /* [DIMENSIONS] Definition des dimensions de la texture+clip =========================================================*/ -void xSprite::dimensions(SDL_Rect r, SDL_Rect clip){ +void xSprite::dimensions(SDL_Rect r, SDL_Rect clip){ /* (1) On definit les dimensions */ _dst = (SDL_Rect){r.x, r.y, r.w, r.h}; _src = (SDL_Rect){clip.x, clip.y, clip.w, clip.h}; @@ -281,13 +281,13 @@ void xSprite::push(string index){ =========================================================*/ void xSprite::pull(string index){ _index = index; - + _manager->pull( index ); } /* [PULL] Retire une sprite du rendu =========================================================*/ -void xSprite::pull(){ +void xSprite::pull(){ _manager->pull( this ); } diff --git a/SDL#4/xSDL/xSprite.h b/SDL#4/xSDL/xSprite.h index 7f1b27a..e7b87c9 100644 --- a/SDL#4/xSDL/xSprite.h +++ b/SDL#4/xSDL/xSprite.h @@ -5,7 +5,7 @@ class xSprite{ public: - xSprite(xManager *m); // Sprite vide + xSprite(xManager *m); // Sprite vide xSprite(xManager *m, const int rgb[]); // Sprite couleur xSprite(xManager *m, const char *url); // Sprite image xSprite(xManager *m, SDL_Texture *t); // Sprite texture