IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

SDL: fenêtre qui s'affiche seulement pour quelque seconde


Sujet :

C

  1. #1
    Candidat au Club
    Inscrit en
    Septembre 2010
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Septembre 2010
    Messages : 6
    Points : 2
    Points
    2
    Par défaut SDL: fenêtre qui s'affiche seulement pour quelque seconde
    Bonsoir tout le monde;
    Je suis entrain d'implémenté une interface graphique du jeu de MOTUS en utilisant le langage C avec la bibliothèque SDL.
    J'ai une fenêtre principale "menu" qui contient 5 boutons (jouer, aide , meilleur_score, options et quitter). En cliquant sur un tel bouton, on accède à la fenêtre correspondante sauf si on clique sur jouer la fenêtre correspondante s'affiche seulement pour quelque seconde puis disparaît.
    J'ai utilisé des fonctions pour tester le chargement des images et des sons, mais j'avais pas de problème de chargement
    SVP si vous pouvez m'aider
    Voila le code de la fenêtre jouer
    "jouer.c"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
     
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<ctype.h>
    #include<conio.h>
    #include<time.h>
    #include<SDL/SDL.h>
    #include<SDL/SDL_image.h>
    #include<SDL/SDL_ttf.h>
    #include<FMOD/fmod.h>
    #include "jeu.h"
    #include "menu.h"
    #define getrandom( min, max ) (int)((rand() % (int)(((max) + 1) - (min))) + (min))
     
    /**************************************************** fonction principale du jeu ************************************************************/
    /********************************************************************************************************************************************/
     
    int jeu(SDL_Surface *ecran, int nblettre, int act)
    {
        /*declaration des variables*/
        char word [10][10]; 
     
        SDL_Surface *imageDeFond = NULL, *b1Back = NULL, *b2Back = NULL,*rouge = NULL, *jaune = NULL, *carreau = NULL;
        SDL_Surface  *solution=NULL, *surfsolution=NULL,  *gris=NULL, *texte=NULL, *textesol = NULL, *scoreF = NULL, *scoreMF = NULL;
     
        SDL_Rect posFond, posbBack, poslet, possurfsol,possol,poscarreau, posessai, posscore;
        SDL_Rect postxt, poslettre, posid;
     
        SDL_Event event;
     
        int continuer ;
        int bJ=0;
        int fermerJeu = 0;
        int verifposB = 0;
        int s,t;
        int k=0, i=0;
        int iterative=1;    
        int affichesolution=0, quitter=0;
        int score_courant=0;
        char* mot_recherche;
        stat x;
     
     
        SDL_Color Couleur = {200,39,19};
        SDL_Color Blanc={255,255,255};
        TTF_Font *police = NULL;
     
        FSOUND_SAMPLE *tirback = NULL;
        FSOUND_SAMPLE *tiraplaud = NULL;
        FSOUND_STREAM *musique = NULL;
     
        police = TTF_OpenFont("comic.ttf",35);
        /*chargement des sons*/
     
        tirback   = ChargerSonCourt("sons\\mBack.mp3 ");
        tiraplaud = ChargerSonCourt("sons\\aplaudissement.wav ");
        musique   = ChargerMusique ("sons\\tempderef.mp3");
       /*repeter la musique à l'infini*/
        FSOUND_Stream_SetLoopCount(musique, -1);
     
        if (act == 1)
        {FSOUND_Stream_Play(FSOUND_FREE,musique);}
     
        posFond.x = 0;
        posFond.y = 0;
        posbBack.x = 40;
        posbBack.y = 60 ;
        possurfsol.x = 428;
        possurfsol.y = 215;
        possol.x = 455;
        possol.y = 215;	
        posessai.x=162;
        posessai.y=545;
        posscore.x=800;
        posscore.y=545;
        postxt.x=0;
        postxt.y=0;
     
        switch(nblettre)
        { 
             case 5: {
                      imageDeFond=ChargerImage("images\\mat5.bmp");
                      poscarreau.x=344;
                      poscarreau.y=274;
                      poslet.x=357;
                      poslet.y=274; 
                      break;
                      }  
     
             case 6: { imageDeFond=ChargerImage("images\\mat6.bmp");
                       poscarreau.x=315;
                       poscarreau.y=272;
                       poslet.x=330;
                       poslet.y=273;   
                       break;
                       }    
     
             case 7: { 
                       imageDeFond=ChargerImage("images\\mat7.bmp"); 
                       poscarreau.x=286;
                       poscarreau.y=272;
                       poslet.x=302;
                       poslet.y=272;
                       break;
                       }    
     
             case 8: {
                       imageDeFond=ChargerImage("images\\mat8.bmp");
                       poscarreau.x=253;
                       poscarreau.y=273;
                       poslet.x=272;
                       poslet.y=273;   
                       break;  
                       }              
          }
          b1Back       = ChargerImage("images\\back1.png");
          b2Back       = ChargerImage("images\\back2.png");
          carreau      = ChargerImage("images\\carreau.png");
          rouge        = ChargerImage("images\\rouge.png"); 
          jaune        = ChargerImage("images\\jaune.png");
          gris         = ChargerImage("images\\gris.png");     
          surfsolution = ChargerImage("images\\surfsol.bmp");
     
          SDL_SetColorKey(carreau, SDL_SRCCOLORKEY, SDL_MapRGB(carreau->format, 255, 255, 255));
          SDL_SetColorKey(surfsolution, SDL_SRCCOLORKEY, SDL_MapRGB(surfsolution->format, 255, 255, 255));
          SDL_SetColorKey(b1Back, SDL_SRCCOLORKEY, SDL_MapRGB(b1Back->format, 200, 39, 19));
          SDL_SetColorKey(b2Back, SDL_SRCCOLORKEY, SDL_MapRGB(b2Back->format, 200, 39, 19));
          SDL_SetColorKey(jaune, SDL_SRCCOLORKEY, SDL_MapRGB(jaune->format, 255, 255, 255));
     
          SDL_BlitSurface(imageDeFond, NULL, ecran, &posFond);
          SDL_BlitSurface(b2Back,NULL,ecran,&posbBack);
          SDL_BlitSurface(carreau,NULL,ecran,&poscarreau);        
          SDL_Flip(ecran);
          do{
              continuer=1;
              initialiser(&x);
              for(s=0;s<10;s++)
              for(t=0;t<10;t++)
     
              word[s][t]=' ';
              mot_recherche = malloc(10*sizeof(char));
              strcpy(mot_recherche,rechercherMot(nblettre));
              word[0][0]=mot_recherche[0];
              while(continuer)
                    {                           
                      char essai[5]="0/5";
                      char points[10];
                      essai[0]=iterative+'0';
    	              if (affichesolution){
                                            SDL_BlitSurface(surfsolution, NULL, ecran, &possurfsol);
                                            SDL_BlitSurface(solution, NULL, ecran, &possol);
                                            SDL_FreeSurface(solution);
                                            SDL_Flip(ecran);
                                            SDL_Delay(2000);
                                            SDL_EventState(SDL_KEYUP,SDL_IGNORE);
                                            SDL_EventState(SDL_KEYUP,SDL_ENABLE);
                                            solution = NULL;
                                            affichesolution=0;
                                           }
                      SDL_BlitSurface(imageDeFond, NULL, ecran, &posFond);
                      verifposB=test(event.motion.x,event.motion.y,posbBack,55,55);
                      if   (verifposB) 
                         SDL_BlitSurface(b1Back,NULL,ecran,&posbBack);
                      else
                         SDL_BlitSurface(b2Back,NULL,ecran,&posbBack);
    	              SDL_BlitSurface(carreau, NULL, ecran, &poscarreau);
    	              texte = TTF_RenderText_Blended(police, itoa(score_courant,points,10) ,Couleur);
                      SDL_BlitSurface(texte, NULL, ecran, &posscore);
    	              SDL_FreeSurface(texte);
    	              texte = TTF_RenderText_Blended(police, essai ,Couleur);
    	              SDL_BlitSurface(texte, NULL, ecran, &posessai);
                      SDL_FreeSurface(texte); 
     
                      for(s=0;s<6;s++)
                      for(t=0;t<nblettre;t++){
                                               char* ch;
                                               ch = malloc(10*sizeof(char));
                                               ch[1]='\0';
                                               ch[0]=toupper(word[s][t]);
                                               texte = TTF_RenderText_Blended(police, ch ,Blanc);
    	                                       free(ch);
                                               postxt.x=t*61+poslet.x;
                                               postxt.y=s*56+poslet.y;
                                               posid.x=t*62+(poslet.x-15);
                                               posid.y=s*56+(poslet.y+2);
                                               if (x.etat[s][t]==1)
                                                 SDL_BlitSurface(jaune, NULL, ecran, &posid);  
                                               else if (x.etat[s][t]==2)
                                                      SDL_BlitSurface(rouge, NULL, ecran, &posid);
                                                    else if (x.etat[s][t]==3)
                                                           SDL_BlitSurface(gris, NULL, ecran, &posid);
                                               SDL_BlitSurface(texte, NULL, ecran, &postxt);  
    	                                       SDL_FreeSurface(texte);
                                               }
     
                      SDL_Flip(ecran);            
                      SDL_WaitEvent(&event);
                      switch(event.type)
                            {
                               case SDL_QUIT:
                                    {
                                    continuer = 0;
                                    fermerJeu = 1;
                                    iterative=10;
                                    quitter=1;
                                    break;
                                    }
                               case SDL_MOUSEBUTTONUP:
                                    { 
                                     verifposB = test(event.motion.x,event.motion.y,posbBack,41,40);
                                     if (verifposB)
                                      {
                                       continuer = 0;
                                       iterative=10;
                                       quitter=1;
                                       if (act == 1) 
                                       { FSOUND_PlaySound(FSOUND_FREE, tirback);}
                                       }
                                       break;  
                                    }          
                               case SDL_KEYUP:
                                    {
                                      switch(event.key.keysym.sym)
                                            {
                                              case SDLK_LEFT:
                                                     if (k>0) 
                                                     {k--;}
                                                     break;
                                              case SDLK_RIGHT:
                                                     if (k < nblettre-1) 
                                                        {k++;}
                                                     break;
                                              case SDLK_RETURN:    
                                                     if (i<6)
                                                        { 
                                                            word[i][nblettre]='\0';
                                                            if (verifier_mot(word[i],nblettre))
                                                               test_lettre(mot_recherche, word[i], i, nblettre, &x);
                                                            else
                                                                {
                                                                for(s=0;s<nblettre;s++)
                                                                x.etat[i][s]=3;
                                                                }
                                                            if (x.gagne)
                                                               { 
                                                                  score_courant=score_courant+(60-10*i);
                                                                  i=-1;
                                                                  k=0;
                                                                  iterative++;
                                                                  continuer=0;
                                                                  for(s=0;s<6;s++)
                                                                     for(t=0;t<nblettre;t++)
                                                                     {
                                                                        char *ch;
                                                                        ch=malloc(10*sizeof(char));
                                                                        ch[1]='\0';
                                                                        ch[0]=toupper(word[s][t]);
                                                                        texte = TTF_RenderText_Blended(police, ch ,Blanc);
    	                                                                free(ch);
                                                                        postxt.x=t*65+poslettre.x;
                                                                        postxt.y=s*56+poslettre.y;
                                                                        posid.x=t*63+(poslettre.x-15);
                                                                        posid.y=s*54+(poslettre.y+2);
                                                                        if (x.etat[s][t]==1)
                                                                            SDL_BlitSurface(jaune, NULL, ecran, &posid);  
                                                                        else if (x.etat[s][t]==2)
                                                                                SDL_BlitSurface(rouge, NULL, ecran, &posid);
                                                                             else if (x.etat[s][t]==3)
                                                                                      SDL_BlitSurface(gris, NULL, ecran, &posid);
                                                                        SDL_BlitSurface(texte, NULL, ecran, &postxt);  
                                                                        SDL_FreeSurface(texte);
                                                                     }
                                                                  SDL_Flip(ecran);
                                                                  SDL_Delay(1000);
                                                                  SDL_EventState(SDL_KEYUP,SDL_IGNORE);
                                                                  SDL_EventState(SDL_KEYUP,SDL_ENABLE);
                                                               }
                                                            if(i<5)
                                                              {
                                                               for(t=0;t<=i;t++)
                                                                   for(s=0;s<nblettre;s++)
                                                                      if(x.etat[t][s]==2)
                                                                         word[i+1][s]=word[t][s];
                                                              }
                                                            i++;
                                                            k=0;
                                                        }/* fin if(i<6) */
                                                     else if (i==6)
                                                            {
                                                              solution = TTF_RenderText_Blended(police, mot_recherche, Blanc);
                                                              affichesolution=1;
                                                              iterative++;
                                                              i=0;
                                                              continuer=0;
                                                            }
                                                     if (i<6) poscarreau.y=272+56*i;      
                                                     break;/*break de SDLK_RETURN*/
                                            }/*fin switch (event.key.keysym.sym)*/
                                      if ((touche_taper(event.key.keysym.sym)!=' ')&(event.key.keysym.sym!=SDLK_LEFT)&(event.key.keysym.sym!=SDLK_RIGHT)&(event.key.keysym.sym!=SDLK_RETURN))
                                         {
                                           word[i][k]=touche_taper(event.key.keysym.sym);
                                           if (k<nblettre-1) 
                                             k++;
                                         }
                                         if (nblettre==5)
                                             poscarreau.x=343+61*k;
                                         else if (nblettre==6)
                                                  poscarreau.x=313+62*k;
                                               else if (nblettre ==7)
                                                     poscarreau.x=285+61*k;
                                                    else 
                                                        poscarreau.x=254+61*k;
                                      break;/*break de SDL_KEYUP*/
                                    }   
                            }/*fin switch (event.type)*/
     
                    } /*fin de while(continuer)*/
     
            }while (iterative<6);/*fin de la boucle DO WHILE*/
     
            /*blit de la solution*/
            if (!x.gagne & !quitter)
            {
               SDL_BlitSurface(surfsolution, NULL, ecran, &possurfsol);
               SDL_BlitSurface(solution, NULL, ecran, &possol);
               SDL_FreeSurface(solution);
               SDL_Flip(ecran);
               SDL_Delay(2000);
               SDL_EventState(SDL_KEYUP,SDL_IGNORE);
               SDL_EventState(SDL_KEYUP,SDL_ENABLE);
               solution = NULL; 
            }                                                                    
     
            FSOUND_Stream_Stop(musique);
            FSOUND_Stream_Close(musique);        
     
            SDL_FreeSurface(imageDeFond);
            SDL_FreeSurface(b1Back);    
            SDL_FreeSurface(b2Back);
            SDL_FreeSurface(carreau);  
            SDL_FreeSurface(surfsolution);
            SDL_FreeSurface(rouge);
            SDL_FreeSurface(jaune);
            SDL_FreeSurface(gris);
     
            if (iterative==6)
            {
              gestion_score(ecran,score_courant);
     
            }
            TTF_CloseFont(police);
     
            return fermerJeu;
    }
    Merci bien d'avance

  2. #2
    Membre actif Avatar de oussi
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    192
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 192
    Points : 290
    Points
    290
    Par défaut
    L'unique aide que je pourrai t'apporter maintenant c'est te dire que tu dois poster le message dans le forum C pas le C#

    Tu trouvera une réponse plus facilement et plus rapidement.

    Bonne chance

Discussions similaires

  1. [SDL] Fenêtre qui plante toujours
    Par Yaman dans le forum SDL
    Réponses: 4
    Dernier message: 28/04/2010, 14h53
  2. Fenêtre qui s'affiche
    Par D3bian dans le forum GTK+ avec Python
    Réponses: 1
    Dernier message: 31/10/2009, 19h19
  3. Afficher une page quelques secondes seulement
    Par Jean-Claude Dusse dans le forum ASP.NET
    Réponses: 3
    Dernier message: 19/02/2009, 12h20
  4. une fentre qui s'affiche et qui se ferme
    Par elmcherqui dans le forum Qt
    Réponses: 1
    Dernier message: 01/07/2008, 08h14
  5. [C# 2.0] Composants d'une fenêtre qui s'affiche un à un
    Par margagn dans le forum Windows Forms
    Réponses: 12
    Dernier message: 13/12/2006, 19h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo