Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème avec un evenement :

    2 novembre 2006 à 14:05:56

    Bonjour à tous :

    Voici mon problème :

    J'ai un programme qui normalement , quand on appuie sur 1 lance une fonction qui permet de faire bouger un bonhomme dans une foret .

    Mais , primo quand j'appuie sur 1 , y a rien ,faut que j'appuie sur ESCAPE pour changer d'écran, et je peux pas me déplacer !

    Voici mon code :

    Le main :
    #include <stdio.h>
    #include <stdlib.h>
    #include <SDL\SDL.h>

    #include "SDL_Game_YoB_Constantes.h"
    #include "SDL_Game_YoB_Train1.h"

    int main(int argc , char *argv[])
    {
        SDL_Init(SDL_INIT_VIDEO);
       
            SDL_Surface *ecran = NULL;
            SDL_Surface *menu = NULL;
           
           
           
            int continuer = 1;
           
            SDL_Event event;
           
            SDL_Rect positionMenu;
           
                     positionMenu.x = 0;
                     positionMenu.y = 0;
                     
         
                 
                     
            SDL_WM_SetCaption("Years Of Bravoury", NULL);
            SDL_WM_SetIcon(SDL_LoadBMP("images\\icone.bmp"),NULL);
           
            ecran = SDL_SetVideoMode(600, 600 , 32 , SDL_HWSURFACE | SDL_DOUBLEBUF);
            menu = SDL_LoadBMP("images\\menu.bmp");
           
           
            SDL_FillRect(ecran , NULL , SDL_MapRGB(ecran->format,255,255,255));
           
            SDL_BlitSurface(menu , NULL , ecran  ,&positionMenu);
           
           
            SDL_Flip(ecran);
            while(continuer)
            {
                            SDL_WaitEvent(&event);
                            switch(event.type)
                            {
                                              case SDL_QUIT :
                                                   continuer = 0;
                                                   break;
                                              case SDL_KEYDOWN :
                                                   switch(event.key.keysym.sym)
                                                   {
                                                                               case SDLK_ESCAPE :
                                                                                    continuer = 0;
                                                                                    break;
                                                                               case SDLK_KP1 :
                                                                                    SDL_FillRect(ecran , NULL , SDL_MapRGB(ecran->format,255,255,255));
                                                                                    entrainement1(ecran);
                                                                               
                                                                                    break
                                                                               case SDLK_KP2 :   
                                                                                   
                                                                                    break;
                                                                               case SDLK_KP3 :
                                                                                   
                                                                                    break;
                                                                               case SDLK_KP4 :
                                                                                   
                                                                                    break;
                                                                               case SDLK_KP5 :
                                                                                   
                                                                                    break;
                                                                                         
                                                                               }
                                              break;
                                              }
                           
                           
                            SDL_Flip(ecran);
                           
                            }

       
       
       
       
       
           
       
       
        SDL_FreeSurface(menu);
       
        SDL_Quit();
       
        return EXIT_SUCCESS;
    }




    Le fonction :

    #include <stdio.h>
    #include <stdlib.h>
    #include <SDL\SDL.h>

    #include "SDL_Game_YoB_Constantes.h"
    #include "SDL_Game_YoB_Train1.h"

    void entrainement1(SDL_Surface *ecran)
    {
         SDL_Surface *Unit[4] = {NULL};
         SDL_Surface *UnitActuel = NULL;
         SDL_Surface *chene = NULL;
         SDL_Surface *carte[NB_BLOCS_HAUTEUR][NB_BLOCS_LARGEUR] = {NULL};
         
         SDL_Event event_train;
         
         SDL_Rect positionUnit;
         
                  positionUnit.x = 300;
                  positionUnit.y = 300;
                 
         SDL_Rect positionchene;
         
                  positionchene.x = 0;
                  positionchene.x = 0;
         
         SDL_Rect positionUnitActuel;         
                 
         SDL_FillRect(ecran , NULL , SDL_MapRGB(ecran->format,255,255,255));
         
         int continuer_train = 1;
         int i = 0;
         int j = 0;
         
         chene = SDL_LoadBMP("images\\chene.bmp");
         Unit[0] = SDL_LoadBMP("images\\unit_haut.bmp");
         Unit[1] = SDL_LoadBMP("images\\unit_bas.bmp");
         Unit[2] = SDL_LoadBMP("images\\unit_gauche.bmp");
         Unit[3] = SDL_LoadBMP("images\\unit_droite.bmp");
         
         SDL_SetColorKey(Unit[HAUT] , SDL_SRCCOLORKEY , SDL_MapRGB(Unit[HAUT]->format , 255,255,255));
         SDL_SetColorKey(Unit[BAS] , SDL_SRCCOLORKEY , SDL_MapRGB(Unit[BAS]->format , 255,255,255));
         SDL_SetColorKey(Unit[GAUCHE] , SDL_SRCCOLORKEY , SDL_MapRGB(Unit[GAUCHE]->format , 255,255,255));
         SDL_SetColorKey(Unit[DROITE] , SDL_SRCCOLORKEY , SDL_MapRGB(Unit[DROITE]->format , 255,255,255));
         
         for(i = 0;i < NB_BLOCS_HAUTEUR ; i++)
         {
               for(j = 0; j< NB_BLOCS_LARGEUR ; j++)
               {
                     
                     carte[i][j] = chene ;
                     positionchene.x = i * TAILLE_BLOC;
                     positionchene.y = j * TAILLE_BLOC;
                     SDL_BlitSurface(chene ,NULL ,ecran , &positionchene);
                     
                     }
                     }
         UnitActuel = Unit[BAS];
         
         SDL_BlitSurface(UnitActuel , NULL , ecran , &positionUnit);
         
         while (continuer_train)
         {
               SDL_WaitEvent(&event_train);
               switch(event_train.type)
               {
                                 case SDL_QUIT :
                                      continuer_train = 0;
                                      break;
                                 case SDL_KEYDOWN :
                                      switch(event_train.key.keysym.sym)
                                      {
                                                                  case SDLK_ESCAPE :
                                                                       continuer_train = 0;
                                                                       break;
                                                                  case SDLK_UP :
                                                                       UnitActuel = Unit[HAUT];
                                                                       positionUnitActuel.y = positionUnit.y - 20;
                                                                       break;
                                                                  case SDLK_DOWN :
                                                                       UnitActuel = Unit[BAS] ;
                                                                       positionUnit.y = positionUnit.y - 20;
                                                                       break;
                                                                  case SDLK_RIGHT :
                                                                       UnitActuel = Unit[DROITE];
                                                                       positionUnit.x = positionUnit.x + 20;
                                                                       break;
                                                                  case SDLK_LEFT :
                                                                       UnitActuel = Unit[GAUCHE];
                                                                       positionUnit.x = positionUnit.x -20;
                                                                       break;
                                                                  }
                                      break;
                                 }
                SDL_BlitSurface(UnitActuel , NULL ,ecran ,&positionUnit)
                               
               }
               
                 
                     
                     
         SDL_Flip(ecran);
     }
    • Partager sur Facebook
    • Partager sur Twitter
      2 novembre 2006 à 14:35:00

      Quand on indente on fait généralement un pas compris entre 2 et 4 espaces pas plus :-°
      Edit : Désolé si mon post n'apporte rien mais je pense que ce sera plus facile de se plonger dans ton code quand il sera indenté avec un pas inférieur.
      • Partager sur Facebook
      • Partager sur Twitter
        2 novembre 2006 à 15:47:51

        Je me trompe peut être, mais le code de la touche 1 n'est-il pas SDLK_1 au lieu de SDLK_KP1 ?
        • Partager sur Facebook
        • Partager sur Twitter
          2 novembre 2006 à 16:03:20

          Le KP correspond à KeyPad 1 .

          Sinon , le problème du switch ( indentation ) est du à des tests précédents ce post .
          • Partager sur Facebook
          • Partager sur Twitter

          Problème avec un evenement :

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown