Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème à la compilation

cration d'un rpg en SDL

    27 juin 2007 à 9:29:08

    Bonjour,
    Je suis en train d'aider quelqu'un pour la construction d'un rpg, j'ai refait le code, mais code block de me créer pas l'éxécutable, et quand je fais "run" dans code block , il me recompile parce qu'il ne trouve pas le fichier .exe .
    J'utilise les nightly builds , mingw c++ tollbox et la SDL;

    je vous passe le code de mes fichiers :
    main.cpp:
    #include <SDL.h>
    #include <SDL_image.h>
    #include <SDL_ttf.h>

    #include "editeur.h"

    #include "constantes.h"



    int main(int argc, char *argv[])
    {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Surface *heros[4] = {NULL};
    SDL_Surface *herbe = NULL, *montagne = NULL, *herosactuel = NULL;
    SDL_Surface *ecran = SDL_SetVideoMode(LARGEUR_FENETRE,HAUTEUR_FENETRE,32, SDL_HWSURFACE);
    SDL_Event event;

    herbe = IMG_Load("sprites/terrain/herbe.png");
    montagne = IMG_Load("sprites/terrain/MONTAGNE.bmp");
    heros[BAS] = IMG_Load("sprites/heros/persodown.bmp");
    heros[GAUCHE] = IMG_Load("sprites/heros/persoleft.bmp");
    heros[HAUT] = IMG_Load("sprites/heros/perso.bmp");
    heros[DROITE] = IMG_Load("sprites/heros/persoright.bmp");

    herosactuel = heros[BAS];

    creer_terrain(herbe,montagne,herosactuel,ecran);
    SDL_EnableKeyRepeat(100, 100);

    while(continuer)
    {
        switch(event.type)
    {
        case SDL_QUIT:
            continuer = false;
            break;
        case SDL_KEYDOWN:
            switch(event.key.keysym.sym)
            {
                case SDLK_ESCAPE:
                    continuer = false;
                    break;
                case SDLK_UP:
                    herosactuel = heros[HAUT];

                    break;
                case SDLK_DOWN:
                    herosactuel = heros[BAS];

                    break;
                case SDLK_RIGHT:
                    herosactuel = heros[DROITE];

                    break;
                case SDLK_LEFT:
                    herosactuel = heros[GAUCHE];
                    break;
                case SDLK_F4:
                editeur(ecran);
                break;
            }
            break;
    }
    creer_terrain(herbe,montagne,herosactuel,ecran);
    }
        SDL_FreeSurface(herbe);
        SDL_FreeSurface(montagne);
        SDL_FreeSurface(heros[1]);
        SDL_FreeSurface(heros[2]);
        SDL_FreeSurface(heros[3]);
        SDL_FreeSurface(heros[0]);
        SDL_FreeSurface(herosactuel);
        SDL_Quit();
        return EXIT_SUCCESS;
    }

    int creer_terrain(SDL_Surface *herbe,SDL_Surface *montagne,SDL_Surface *herosactuel, SDL_Surface *ecran)
    {
    for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
    {
        for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
        {
            position.x = i * TAILLE_BLOC;
            position.y = j * TAILLE_BLOC;

            switch(carte[i][j])
            {
                case HERBE:
                    SDL_BlitSurface(herbe, NULL, ecran, &position);
                    break;
                case MONTAGNE:
                    SDL_BlitSurface(montagne, NULL, ecran, &position);
                    break;

            }
        }
    }
    position.x = positionJoueur.x * TAILLE_BLOC;
    position.y = positionJoueur.y * TAILLE_BLOC;
    SDL_BlitSurface(herosactuel, NULL, ecran, &position);
    SDL_Flip(ecran);
    }


    constantes.h:
    #ifndef DEF_CONSTANTES
    #define DEF_CONSTANTES

        #define TAILLE_BLOC         35 // Taille d'un bloc (carré) en pixels
        #define NB_BLOCS_LARGEUR    12
        #define NB_BLOCS_HAUTEUR    12
        #define LARGEUR_FENETRE     TAILLE_BLOC * NB_BLOCS_LARGEUR
        #define HAUTEUR_FENETRE     TAILLE_BLOC * NB_BLOCS_HAUTEUR

    int creer_terrain(SDL_Surface *herbe,SDL_Surface *montagne,SDL_Surface *herosactuel, SDL_Surface *ecran);
    int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR]);

    int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0};
    enum {HERBE, HEROS, MONTAGNE};
    enum {HAUT,BAS,GAUCHE,DROITE};

    bool continuer = true;
    int i, j;

    SDL_Rect position, positionJoueur;

    #endif


    editeur.h:
    #ifndef DEF_EDITEUR
    #define DEF_EDITEUR
    #include "constantes.h"
        void editeur(SDL_Surface* ecran);
        int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR]);
        int sauvegarderNiveau(int niveau[][NB_BLOCS_HAUTEUR]);
    #endif


    et editeur.cpp:

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

    #include "constantes.h"
    #include "editeur.h"


    void editeur(SDL_Surface* ecran)
    {
        SDL_Surface *herbe = NULL, *montagne = NULL, *herosactuel = NULL;
        SDL_Rect position;
        SDL_Event event;

        bool continuer = true, clicGaucheEnCours = false, clicDroitEnCours = false;
        int objetActuel = HERBE, i = 0, j = 0;
        int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0};

        // Chargement des objets et du niveau
        herbe = IMG_Load("sprites/terrain/herbe.png");
    montagne = IMG_Load("sprites/terrain/MONTAGNE.bmp");
        herosactuel = IMG_Load("sprites/heros/persodown.bmp");

        if (!chargerNiveau(carte))
            exit(EXIT_FAILURE);

        // Boucle infinie de l'éditeur
        while (continuer)
        {
            SDL_WaitEvent(&event);
            switch(event.type)
            {
                case SDL_QUIT:
                    continuer = 0;
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    if (event.button.button == SDL_BUTTON_LEFT)
                    {
                        // On met l'objet actuellement choisi (mur, caisse...) à l'endroit du clic
                        carte[event.button.x / TAILLE_BLOC][event.button.y / TAILLE_BLOC] = objetActuel;
                        clicGaucheEnCours = 1; // On active un booléen pour retenir qu'un bouton est enfoncé
                    }
                    else if (event.button.button == SDL_BUTTON_RIGHT) // Le clic droit sert à effacer
                    {
                        carte[event.button.x / TAILLE_BLOC][event.button.y /TAILLE_BLOC] = HERBE;
                        clicDroitEnCours = 1;
                    }
                    break;
                case SDL_MOUSEBUTTONUP: // On désactive le booléen qui disait qu'un bouton était enfoncé
                    if (event.button.button == SDL_BUTTON_LEFT)
                        clicGaucheEnCours = 0;
                    else if (event.button.button == SDL_BUTTON_RIGHT)
                        clicDroitEnCours = 0;
                    break;
                case SDL_MOUSEMOTION:
                    if (clicGaucheEnCours) // Si on déplace la souris et que le bouton gauche de la souris est enfoncé
                    {
                        carte[event.motion.x / TAILLE_BLOC][event.motion.y / TAILLE_BLOC] = objetActuel;
                    }
                    else if (clicDroitEnCours) // Pareil pour le bouton droit de la souris
                    {
                        carte[event.motion.x / TAILLE_BLOC][event.motion.y / TAILLE_BLOC] = HERBE;
                    }
                    break;
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym)
                    {
                        case SDLK_ESCAPE:
                            continuer = 0;
                            break;
                        case SDLK_s:
                            sauvegarderNiveau(carte);
                            break;
                        case SDLK_c:
                            chargerNiveau(carte);
                            break;
                        case SDLK_KP1:
                            objetActuel = HERBE;
                            break;
                        case SDLK_KP2:
                            objetActuel = HEROS;
                            break;
                        case SDLK_KP3:
                            objetActuel = MONTAGNE;
                            break;

                    }
                    break;
            }

            // Effacement de l'écran
            SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));

            // Placement des objets à l'écran
            for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
            {
                for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
                {
                    position.x = i * TAILLE_BLOC;
                    position.y = j * TAILLE_BLOC;

                    switch(carte[i][j])
                    {
                        case HERBE:
                            SDL_BlitSurface(herbe, NULL, ecran, &position);
                            break;
                        case HEROS:
                            SDL_BlitSurface(herosactuel, NULL, ecran, &position);
                            break;
                        case MONTAGNE:
                            SDL_BlitSurface(montagne, NULL, ecran, &position);
                            break;

                    }
                }
            }

            // Mise à jour de l'écran
            SDL_Flip(ecran);
        }

        SDL_FreeSurface(herbe);
        SDL_FreeSurface(herosactuel);
        SDL_FreeSurface(montagne);

    }
    int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR])
    {
        FILE* fichier = NULL;
        char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0};
        int i = 0, j = 0;

        fichier = fopen("niveaux.lvl", "r");
        if (fichier == NULL)
            return 0;

        fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier);

        for (i = 0 ; i < NB_BLOCS_HAUTEUR ; i++)
        {
            for (j = 0 ; j < NB_BLOCS_LARGEUR ; j++)
            {
                switch (ligneFichier[(i * NB_BLOCS_LARGEUR) + j])
                {
                    case '0':
                        niveau[j][i] = 0;
                        break;
                    case '1':
                        niveau[j][i] = 1;
                        break;
                    case '2':
                        niveau[j][i] = 2;
                        break;
                    case '3':
                        niveau[j][i] = 3;
                        break;

                }
            }
        }

        fclose(fichier);
        return 0;
    }

    int sauvegarderNiveau(int niveau[][NB_BLOCS_HAUTEUR])
    {
        FILE* fichier = NULL;
        int i = 0, j = 0;

        fichier = fopen("niveaux.lvl", "w");
        if (fichier == NULL)
            return 0;

        for (i = 0 ; i < NB_BLOCS_HAUTEUR ; i++)
        {
            for (j = 0 ; j < NB_BLOCS_LARGEUR ; j++)
            {
                fprintf(fichier, "%d", niveau[j][i]);
            }
        }

        fclose(fichier);
        return 1;
    }


    Je me suis servi de mario sokoban pour le code source et j'ai modifié des choses.
    Je comprends pas pourquoi les dernières phrases code c++ sont rouges mais bon, elles le sont pas sous code::block;
    Merci de me donner des petits conseils pour mon code et de m'expliquer pourquoi ça ne compile pas.
    • Partager sur Facebook
    • Partager sur Twitter
      27 juin 2007 à 10:55:54

      Ca compile pas ?

      Est-ce que tu as des messages d'erreur ? Si oui lesquels ?

      Sinon si tu utilises les nighty Builds, le .exe n'est pas dans le dossier du projet masi dans

      dossierOuEstLeProjet/bin/Release

      ou un truc dans le genre.
      • Partager sur Facebook
      • Partager sur Twitter
      Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
        27 juin 2007 à 13:46:00

        Je sais déjà pour l'exe dans obj release, iln'y a pas de message d'erreur, seulement plein de warnings qui défilent par rapport à SDL.h , ça marque warning ... et le nom de l'évènement ( SDL_KP1) et tout défile, ça c déjà un pb car ça me ralenti mais il n'y a pas de messages d'erreurs...
        • Partager sur Facebook
        • Partager sur Twitter
          27 juin 2007 à 14:30:07

          Si ça compile sans erreur, il y a forcément un .exe quelquepart.
          • Partager sur Facebook
          • Partager sur Twitter
          Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
            27 juin 2007 à 15:54:41

            y a juste marqué statut 1 et rien g cherché, y a pas d'exe
            • Partager sur Facebook
            • Partager sur Twitter
              27 juin 2007 à 16:04:38

              En effet puisqu'il y a une montagne d'erreur:


              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «herbe" was not declared in this scope
              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «montagne" was not declared in this scope
              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «herosactuel" was not declared in this scope
              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «ecran" was not declared in this scope
              constantes.h:10: erreur: initializer liste d'expressions traitée comme une expression composée
              constantes.h:20: erreur: «SDL_Rect" does not name a type
              editeur.h:4: erreur: variable or field «editeur" declared void
              editeur.h:4: erreur: «SDL_Surface" was not declared in this scope
              editeur.h:4: erreur: «ecran" was not declared in this scope
              editeur.cpp:8: erreur: variable or field «editeur" declared void
              editeur.cpp:8: erreur: redefinition of «int editeur"
              editeur.h:4: erreur: «int editeur" previously defined here
              editeur.cpp:8: erreur: «SDL_Surface" was not declared in this scope
              editeur.cpp:8: erreur: «ecran" was not declared in this scope
              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «herbe" was not declared in this scope
              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «montagne" was not declared in this scope
              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «herosactuel" was not declared in this scope
              constantes.h:10: erreur: «SDL_Surface" was not declared in this scope
              constantes.h:10: erreur: «ecran" was not declared in this scope
              constantes.h:10: erreur: initializer liste d'expressions traitée comme une expression composée
              constantes.h:20: erreur: «SDL_Rect" does not name a type
              editeur.h:4: erreur: variable or field «editeur" declared void
              editeur.h:4: erreur: «SDL_Surface" was not declared in this scope
              editeur.h:4: erreur: «ecran" was not declared in this scope
              main.cpp: In function «int main(int, char**)":
              main.cpp:13: erreur: «SDL_INIT_VIDEO" was not declared in this scope
              main.cpp:13: erreur: «SDL_Init" was not declared in this scope
              main.cpp:14: erreur: «SDL_Surface" was not declared in this scope
              main.cpp:14: erreur: «heros" was not declared in this scope
              main.cpp:14: erreur: expected primary-expression before «{" token
              main.cpp:14: erreur: expected `;' before «{" token
              main.cpp:15: erreur: «herbe" was not declared in this scope
              main.cpp:15: erreur: «NULL" was not declared in this scope
              main.cpp:15: erreur: «montagne" was not declared in this scope
              main.cpp:15: erreur: «herosactuel" was not declared in this scope
              main.cpp:16: erreur: «ecran" was not declared in this scope
              main.cpp:16: erreur: «SDL_HWSURFACE" was not declared in this scope
              main.cpp:16: erreur: «SDL_SetVideoMode" was not declared in this scope
              main.cpp:17: erreur: «SDL_Event" was not declared in this scope
              main.cpp:17: erreur: expected `;' before «event"
              main.cpp:19: erreur: «IMG_Load" was not declared in this scope
              main.cpp:28: erreur: «creer_terrain" cannot be used as a function
              main.cpp:29: erreur: «SDL_EnableKeyRepeat" was not declared in this scope
              main.cpp:33: erreur: «event" was not declared in this scope
              main.cpp:35: erreur: «SDL_QUIT" was not declared in this scope
              main.cpp:38: erreur: «SDL_KEYDOWN" was not declared in this scope
              main.cpp:41: erreur: «SDLK_ESCAPE" was not declared in this scope
              main.cpp:44: erreur: «SDLK_UP" was not declared in this scope
              main.cpp:48: erreur: «SDLK_DOWN" was not declared in this scope
              main.cpp:52: erreur: «SDLK_RIGHT" was not declared in this scope
              main.cpp:56: erreur: «SDLK_LEFT" was not declared in this scope
              main.cpp:59: erreur: «SDLK_F4" was not declared in this scope
              main.cpp:60: erreur: «editeur" cannot be used as a function
              main.cpp:65: erreur: «creer_terrain" cannot be used as a function
              main.cpp:67: erreur: «SDL_FreeSurface" was not declared in this scope
              main.cpp:74: erreur: «SDL_Quit" was not declared in this scope
              main.cpp:75: erreur: «EXIT_SUCCESS" was not declared in this scope
              main.cpp: At global scope:
              main.cpp:78: erreur: redefinition of «int creer_terrain"
              constantes.h:10: erreur: «int creer_terrain" previously defined here
              main.cpp:78: erreur: «SDL_Surface" was not declared in this scope
              main.cpp:78: erreur: «herbe" was not declared in this scope
              main.cpp:78: erreur: «SDL_Surface" was not declared in this scope
              main.cpp:78: erreur: «montagne" was not declared in this scope
              main.cpp:78: erreur: «SDL_Surface" was not declared in this scope
              main.cpp:78: erreur: «herosactuel" was not declared in this scope
              main.cpp:78: erreur: «SDL_Surface" was not declared in this scope
              main.cpp:78: erreur: «ecran" was not declared in this scope
              • Partager sur Facebook
              • Partager sur Twitter
              Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
                27 juin 2007 à 16:33:07

                là la montagne d'erreur c parce que SDL.h n'est pas dans le même répertoire que le tien, toi c sans doute SDL/SDL.h
                • Partager sur Facebook
                • Partager sur Twitter
                  27 juin 2007 à 16:51:24

                  oui mais entre 2 y a des erreurs qui proviennent de ton code.

                  Par exemple:

                  editeur.h:4: erreur: variable or field «editeur" declared void
                  main.cpp:14: erreur: expected primary-expression before «{" token
                  main.cpp:14: erreur: expected `;' before «{" token
                  • Partager sur Facebook
                  • Partager sur Twitter
                  Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
                    27 juin 2007 à 17:27:15

                    bon, c pas grave parce que je bosse sur autre chose, merci de tes conseils nanoc, faut que je refasse le code différemment
                    au revoir
                    • Partager sur Facebook
                    • Partager sur Twitter

                    Problème à la compilation

                    × 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