6
#include <SDL/SDL_image.h>
10
// ****************************************************************************
11
// ********************************** Main ************************************
12
// ****************************************************************************
13
int main (int argc, char *argv[])
15
JEU jeu; // Donn�es principales du jeu
16
Uint32 flags; // Param�tres pour l'affichage (fen�tre ou plein �cran)
19
srand ((unsigned) time (NULL)); // Initialise le g�n�rateur de nbs al�atoires
20
flags = SDL_SWSURFACE; // Parametre de l'�cran
22
// Lit les options pass�es en argument au programme
23
for (i = 1; i < argc; i ++)
25
if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) // Affiche une aide
26
{ printf ("\n************** Do'SSi Zo'la 1.0 **************\n");
27
printf ("\n\t\t-h : this help\n\t\t-f : fullscreen\n\t\t-w : windowed\n");
28
printf ("\ncontact the authors:\nCyril CLEMENT <dossiman@users.sourceforge.net>\nGaelle DAIREAUX <ponstyl@users.sourceforge.net>\n");
29
printf ("\nhome page: http://dossizola.sourceforge.net\n\n");
32
else if (!strcmp (argv[i], "-f")) // Mode plein �cran
33
flags = SDL_HWSURFACE | SDL_FULLSCREEN;
34
else if (!strcmp (argv[i], "-w")) // Mode fen�tr�e
35
flags = SDL_HWSURFACE;
37
{ fprintf (stderr, "%s not allowed.\n", argv[i]);
41
strcpy (imgpath, argv[0]);
42
for (i = strlen (imgpath); i >= 0; i --)
44
if (imgpath[i] == '/')
46
strcat (imgpath, "/images/");
49
if (!i) strcpy (imgpath, "./images/");
53
if (SDL_Init (SDL_INIT_VIDEO) < 0)
54
{ fprintf (stderr, "Impossible d'initialiser SDL (%s)\n", SDL_GetError());
57
// Lib�rera les ressources utilis�es par SDL en quittant
60
// Initialise l'affichage en plein �cran ou en fen�tre en 1024x768x32
61
if (!(jeu.ecran = SDL_SetVideoMode (800, 600, 32, flags)))
62
if (!(jeu.ecran = SDL_SetVideoMode (800, 600, 24, flags)))
63
if (!(jeu.ecran = SDL_SetVideoMode (800, 600, 16, flags)))
64
{ fprintf (stderr, "Impossible de definir le mode 800*600 (%s)\n", SDL_GetError());
67
// D�finit le titre de la fen�tre
68
SDL_WM_SetCaption ("Do'SSi Zo'la", "Do'SSi Zo'la");
70
// Cr�e un back buffer (une copie de sauvegarde de l'�cran en m�moire)
71
if (!(jeu.back = SDL_DisplayFormat (jeu.ecran)))
72
{ fprintf (stderr, "Impossible de cr�er un back buffer (%s)\n", SDL_GetError ());
73
SDL_FreeSurface (jeu.back);
77
// Pr�pare la police de caract�re
78
sprintf (fichier, "%s%s", imgpath, IMG_POLICE1);
79
if (!(jeu.police1.img = IMG_Load (fichier))) ImageErreur (fichier);
80
sprintf (fichier, "%s%s", imgpath, IMG_POLICE2);
81
if (!(jeu.police2.img = IMG_Load (fichier))) ImageErreur (fichier);
82
sprintf (fichier, "%s%s", imgpath, IMG_POLICE3);
83
if (!(jeu.police3.img = IMG_Load (fichier))) ImageErreur (fichier);
84
SDL_SetColorKey (jeu.police1.img, SDL_SRCCOLORKEY, SDL_MapRGB (jeu.police1.img->format, 255, 0, 255));
85
SDL_SetColorKey (jeu.police2.img, SDL_SRCCOLORKEY, SDL_MapRGB (jeu.police2.img->format, 255, 0, 255));
86
SDL_SetColorKey (jeu.police3.img, SDL_SRCCOLORKEY, SDL_MapRGB (jeu.police3.img->format, 255, 0, 255));
87
jeu.police1.rect.x = jeu.police2.rect.x = jeu.police3.rect.x = 0;
88
jeu.police1.rect.y = jeu.police2.rect.y = jeu.police3.rect.y = 0;
89
jeu.police1.rect.w = jeu.police2.rect.w = jeu.police3.rect.w = jeu.police1.img->w / 37; // Il y a 37 caracteres dans la police
90
jeu.police1.rect.h = jeu.police2.rect.h = jeu.police3.rect.h = jeu.police1.img->h;
92
// Param�tres par d�faut
93
jeu.J1ROUGE = DFT_J1ROUGE;
94
jeu.J1TYPE = DFT_J1TYPE;
95
jeu.J2TYPE = DFT_J2TYPE;
96
jeu.J1NIVO = DFT_J1NIVO;
97
jeu.J2NIVO = DFT_J2NIVO;
98
jeu.INTEMP = DFT_INTEMP;
99
jeu.DOUBLE_DEPLACE = DFT_DOUBLE_DEPLACE;
100
jeu.DOUBLE_BOULEFEU = DFT_DOUBLE_BOULEFEU;
101
jeu.XGRILLE = DFT_XGRILLE;
102
jeu.YGRILLE = DFT_YGRILLE;
107
// Lance le menu de choix des options du jeu si la fonction retourne oui, le prog quitte
108
if (Menu (&jeu)) break;
111
if (Jeu (&jeu)) break;
114
printf ("\nIf you have fun with this game, do not forget to rate it at :\n\thttp://happypenguin.org/show?Do'SSi%%20Zo'la\n\nIf you have some question or remark, please send mail to:\n\tdossiman@users.sourceforge.net\n\n");
116
SDL_FreeSurface (jeu.back);
117
SDL_FreeSurface (jeu.police1.img);
118
SDL_FreeSurface (jeu.police2.img);
119
SDL_FreeSurface (jeu.police3.img);