File: main.cc

package info (click to toggle)
ri-li 2.0.1%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 41,988 kB
  • sloc: cpp: 4,493; sh: 785; makefile: 95
file content (339 lines) | stat: -rw-r--r-- 9,707 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//      (_||_/
//      (    )       Programme Principale
//     ( o  0 )
//-OOO--(_)---OOO---------------------------------------
//                   Copyright (C) 2006 By Dominique Roux-Serret
// .OOOo      oOOO.  roux-serret@ifrance.com
//-(   )------(   )---------------------------------------
//  ( (        ) /   Le 03/01/2006
//   (_)      (_/

//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 or version 3 of the License.

//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License along
//    with this program; if not, write to the Free Software Foundation, Inc.,
//    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <stdlib.h>
#include <iostream>
using namespace std;
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

#include "sprite.h"

/*** Variables globales ***/
/**************************/
SDL_Surface *sdlVideo; // Pointe sur l'cran video
Uint32 FontColor;      // Couleur du fond d'cran
FILE *file;            // Pointe sur le fichier de sauvegarde

char Titre[]="MakeDat V2.0.1";

struct s_Sprite {
  char *NomF,*NomA;
  int nombre;
  bool Caractaire;
};

const char* Langues[]={"langues/De/","langues/En/","langues/Es/","langues/Fr/","langues/Ar/","langues/Cn/",
		 "langues/Jp/","langues/Ru/","langues/Sl/","langues/It/","langues/Br/","langues/Po/",
		 "langues/Se/","langues/Eo/","langues/Hu/","langues/Tu/","langues/Pl/","langues/Du/",
		 "langues/Ko/",NULL};

s_Sprite Spri[]={
  { "png/locomotive","png/locomotiveA",320,false},
  { "png/charbon","png/charbonA",320,false},
  { "png/buche","png/bucheA",320,false},
  { "png/balles","png/ballesA",320,false},
  { "png/moteur","png/moteurA",320,false},
  { "png/citerne","png/citerneA",320,false},
  { "png/wagon","png/wagonA",50,false},
  { "png/pluslong","png/pluslongA",50,false},
  { "png/pluscourt","png/pluscourtA",50,false},
  { "png/vitesse","png/vitesseA",50,false},
  { "png/vie","png/vieA",50,false},
  { "png/nouveau_wagon",NULL,50,false},
  { "png/logo_vie","png/logo_vieA",1,false},
  { "png/rail","png/railA",11,false},
  { "png/dir",NULL,12,false},
  { "langues/lettres",NULL,1,true},
  { "langues/chiffres",NULL,1,true},
  { "png/logo",NULL,1,false},
  { "png/copyright",NULL,1,false},
  { "png/deco","png/decoA",24,false},
  { "png/curseur","png/curseurA",20,false},
  { "png/fleche_gauche","png/fleche_gaucheA",20,false},
  { "png/fleche_droite","png/fleche_droiteA",20,false},
  { "png/fleches","png/flechesA",6,false},
  { "png/monde",NULL,50,false},
  { "png/music",NULL,25,false},
  { "png/bruitage",NULL,25,false},
  { "png/fscreen",NULL,1,false},
  { "png/window",NULL,1,false},
  { "png/keys",NULL,1,false},
  { "png/gmenu",NULL,1,false},
  { "png/menu",NULL,1,false},
  { "png/fond_hr",NULL,1,false},
  { "png/fond_hrr",NULL,1,false},

  // *** FONDS D'ECRAN ***
  { "png/fond_menu",NULL,1,false},
  { "png/fond",NULL,1,false},
  { NULL,NULL,0,false }
};

s_Sprite SpriLoad[]={
  { "png/chargeur",NULL,20,false},
  { NULL,NULL,0,false }
};

s_Sprite Sprit[]={
  { "langue",NULL,1,false},
  { "level",NULL,1,false},
  { "lives",NULL,1,false},
  { "options",NULL,1,false},
  { "score",NULL,1,false},
  { "press_any_key",NULL,1,false},
  { "continue",NULL,1,false},
  { "moptions",NULL,1,false},
  { "exit_game",NULL,1,false},
  { "play",NULL,1,false},
  { "scores",NULL,1,false},
  { "better_scores",NULL,1,false},
  { "quit",NULL,1,false},
  { "new_game",NULL,1,false},
  { "old_level",NULL,1,false},
  { "menu",NULL,1,false},
  { "easy",NULL,1,false},
  { "normal",NULL,1,false},
  { "hard",NULL,1,false},
  { "question",NULL,1,false},
  { "tart1",NULL,1,false},
  { "tart2",NULL,1,false},
  { "tart3",NULL,1,false},
  { "tart4",NULL,1,false},
  { "tart5",NULL,1,false},
  { "tart6",NULL,1,false},
  { "tart7",NULL,1,false},
  { "tart8",NULL,1,false},
  { "tart9",NULL,1,false},
  { "tart10",NULL,1,false},
  { "tart11",NULL,1,false},
  { "tart12",NULL,1,false},
  { "tart13",NULL,1,false},
  { "tart14",NULL,1,false},
  { "tart15",NULL,1,false},
  { "tart16",NULL,1,false},
  { "tart17",NULL,1,false},
  { "tart18",NULL,1,false},
  { "tart19",NULL,1,false},
  { "tart20",NULL,1,false},
  { "tart21",NULL,1,false},
  { "tart22",NULL,1,false},
  { "tart23",NULL,1,false},
  { "tart24",NULL,1,false},
  { "tart25",NULL,1,false},
  { "tart26",NULL,1,false},
  { "tart27",NULL,1,false},
  { "tart28",NULL,1,false},
  { "tart29",NULL,1,false},
  { "tart30",NULL,1,false},
  { "art1",NULL,1,false},
  { "art2",NULL,1,false},
  { "art3",NULL,1,false},
  { "art4",NULL,1,false},
  { "art5",NULL,1,false},
  { "art6",NULL,1,false},
  { "art7",NULL,1,false},
  { "art8",NULL,1,false},
  { "art9",NULL,1,false},
  { "art10",NULL,1,false},
  { "art11",NULL,1,false},
  { "art12",NULL,1,false},
  { "art13",NULL,1,false},
  { "art14",NULL,1,false},
  { "art15",NULL,1,false},
  { "art16",NULL,1,false},
  { "art17",NULL,1,false},
  { "art18",NULL,1,false},
  { "art19",NULL,1,false},
  { "art20",NULL,1,false},
  { "art21",NULL,1,false},
  { "art22",NULL,1,false},
  { "art23",NULL,1,false},
  { "art24",NULL,1,false},
  { "art25",NULL,1,false},
  { "art26",NULL,1,false},
  { "art27",NULL,1,false},
  { "art28",NULL,1,false},
  { "art29",NULL,1,false},
  { "art30",NULL,1,false},
  { NULL,NULL,0,false }
};

/*** Preogramme principale ***/
/*****************************/
int main(int narg,char *argv[])
{
  int i,j,n,nt;
  char **pTitre=NULL;
  char **pIcon=NULL;
  char Provi[512];
  char Extension[3];
  SDL_VideoInfo *sdlVideoInfo;
  Sprite Spr;
  int NL;
  unsigned char Buf[2];
  
  // Initilise SDL
  if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE) < 0 ) {
    cerr <<"Impossible d'initialiser SDL:"<<SDL_GetError()<<endl;
    exit(-1);
  }
  // Ferme le programme correctement quant quit
  atexit(SDL_Quit);
    
  // Teste la resolution video
  sdlVideoInfo=(SDL_VideoInfo*)SDL_GetVideoInfo();

  if(sdlVideoInfo->vfmt->BitsPerPixel==8) {
    cerr <<"Impossible d'utiliser 8bits pour la vido !"<<endl;
    exit(-1);
  }

  // Demande la recolution Video
  int vOption=SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_ASYNCBLIT;
  //  if(Jeu.Pref.FullScreen) vOption|=SDL_FULLSCREEN;
  sdlVideo=SDL_SetVideoMode(800,600,sdlVideoInfo->vfmt->BitsPerPixel,vOption);

  if(sdlVideo==NULL) {
    cerr <<"Impossible de passer dans le mode vido 800x600 !"<<endl;
    exit(-1);
  }
  // Change le nom de la fenetre
  SDL_WM_GetCaption(pTitre,pIcon);
  SDL_WM_SetCaption(Titre,NULL);

  // Couleur du font d'cran
  FontColor=SDL_MapRGB(sdlVideo->format,128,128,128);

 
  // *** Compte les sprites de dcos ***
  // ***********************************
  n=0;
  while(Spri[n].NomF!=NULL) n++;
  cout <<n<<"Sprites  traiter !"<<endl;
  
  // Compte les sprites de texte
  nt=0;
  while(Sprit[nt].NomF!=NULL) nt++;
  nt--; // del le sprite de langue
  cout <<nt<<"Sprites de texte  traiter par langue!"<<endl;
  
  // Compte les langues
  NL=0;
  while(Langues[NL]!=NULL) NL++;
  cout <<"Trouve "<<NL<<" langues!"<<endl;

  // *** Cration du fichier de sauvegarde sprites.dat ***
  // *****************************************************
  file=fopen("sprites.dat","w");
  if(!file) {
    cerr <<"ERREUR: Impossible de crer sprites.dat!"<<endl;
    perror("fopen");
    exit(-1);
  }
 
  // Chargement des Sprites
  for(i=0;i<n;i++) {
    if(Spri[i].Caractaire==false) {
      if(Spr.Load(Spri[i].NomF,Spri[i].NomA,Spri[i].nombre)==false) exit(-1);
    }
    else {
      if(Spr.LoadCaractaire(Spri[i].NomF)==false) exit(-1);
    }
  }

  // Ferme le fichier
  fclose(file);

  // *** Cration du fichier de sauvegarde sprites.dat ***
  // *****************************************************
  file=fopen("language.dat","w");
  if(!file) {
    cerr <<"ERREUR: Impossible de crer language.dat!"<<endl;
    perror("fopen");
    exit(-1);
  }

  // Sauve le nombre de sprites de decor
  Buf[0]=n/256;
  Buf[1]=n%256;
  fwrite(Buf,1,2,file);

  // Sauve le nombre textes par langues
  Buf[0]=nt/256;
  Buf[1]=nt%256;
  fwrite(Buf,1,2,file);
 
  // Sauve le nombre de langues
  Buf[0]=NL/256;
  Buf[1]=NL%256;
  fwrite(Buf,1,2,file);

  // sauve les noms de langues
  Extension[2]=0;
  for(i=0;i<NL;i++) {
    Extension[0]=Langues[i][8];
    Extension[1]=Langues[i][9];
    sprintf(Provi,"language.%s",Extension);
    fwrite(Provi,1,strlen(Provi)+1,file);
  }

  // Sauve les sprites de langue
  for(i=0;i<NL;i++) {
    sprintf(Provi,"%s%s",Langues[i],Sprit[0].NomF);
    if(Spr.Load(Provi,NULL,Sprit[0].nombre)==false) exit(-1);
  }

  // Sauve le sprite d'animation loars du chargement
  if(Spr.Load(SpriLoad[0].NomF,SpriLoad[0].NomA,SpriLoad[0].nombre)==false) exit(-1);
  
  // Ferme le fichier
  fclose(file);
  
  // *** Cration des fichiers de langue ***
  // ***************************************
  for(j=0;j<NL;j++) {
    // Fabrique le nom du fichier
    Extension[0]=Langues[j][8];
    Extension[1]=Langues[j][9];
    sprintf(Provi,"language.%s",Extension);
    
    file=fopen(Provi,"w");
    if(!file) {
      cerr <<"ERREUR: Impossible de crer le fichier "<<Provi<<endl;
      perror("fopen");
      exit(-1);
    }
    
    // Charge les langues
    for(i=1;i<nt+1;i++) {
      sprintf(Provi,"%s%s",Langues[j],Sprit[i].NomF);
      if(Spr.Load(Provi,NULL,Sprit[i].nombre)==false) exit(-1);
    }
    
    fclose(file);  
  }  
  
  exit(0);
}