new branch
This commit is contained in:
parent
29d8287d87
commit
15576c8cfe
|
@ -0,0 +1,184 @@
|
||||||
|
INDEX: bottom-left0 AT 0
|
||||||
|
(-32,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left1 AT 1
|
||||||
|
(0,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left2 AT 2
|
||||||
|
(32,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left3 AT 3
|
||||||
|
(64,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left4 AT 4
|
||||||
|
(96,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left5 AT 5
|
||||||
|
(128,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left6 AT 6
|
||||||
|
(160,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left7 AT 7
|
||||||
|
(192,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left8 AT 8
|
||||||
|
(224,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left9 AT 9
|
||||||
|
(256,576) -> (32, 32)
|
||||||
|
INDEX: bottom-left10 AT 10
|
||||||
|
(-32,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left11 AT 11
|
||||||
|
(0,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left12 AT 12
|
||||||
|
(32,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left13 AT 13
|
||||||
|
(64,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left14 AT 14
|
||||||
|
(96,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left15 AT 15
|
||||||
|
(128,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left16 AT 16
|
||||||
|
(160,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left17 AT 17
|
||||||
|
(192,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left18 AT 18
|
||||||
|
(224,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left19 AT 19
|
||||||
|
(256,608) -> (32, 32)
|
||||||
|
INDEX: bottom-left20 AT 20
|
||||||
|
(-32,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left21 AT 21
|
||||||
|
(0,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left22 AT 22
|
||||||
|
(32,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left23 AT 23
|
||||||
|
(64,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left24 AT 24
|
||||||
|
(96,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left25 AT 25
|
||||||
|
(128,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left26 AT 26
|
||||||
|
(160,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left27 AT 27
|
||||||
|
(192,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left28 AT 28
|
||||||
|
(224,640) -> (32, 32)
|
||||||
|
INDEX: bottom-left29 AT 29
|
||||||
|
(256,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center0 AT 30
|
||||||
|
(384,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center1 AT 31
|
||||||
|
(416,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center2 AT 32
|
||||||
|
(448,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center3 AT 33
|
||||||
|
(480,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center4 AT 34
|
||||||
|
(512,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center5 AT 35
|
||||||
|
(544,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center6 AT 36
|
||||||
|
(576,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center7 AT 37
|
||||||
|
(608,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center8 AT 38
|
||||||
|
(640,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center9 AT 39
|
||||||
|
(672,576) -> (32, 32)
|
||||||
|
INDEX: bottom-center10 AT 40
|
||||||
|
(384,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center11 AT 41
|
||||||
|
(416,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center12 AT 42
|
||||||
|
(448,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center13 AT 43
|
||||||
|
(480,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center14 AT 44
|
||||||
|
(512,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center15 AT 45
|
||||||
|
(544,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center16 AT 46
|
||||||
|
(576,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center17 AT 47
|
||||||
|
(608,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center18 AT 48
|
||||||
|
(640,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center19 AT 49
|
||||||
|
(672,608) -> (32, 32)
|
||||||
|
INDEX: bottom-center20 AT 50
|
||||||
|
(384,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center21 AT 51
|
||||||
|
(416,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center22 AT 52
|
||||||
|
(448,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center23 AT 53
|
||||||
|
(480,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center24 AT 54
|
||||||
|
(512,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center25 AT 55
|
||||||
|
(544,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center26 AT 56
|
||||||
|
(576,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center27 AT 57
|
||||||
|
(608,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center28 AT 58
|
||||||
|
(640,640) -> (32, 32)
|
||||||
|
INDEX: bottom-center29 AT 59
|
||||||
|
(672,640) -> (32, 32)
|
||||||
|
INDEX: float-center0 AT 60
|
||||||
|
(160,64) -> (32, 32)
|
||||||
|
INDEX: float-center1 AT 61
|
||||||
|
(192,64) -> (32, 32)
|
||||||
|
INDEX: float-center2 AT 62
|
||||||
|
(224,64) -> (32, 32)
|
||||||
|
INDEX: float-center3 AT 63
|
||||||
|
(256,64) -> (32, 32)
|
||||||
|
INDEX: float-center4 AT 64
|
||||||
|
(288,64) -> (32, 32)
|
||||||
|
INDEX: float-center5 AT 65
|
||||||
|
(160,96) -> (32, 32)
|
||||||
|
INDEX: float-center6 AT 66
|
||||||
|
(192,96) -> (32, 32)
|
||||||
|
INDEX: float-center7 AT 67
|
||||||
|
(224,96) -> (32, 32)
|
||||||
|
INDEX: float-center8 AT 68
|
||||||
|
(256,96) -> (32, 32)
|
||||||
|
INDEX: float-center9 AT 69
|
||||||
|
(288,96) -> (32, 32)
|
||||||
|
INDEX: float-center10 AT 70
|
||||||
|
(160,128) -> (32, 32)
|
||||||
|
INDEX: float-center11 AT 71
|
||||||
|
(192,128) -> (32, 32)
|
||||||
|
INDEX: float-center12 AT 72
|
||||||
|
(224,128) -> (32, 32)
|
||||||
|
INDEX: float-center13 AT 73
|
||||||
|
(256,128) -> (32, 32)
|
||||||
|
INDEX: float-center14 AT 74
|
||||||
|
(288,128) -> (32, 32)
|
||||||
|
INDEX: float-center15 AT 75
|
||||||
|
(160,160) -> (32, 32)
|
||||||
|
INDEX: float-center16 AT 76
|
||||||
|
(192,160) -> (32, 32)
|
||||||
|
INDEX: float-center17 AT 77
|
||||||
|
(224,160) -> (32, 32)
|
||||||
|
INDEX: float-center18 AT 78
|
||||||
|
(256,160) -> (32, 32)
|
||||||
|
INDEX: float-center19 AT 79
|
||||||
|
(288,160) -> (32, 32)
|
||||||
|
INDEX: float-center20 AT 80
|
||||||
|
(160,192) -> (32, 32)
|
||||||
|
INDEX: float-center21 AT 81
|
||||||
|
(192,192) -> (32, 32)
|
||||||
|
INDEX: float-center22 AT 82
|
||||||
|
(224,192) -> (32, 32)
|
||||||
|
INDEX: float-center23 AT 83
|
||||||
|
(256,192) -> (32, 32)
|
||||||
|
INDEX: float-center24 AT 84
|
||||||
|
(288,192) -> (32, 32)
|
||||||
|
INDEX: brick1 AT 85
|
||||||
|
(128,448) -> (32, 32)
|
||||||
|
INDEX: mystery-bloc AT 86
|
||||||
|
(160,448) -> (32, 32)
|
||||||
|
INDEX: brick2 AT 87
|
||||||
|
(192,448) -> (32, 32)
|
||||||
|
INDEX: mystery-bloc2 AT 88
|
||||||
|
(480,448) -> (32, 32)
|
||||||
|
INDEX: mystery-bloc3 AT 89
|
||||||
|
(544,480) -> (32, 32)
|
||||||
|
INDEX: mystery-bloc4 AT 90
|
||||||
|
(608,512) -> (32, 32)
|
||||||
|
INDEX: mario AT 91
|
||||||
|
(547,544) -> (25, 32)
|
2835
SDL#4/err.log
2835
SDL#4/err.log
File diff suppressed because it is too large
Load Diff
|
@ -101,6 +101,12 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
mgr->debug();
|
mgr->debug();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Boucle de traitement
|
// Boucle de traitement
|
||||||
mgr->update();
|
mgr->update();
|
||||||
mgr->manageFps(FPS);
|
mgr->manageFps(FPS);
|
||||||
|
@ -130,6 +136,7 @@ int main(int argc, char* argv[]) {
|
||||||
else mb2.unjump();
|
else mb2.unjump();
|
||||||
|
|
||||||
if( mgr->hit("mystery-bloc4", 0, 1) ) mb3.jump();
|
if( mgr->hit("mystery-bloc4", 0, 1) ) mb3.jump();
|
||||||
|
|
||||||
else mb3.unjump();
|
else mb3.unjump();
|
||||||
|
|
||||||
mgr->manageFps(); // Gestion des FPS (speed)
|
mgr->manageFps(); // Gestion des FPS (speed)
|
||||||
|
|
BIN
SDL#4/main.o
BIN
SDL#4/main.o
Binary file not shown.
|
@ -1,6 +1,7 @@
|
||||||
A FAIRE
|
A FAIRE
|
||||||
=======
|
=======
|
||||||
- [ ] Ajout d'objets et non uniquement de SDL_Textures au xManager
|
- [ ] @pushsprites Ajout de Sprites et non uniquement de SDL_Textures au xManager
|
||||||
|
|
||||||
- [x][ ] Gestion du saut unique ou double (limitation)
|
- [x][ ] Gestion du saut unique ou double (limitation)
|
||||||
|
|
||||||
EN COURS
|
EN COURS
|
||||||
|
@ -8,14 +9,13 @@ EN COURS
|
||||||
- [ ] Optimisation/Correction des collisions (hit + move)
|
- [ ] Optimisation/Correction des collisions (hit + move)
|
||||||
- [ ] Erreur de hit()
|
- [ ] Erreur de hit()
|
||||||
- [x] Optimisation de la correction apres saut
|
- [x] Optimisation de la correction apres saut
|
||||||
- [..] Correction du move qui fait friser parfois
|
- [x] Correction du move qui fait friser parfois
|
||||||
- [ ] Liberation memoire car lag
|
- [ ] Liberation memoire car lag
|
||||||
- [...] Gestion sprites de mario en fonction mouvement
|
- [...] Gestion sprites de mario en fonction mouvement
|
||||||
|
|
||||||
- [ ] Permettre a move() de renvoyer qqch
|
|
||||||
|
|
||||||
FAIT
|
FAIT
|
||||||
====
|
====
|
||||||
|
- [x] Permettre a move() de renvoyer qqch
|
||||||
- [x] Gestion velocite pour deplacement
|
- [x] Gestion velocite pour deplacement
|
||||||
- [x] Gestion de l'acceleration
|
- [x] Gestion de l'acceleration
|
||||||
- [x] Gestion de la gravite
|
- [x] Gestion de la gravite
|
||||||
|
|
|
@ -54,18 +54,16 @@ void xMarioMario::moveFromVelocity(){
|
||||||
/* (1) Si aucune collision, on deplace */
|
/* (1) Si aucune collision, on deplace */
|
||||||
vector<int> after = this->move(_velocity[0], _velocity[1]);
|
vector<int> after = this->move(_velocity[0], _velocity[1]);
|
||||||
|
|
||||||
// after[0] -> sens sur x de la collision
|
|
||||||
// after[1] -> sens sur y de la collision
|
|
||||||
|
|
||||||
if( after[2] != ((int)_velocity[0]) )
|
// if( _velocity[0] != after[2] && after[0] != 0 )
|
||||||
cerr << "collision X -> " << _velocity[0] << " to " << after[2] << endl;
|
// cerr << "collision from " << ((after[0]==1)?"right":"left") << " at " << (_dst.x+after[2]) << endl;
|
||||||
|
|
||||||
if( after[3] != ((int)_velocity[1]) )
|
// if( _velocity[1] != after[3] && after[1] != 0 )
|
||||||
cerr << "collision Y -> " << _velocity[1] << " to " << after[3] << endl;
|
// cerr << "collision from " << ((after[1]==1)?"bottom":"top") << " at " << (_dst.y+after[3]) <<endl;
|
||||||
|
|
||||||
/* (2) On modifie la velocite en fonction des collisions */
|
/* (2) On modifie la velocite en fonction des collisions */
|
||||||
_velocity[0] = (double) after[0];
|
_velocity[0] = (double) after[2];
|
||||||
_velocity[1] = (double) after[1];
|
_velocity[1] = (double) after[3];
|
||||||
|
|
||||||
|
|
||||||
/* (3) Modification du sprite en fonction du mouvement */
|
/* (3) Modification du sprite en fonction du mouvement */
|
||||||
|
@ -107,11 +105,11 @@ void xMarioMario::moveFromVelocity(){
|
||||||
|
|
||||||
|
|
||||||
/* (8) Gestion du temps */
|
/* (8) Gestion du temps */
|
||||||
if( abs(_velocity[0]) > 0 )
|
// if( abs(_velocity[0]) > 0 )
|
||||||
cerr << "x -> " << _velocity[0] << endl;
|
// cerr << "x -> " << _velocity[0] << endl;
|
||||||
|
|
||||||
if( abs(_velocity[1]) > 0 )
|
// if( abs(_velocity[1]) > 0 )
|
||||||
cerr << "y -> " << _velocity[1] << endl;
|
// cerr << "y -> " << _velocity[1] << endl;
|
||||||
|
|
||||||
// cout << endl;
|
// cout << endl;
|
||||||
// usleep(20000);
|
// usleep(20000);
|
||||||
|
|
|
@ -11,7 +11,7 @@ xManager::xManager(const char *t, int w, int h){
|
||||||
_debug = (SDL_Rect){0, 0, 0, 0};
|
_debug = (SDL_Rect){0, 0, 0, 0};
|
||||||
|
|
||||||
// Initialisation des sous-sys. SDL
|
// Initialisation des sous-sys. SDL
|
||||||
SDL_Init( SDL_INIT_EVERYTHING );
|
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
|
||||||
|
|
||||||
|
|
||||||
// Creation de la fenetre
|
// Creation de la fenetre
|
||||||
|
@ -21,13 +21,15 @@ xManager::xManager(const char *t, int w, int h){
|
||||||
SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
w,
|
w,
|
||||||
h,
|
h,
|
||||||
SDL_WINDOW_SHOWN
|
SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL
|
||||||
);
|
);
|
||||||
|
|
||||||
// Gestion erreur
|
// Gestion erreur
|
||||||
if( _window == NULL )
|
if( _window == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
cerr << "WINDOW CREATED" << endl;
|
||||||
|
|
||||||
|
|
||||||
// On enregistre les dimensions de la fenetre
|
// On enregistre les dimensions de la fenetre
|
||||||
_winrect.x = 0; _winrect.y = 0;
|
_winrect.x = 0; _winrect.y = 0;
|
||||||
|
@ -41,6 +43,12 @@ xManager::xManager(const char *t, int w, int h){
|
||||||
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
|
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Gestion erreur
|
||||||
|
if( _renderer == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
cerr << "RENDERER CREATED" << endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* [DESTROYER] Destructeur de la classe
|
/* [DESTROYER] Destructeur de la classe
|
||||||
|
@ -72,6 +80,8 @@ SDL_Renderer* xManager::renderer(){ return _renderer; }
|
||||||
/* [SETBACKGROUND] Modifie la couleur de fond
|
/* [SETBACKGROUND] Modifie la couleur de fond
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
bool xManager::setBackground(Uint8 r, Uint8 g, Uint8 b, Uint8 a){
|
bool xManager::setBackground(Uint8 r, Uint8 g, Uint8 b, Uint8 a){
|
||||||
|
if( !this->status() ) return false;
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor( _renderer, r, g, b, a );
|
SDL_SetRenderDrawColor( _renderer, r, g, b, a );
|
||||||
|
|
||||||
|
@ -81,6 +91,7 @@ bool xManager::setBackground(Uint8 r, Uint8 g, Uint8 b, Uint8 a){
|
||||||
/* [SETIMAGE] Met une image en fond
|
/* [SETIMAGE] Met une image en fond
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
bool xManager::setImage(const char *url){
|
bool xManager::setImage(const char *url){
|
||||||
|
if( !this->status() ) return false;
|
||||||
|
|
||||||
// On cree la texture associee
|
// On cree la texture associee
|
||||||
_texture = IMG_LoadTexture( _renderer, url );
|
_texture = IMG_LoadTexture( _renderer, url );
|
||||||
|
@ -165,12 +176,22 @@ bool xManager::setImage(const char *url){
|
||||||
/* [COLLIDE] Retourne si 2 objets sont en collision
|
/* [COLLIDE] Retourne si 2 objets sont en collision
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
bool xManager::collide(SDL_Rect a, SDL_Rect b){
|
bool xManager::collide(SDL_Rect a, SDL_Rect b){
|
||||||
|
if( !this->status() ) return true;
|
||||||
|
|
||||||
bool notCollide =
|
bool notCollide =
|
||||||
(a.x >= b.x+b.w ) // Inclus a droite
|
(a.x >= b.x+b.w ) // Inclus a droite
|
||||||
|| (a.x+a.w <= b.x ) // Inclus a gauche
|
|| (a.x+a.w <= b.x ) // Inclus a gauche
|
||||||
|| (a.y >= b.y+b.h ) // Inclus en haut
|
|| (a.y >= b.y+b.h ) // Inclus en haut
|
||||||
|| (a.y+a.h <= b.y ); // Inclus en bas
|
|| (a.y+a.h <= b.y ); // Inclus en bas
|
||||||
|
|
||||||
|
// bool collide = (
|
||||||
|
// ( ( a.x > b.x && a.x < b.x+b.w )
|
||||||
|
// || ( a.x+a.w > b.x && a.x+a.w < b.x+b.w ) )
|
||||||
|
// &&
|
||||||
|
// ( ( a.y > b.y && a.y < b.y+b.h )
|
||||||
|
// || ( a.y+a.h > b.y && a.y+a.h < b.y+b.h ) )
|
||||||
|
// );
|
||||||
|
|
||||||
return !notCollide;
|
return !notCollide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +203,8 @@ bool xManager::collide(SDL_Rect a, SDL_Rect b){
|
||||||
/* [HIT] Retourne si une texture est en collision avec une autre
|
/* [HIT] Retourne si une texture est en collision avec une autre
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
bool xManager::hit(SDL_Texture *current, int movex, int movey){
|
bool xManager::hit(SDL_Texture *current, int movex, int movey){
|
||||||
|
if( !this->status() ) return true;
|
||||||
|
|
||||||
// Anti conflit inter-thread
|
// Anti conflit inter-thread
|
||||||
_mutex_hit.lock();
|
_mutex_hit.lock();
|
||||||
|
|
||||||
|
@ -229,8 +252,8 @@ bool xManager::hit(SDL_Texture *current, int movex, int movey){
|
||||||
if( this->collide(a, *_dst[i]) ){
|
if( this->collide(a, *_dst[i]) ){
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
if( i != 35 )
|
// if( i != 35 )
|
||||||
cerr << "locked by sprite " << i << endl;
|
// cerr << "locked by sprite " << i << endl;
|
||||||
|
|
||||||
_debug = *_dst[i];
|
_debug = *_dst[i];
|
||||||
// _debug = (SDL_Rect){547-1, 531-1, 2, 2};
|
// _debug = (SDL_Rect){547-1, 531-1, 2, 2};
|
||||||
|
@ -255,6 +278,8 @@ bool xManager::hit(SDL_Texture *current, int movex, int movey){
|
||||||
/* [HIT] Retourne si une texture est en collision avec une autre
|
/* [HIT] Retourne si une texture est en collision avec une autre
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
bool xManager::hit(string current, int movex, int movey){
|
bool xManager::hit(string current, int movex, int movey){
|
||||||
|
if( !this->status() ) return true;
|
||||||
|
|
||||||
_mutex_hit.lock();
|
_mutex_hit.lock();
|
||||||
|
|
||||||
/* (1) On recupere le SDL_Rect destination du sprite courant */
|
/* (1) On recupere le SDL_Rect destination du sprite courant */
|
||||||
|
@ -278,6 +303,8 @@ bool xManager::hit(string current, int movex, int movey){
|
||||||
/* [GETTEXTURE] Renvoie la texture
|
/* [GETTEXTURE] Renvoie la texture
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
SDL_Texture *xManager::getTexture(string index){
|
SDL_Texture *xManager::getTexture(string index){
|
||||||
|
if( !this->status() ) return NULL;
|
||||||
|
|
||||||
|
|
||||||
// On cherche la texture avec l'index
|
// On cherche la texture avec l'index
|
||||||
for( int i = 0 ; i < _indexes.size() ; i++ )
|
for( int i = 0 ; i < _indexes.size() ; i++ )
|
||||||
|
@ -291,6 +318,7 @@ SDL_Texture *xManager::getTexture(string index){
|
||||||
/* [GETSRC] Renvoie le SDL_Rect source
|
/* [GETSRC] Renvoie le SDL_Rect source
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
SDL_Rect *xManager::getSrc(string index){
|
SDL_Rect *xManager::getSrc(string index){
|
||||||
|
if( !this->status() ) return NULL;
|
||||||
|
|
||||||
// On cherche la texture avec l'index
|
// On cherche la texture avec l'index
|
||||||
for( int i = 0 ; i < _indexes.size() ; i++ )
|
for( int i = 0 ; i < _indexes.size() ; i++ )
|
||||||
|
@ -304,6 +332,7 @@ SDL_Rect *xManager::getSrc(string index){
|
||||||
/* [GETDST] Renvoie le SDL_Rect destination
|
/* [GETDST] Renvoie le SDL_Rect destination
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
SDL_Rect *xManager::getDst(string index){
|
SDL_Rect *xManager::getDst(string index){
|
||||||
|
if( !this->status() ) return NULL;
|
||||||
|
|
||||||
// On cherche la texture avec l'index
|
// On cherche la texture avec l'index
|
||||||
for( int i = 0 ; i < _indexes.size() ; i++ )
|
for( int i = 0 ; i < _indexes.size() ; i++ )
|
||||||
|
@ -318,6 +347,8 @@ SDL_Rect *xManager::getDst(string index){
|
||||||
/* [PUSH] Ajoute une texture au rendu principal
|
/* [PUSH] Ajoute une texture au rendu principal
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
void xManager::push(string index, SDL_Texture *t, SDL_Rect *src, SDL_Rect *dst){
|
void xManager::push(string index, SDL_Texture *t, SDL_Rect *src, SDL_Rect *dst){
|
||||||
|
if( !this->status() ) return;
|
||||||
|
|
||||||
// On bloque l'acces inter-thread
|
// On bloque l'acces inter-thread
|
||||||
_mutex_push.lock();
|
_mutex_push.lock();
|
||||||
|
|
||||||
|
@ -334,6 +365,8 @@ void xManager::push(string index, SDL_Texture *t, SDL_Rect *src, SDL_Rect *dst){
|
||||||
/* [PULL] Retire une texture du rendu principal
|
/* [PULL] Retire une texture du rendu principal
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
void xManager::pull(string index){
|
void xManager::pull(string index){
|
||||||
|
if( !this->status() ) return;
|
||||||
|
|
||||||
// On bloque l'acces inter-thread
|
// On bloque l'acces inter-thread
|
||||||
_mutex_pull.lock();
|
_mutex_pull.lock();
|
||||||
|
|
||||||
|
@ -361,6 +394,8 @@ void xManager::pull(string index){
|
||||||
/* [PULL] Retire une texture du rendu principal
|
/* [PULL] Retire une texture du rendu principal
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
void xManager::pull(SDL_Texture *t){
|
void xManager::pull(SDL_Texture *t){
|
||||||
|
if( !this->status() ) return;
|
||||||
|
|
||||||
// On bloque l'acces inter-thread
|
// On bloque l'acces inter-thread
|
||||||
_mutex_pull.lock();
|
_mutex_pull.lock();
|
||||||
|
|
||||||
|
@ -391,6 +426,8 @@ void xManager::pull(SDL_Texture *t){
|
||||||
/* [MANAGEFTP] Gestion de la vitesse de boucle
|
/* [MANAGEFTP] Gestion de la vitesse de boucle
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
void xManager::manageFps(const int fps){
|
void xManager::manageFps(const int fps){
|
||||||
|
if( !this->status() ) return;
|
||||||
|
|
||||||
/* (1) Definition de fps */
|
/* (1) Definition de fps */
|
||||||
if( fps != 0 )
|
if( fps != 0 )
|
||||||
_fpstime = 1000/fps;
|
_fpstime = 1000/fps;
|
||||||
|
@ -415,6 +452,8 @@ void xManager::manageFps(const int fps){
|
||||||
/* [UPDATE] Mise a jour du rendu
|
/* [UPDATE] Mise a jour du rendu
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
void xManager::update(){
|
void xManager::update(){
|
||||||
|
if( !this->status() ) return;
|
||||||
|
|
||||||
|
|
||||||
// cout << "Update MAIN SPRITE +" << _sprites.size() << " added sprites.." << endl;
|
// cout << "Update MAIN SPRITE +" << _sprites.size() << " added sprites.." << endl;
|
||||||
// On bloque l'acces inter-thread
|
// On bloque l'acces inter-thread
|
||||||
|
@ -451,6 +490,8 @@ void xManager::update(){
|
||||||
/* [ATTACHEVENT] Ajoute une fonction a un type d'evenement
|
/* [ATTACHEVENT] Ajoute une fonction a un type d'evenement
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
void xManager::attachEvent(SDL_EventType t, void(*handler)(SDL_Event*)){
|
void xManager::attachEvent(SDL_EventType t, void(*handler)(SDL_Event*)){
|
||||||
|
if( !this->status() ) return;
|
||||||
|
|
||||||
|
|
||||||
// On attache le type d'evenement a la fonction
|
// On attache le type d'evenement a la fonction
|
||||||
_events.push_back( t );
|
_events.push_back( t );
|
||||||
|
@ -463,6 +504,8 @@ void xManager::attachEvent(SDL_EventType t, void(*handler)(SDL_Event*)){
|
||||||
/* [MANAGEEVENTS] Gestion des evenements
|
/* [MANAGEEVENTS] Gestion des evenements
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
void xManager::manageEvents(SDL_Event *event){
|
void xManager::manageEvents(SDL_Event *event){
|
||||||
|
if( !this->status() ) return;
|
||||||
|
|
||||||
// On lance les evenements en fonction de leur type
|
// On lance les evenements en fonction de leur type
|
||||||
for( int i = 0 ; i < _events.size() ; i ++ )
|
for( int i = 0 ; i < _events.size() ; i ++ )
|
||||||
if( event->type == _events[i] ) // si type ok
|
if( event->type == _events[i] ) // si type ok
|
||||||
|
|
|
@ -115,8 +115,8 @@ vector<int> xSprite::move(int x, int y){
|
||||||
|
|
||||||
|
|
||||||
vector<int> result;
|
vector<int> result;
|
||||||
result.push_back(0);
|
result.push_back( (x!=0) ? (int)( x / abs(x) ) : 0 );
|
||||||
result.push_back(0);
|
result.push_back( (y!=0) ? (int)( y / abs(y) ) : 0 );
|
||||||
result.push_back(0);
|
result.push_back(0);
|
||||||
result.push_back(0);
|
result.push_back(0);
|
||||||
|
|
||||||
|
@ -137,10 +137,10 @@ vector<int> xSprite::move(int x, int y){
|
||||||
_dst.x += incrx;
|
_dst.x += incrx;
|
||||||
_dst.y += incry;
|
_dst.y += incry;
|
||||||
|
|
||||||
cerr << ">>> not locked <<<" << endl;
|
// cerr << ">>> not locked <<<" << endl;
|
||||||
|
|
||||||
result[0] = incrx;
|
result[2] = incrx;
|
||||||
result[1] = incry;
|
result[3] = incry;
|
||||||
|
|
||||||
_mutex_move.unlock();
|
_mutex_move.unlock();
|
||||||
return result;
|
return result;
|
||||||
|
@ -165,14 +165,14 @@ vector<int> xSprite::move(int x, int y){
|
||||||
return result; // On arrete de chercher
|
return result; // On arrete de chercher
|
||||||
}
|
}
|
||||||
|
|
||||||
// if( !_manager->hit(_texture, 0, 1) )
|
// if( !_manager->hit(_texture, 0, 1) ){
|
||||||
// cerr << "locked from (" << _dst.x << ", " << _dst.y << ") to (" << incrx << ", " << incry << ")" << endl;
|
// cerr << "locked from (" << _dst.x << ", " << _dst.y << ") to (" << incrx << ", " << incry << ")" << endl;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// retour
|
// retour
|
||||||
result[0] = incrx;
|
result[2] = incrx;
|
||||||
result[1] = incry;
|
result[3] = incry;
|
||||||
|
|
||||||
_mutex_move.unlock();
|
_mutex_move.unlock();
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue