1 // (_||_/
2 // ( ) Programme Principale
3 // ( o 0 )
4 //-OOO�--(_)---�OOO---------------------------------------
5 // Copyright (C) 2006 By Dominique Roux-Serret
6 // .OOOo oOOO. roux-serret@ifrance.com
7 //-( )------( )---------------------------------------
8 // ( ( ) / Le 03/01/2006
9 // (_) (_/
10
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 or version 3 of the License.
14
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19
20 // You should have received a copy of the GNU General Public License along
21 // with this program; if not, write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <iostream>
27 #include <string.h>
28 #include <SDL/SDL.h>
29 #include <SDL/SDL_mixer.h>
30
31 #include "preference.h"
32 #include "jeux.h"
33 #include "audio.h"
34 #include "sprite.h"
35 #include "ecran.h"
36 #include "mouse.h"
37 #include "menu.h"
38 #include "tableau.h"
39 #include "editeur.h"
40 #include "utils.h"
41
42 /*** Variables globales ***/
43 /************************/
44 SDL_Surface *sdlVideo; // Pointe sur l'�cran video
45 SDL_VideoInfo *sdlVideoInfo; // Infos sur la video
46 Uint32 FontColor; // Couleur du fond d'�cran
47
48 char Titre[]="Ri-li V2.0.1";
49
50 Sprite *Sprites=NULL; // Pointe sur les sprites
51 int NSprites=0; // Nombre de sprites en m�moire
52 Ecran Ec[2]; // Pointe sur les 2 buffets vid�o
53 sPreference Pref; // Tableau des pr�f�rences.
54 Jeux Jeu; // G�re le jeu
55 Mouse Sourie; // G�re les mouvements de sourie
56 Menu MenuPrincipale; // G�re les menus
57 Tableau Niveau; // G�re les niveaux
58 Editeur Edit; // G�re le menu de l'�diteur
59 Audio Sons; // G�re les sons
60
61 int Horloge=0; // Horloges du jeu
62 int HorlogeAvant=0;
63
64 #ifdef LINUX
65 char DefPath[256]; // Chemin par defaut dans arg
66 #endif
67
68 /*** Initialise les preferences ***/
69 /**********************************/
InitPref(void)70 void InitPref(void)
71 {
72 #ifdef LINUX
73 DefPath[0]=0;
74 #endif
75
76 Pref.NiveauMax=0;
77 Pref.FullScreen=false;
78 Pref.Langue=-1;
79 Pref.Volume=(float)SDL_MIX_MAXVOLUME;
80 Pref.VolumeM=(float)SDL_MIX_MAXVOLUME; //*6.0/10.0;
81
82 for(int i=0;i<8;i++) { // Vide les scores
83 Pref.Sco[i].Score=0;
84 Pref.Sco[i].Name[0]=0;
85 }
86 /* Pref.Sco[0].Score=11425; */
87 /* sprintf(Pref.Sco[0].Name,"%s","Dominique"); */
88 /* Pref.Sco[1].Score=678; */
89 /* sprintf(Pref.Sco[1].Name,"%s","Veronique"); */
90
91 LoadPref();
92
93 Pref.Difficulte=Normal;
94 Pref.Vitesse=VITESSE_MOY;
95 Pref.VitesseMoy=VITESSE_MOY;
96 Pref.NVie=N_VIES_DEP;
97 Pref.EcartWagon=ECARTWAGON_MOY;
98 }
99
100 /*** Preogramme principale ***/
101 /*****************************/
main(int narg,char * argv[])102 int main(int narg,char *argv[])
103 {
104 int i;
105 char **pTitre=NULL;
106 char **pIcon=NULL;
107 Sprite Spr;
108 eMenu RetM,RetMenu=mMenu;
109
110 // Initialuse les pr�ferences
111 InitPref();
112 #ifdef LINUX
113 strcpy(DefPath,"/usr/local/share/Ri-li/");
114 #endif
115
116 // Initilise SDL
117 if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE) < 0 ) {
118 std::cerr <<"Impossible d'initialiser SDL:"<<SDL_GetError()<<std::endl;
119 exit(-1);
120 }
121 // Ferme le programme correctement quant quit
122 atexit(SDL_Quit);
123
124 // Teste la resolution video
125 sdlVideoInfo=(SDL_VideoInfo*)SDL_GetVideoInfo();
126
127 if(sdlVideoInfo->vfmt->BitsPerPixel==8) {
128 std::cerr <<"Impossible d'utiliser 8bits pour la vid�o !"<<std::endl;
129 exit(-1);
130 }
131
132 // Demande la resolution Video
133 #ifndef LINUX
134 int vOption;
135 if(Pref.FullScreen) vOption=SDL_SWSURFACE; // Bug acc� aux bits pour les cordes
136 else vOption=SDL_SWSURFACE|SDL_DOUBLEBUF;
137 #else
138 #ifndef __AMIGAOS4__
139 int vOption=SDL_SWSURFACE|SDL_DOUBLEBUF;
140 #else
141 int vOption=SDL_SWSURFACE;
142 #endif
143 #endif
144 if(Pref.FullScreen) vOption|=SDL_FULLSCREEN;
145 sdlVideo=SDL_SetVideoMode(800,600,sdlVideoInfo->vfmt->BitsPerPixel,vOption);
146
147 if(sdlVideo==NULL) {
148 std::cerr <<"Impossible de passer dans le mode vid�o 800x600 !"<<std::endl;
149 exit(-1);
150 }
151 // Change le nom de la fenetre
152 SDL_WM_GetCaption(pTitre,pIcon);
153 SDL_WM_SetCaption(Titre,NULL);
154 SDL_ShowCursor(0); // Masque le curseur
155 SDL_EnableUNICODE(1);
156
157 // Couleur du font d'�cran
158 FontColor=SDL_MapRGB(sdlVideo->format,128,128,128);
159
160 // Chargement des sprites
161 Sons.Init();
162 if(LoadSprites()==false) exit(-1);
163 if(Niveau.Load()==false) exit(-1);
164
165 Sons.PlayMusic();
166 Sourie.InitStart();
167
168 // Initialise l'horloge et le hazard
169 HorlogeAvant=Horloge=SDL_GetTicks();
170 srand(SDL_GetTicks());
171
172 // Si pas de langues demande la langue
173 if(Pref.Langue==-1) MenuPrincipale.SDLMain_Langue();
174
175 // G�re les menus
176 do {
177 switch(RetMenu) {
178 case mMenu:
179 RetM=MenuPrincipale.SDLMain();
180 break;
181 case mLangue:
182 RetM=MenuPrincipale.SDLMain_Langue();
183 break;
184 case mOption:
185 RetM=MenuPrincipale.SDLMain_Options();
186 break;
187 case mScoreEdit:
188 RetM=MenuPrincipale.SDLMain_Score(true);
189 break;
190 case mScore:
191 RetM=MenuPrincipale.SDLMain_Score();
192 break;
193 case mMenuSpeed:
194 RetM=MenuPrincipale.SDLMain_Speed();
195 break;
196 case mMenuNiveau:
197 RetM=MenuPrincipale.SDLMain_Niveau();
198 break;
199 case mJeux:
200 Sons.LoadMusic(1);
201 RetM=Jeu.SDLMain();
202 Sons.LoadMusic(0);
203 break;
204 case mEdit:
205 RetM=Edit.SDLMain(0);
206 break;
207 default:
208 RetM=mQuit;
209 }
210 RetMenu=RetM;
211 } while(RetMenu!=mQuit);
212
213 // Ferme proprement le programme
214 Mix_HaltMusic(); // Arrete la music
215 Mix_FreeMusic(Sons.Music); // Efface la music
216
217 for(i=0;i<NSprites;i++) { // Efface les sprites
218 Sprites[i].Delete();
219 }
220 delete [] Sprites;
221
222 SauvePref(); // Sauve les preferences
223
224 exit(0);
225 }
226