Bonjour tout le monde ! :)
Voila j'essaye de me coder un petit jeu avec la bibliothèque SDL 1.2 et l'aide du site du zéro.
J'essaye autant que possible d'écrire le programme en C++ (je préfère), mais ca me cause pas mal de problèmes pour compiler !
Pour compiler j'utilise l'IDE code::blocks avec le compilateur mingw (sous Windows 7).
Je ne sais pas trop comment faire pour placer les fichiers quand on utilise une bilbiothèque. J'ai suivi la méthode du site du zéro : dans le dossier racine de l'IDE, créer un sous dossier SDL 1.2 a l'intérieur duquel on place les dossiers lib et include contenant respectivement les fichiers .a et .h, puis "linker" les .a au projet depuis l'IDE.
Le problème c'est que quand je crée un nouveau projet de type SDL et que je fais cette manip, tout marche niquel a partir du moment ou je ne rajoute pas de C++ dans le code !
Par exemple voila mon main.cpp :
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
#include <SDL_image.h>
#include "constants.h"
#include "positions.h"
using namespace nsBTConstants;
using namespace nsPositions;
namespace
{
typedef int choice_t;
enum {MENU_PLAY, MENU_OPTIONS, MENU_ABOUT, MENU_QUIT};
void runSplash () throw (std::string)
{
SDL_Surface * splash1 = IMG_Load($IMAGES + "splash1.jpg");
for (int i = 0; i <= 256; i += 8)
{
SDL_FillRect(background, NULL, COLOR_BLACK);
SDL_SetAlpha(splash1, SDL_SRCALPHA, i);
SDL_BlitSurface(splash1, NULL, screen, &origin);
SDL_Flip(screen);
SDL_Delay(33);
// 33 times
}
SDL_FreeSurface(splash1);
} // runSplash()
choice_t runMainMenu () throw (std::string)
{
// ToDo
} // runMainmenu()
void runOptionsMenu () throw (std::string)
{
// ToDo
} // runOptionsMenu()
void runAboutMenu () throw (std::string)
{
// ToDo
} // runAboutMenu()
void runGame () throw (std::string)
{
// ToDo
} // runGame()
void runBT () throw (std::string)
{
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
SDL_MW_SetIcon (IMG_Load ($ICONS + "captionIcon.jpg"), NULL);
SDL_MW_SetCaption ("Backflip Theory", NULL);
SDL_Surface * screen
= SDL_SetVideoMode (WINWIDTH, WINHEIGHT, COLDEPTH,
SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_Surface * background
= SDL_CreateRGBSurface (SDL_HWSURFACE, WINWIDTH, WINHEIGHT,
COLDEPTH, 0, 0, 0, 0);
::runSplash(); // throw (std::string)
switch ( ::runMainMenu() ) // throw (std::string)
{
case MENU_PLAY:
::runGame();
break;
case MENU_OPTIONS:
::runOptionsMenu();
break;
case MENU_ABOUT:
::runAboutMenu();
break;
}
SDL_FreeSurface(background);
SDL_FreeSurface(screen);
SDL_Quit();
} // runBT()
} // namespace
int main ( int argc, char * argv [])
{
try { ::runBT(); }
catch (std::string & errMsg)
{
std::cerr << errMsg << std::endl;
return EXIT_FAILURE;
}
catch (...)
{
std::cerr << "Unknown error !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
} // main()
/* MAIN.CPP */
Et a la copilation il me sort des trucs du genre :
'std::string' has not been declared...
J'ai essayé en rajoutant string.h, cstring, using namespace std, mais rien a faire...
Alors j'ai essayé de créer un projet vide, j'ai linké les .a de la SDL, et la c'est encore mieux il ne reconnait même plus les truc issus de la SDL et du C++ !
Que dois-je faire ?
Faut-il que j'indique au compilateur (gcc je crois) que mon code est en C++ ? Si oui comment ?
Merci d'avance !