~ubuntu-branches/ubuntu/raring/powermanga/raring

« back to all changes in this revision

Viewing changes to src/sdl_tlk.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-08-19 10:15:56 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060819101556-llg7innyzoadukro
Tags: 0.80-3ubuntu1
* Re-merge with Debian
* Fix desktop file for validation
* Install icon in /usr/share/pixmaps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//*****************************************************************************
2
 
// copyright (c) 1998-2004 TLK Games all rights reserved
 
2
// copyright (c) 1998-2005 TLK Games all rights reserved
3
3
//-----------------------------------------------------------------------------
4
 
// file         : "sdl_tlk.cpp"
5
 
// created      : 2003-07-09
6
 
// updates      : 2004-08-01
 
4
// file         : "sdl_tlk.cpp"
 
5
// created      : 2003-07-09
 
6
// updates      : 2005-01-26
 
7
// id           : %Id$
7
8
//-----------------------------------------------------------------------------
8
9
// This program is free software; you can redistribute it and/or modify it under
9
10
// the terms of the GNU General Public License as published by the Free Software
47
48
unsigned int            iHauteurEcran = 0;                     //hauteur de notre fenetre
48
49
unsigned int            iLargeurEcranTotal = 0;                //taille d'une ligne du buffer 'ecran_ram'
49
50
int                     vmode = 1;                             //0=resolution de 320x200 / 1=640*400 / 2=640*400 (double pixels)
 
51
#ifdef WIN32
 
52
Sint32                  vmode2 = 1;                             // si vmode = 1 ==> 0 = 640x400 / 1 = 640x480
 
53
#else
 
54
Sint32                  vmode2 = 0;
 
55
#endif
50
56
 
51
57
//...............................................................................
52
 
int                     fullscreen = 1;                        //1=marche en plein ecran
53
58
char                   *ecran_playanim = 0;                    //memory buffer 320*200
54
59
char                   *ecran_ram640 = 0;                      //memory buffer 640*400
55
60
char                   *ecran_scr = 0;                         //memory buffer 320*016 (score bar-line)
59
64
//..............................................................................
60
65
extern bool             bar_nrj_player;
61
66
extern char            *ecran_ram;                             //adresse du buffer de 512x440 (XImage)
62
 
extern unsigned int     iVerbeux;                              //1=affiche les arguments
63
67
extern short            touch[500];                            //tableau des flags de toutes les touches clavier
64
68
extern int              quit_game;                             //1=demande a quitter le jeu
65
69
extern unsigned int     iCodeTouche;                           // code touche pressee
70
74
void                    initialiseCurseurBlanc();
71
75
void                    affiche_ecran();
72
76
void                    afficheAnim();
 
77
 
73
78
void                    fenetre320x200();
74
 
void                    fenetre640x400();
 
79
void                    fenetre640x400();
 
80
 
75
81
void                    dga320x200();
76
 
void                    dga640x400();
 
82
void                    dga640x400();
 
83
 
77
84
SDL_Surface            *creeXImage(unsigned int _iLarge,
78
85
                                   unsigned int _iHaute);
79
86
void                    libereXImage(SDL_Surface *_pXImage);
89
96
extern unsigned int     iBarreNrjJoueurXWindow;                //1=update player's enerny bar-line
90
97
extern unsigned int     iBarreNrjGardienXWindow;               //1=update bigboss's energy bar-line
91
98
extern unsigned int     iScoreXWindow;                         //1=update player's score points
 
99
extern configfile*      power_conf;
92
100
 
93
101
//...............................................................................
94
102
SDL_Color              *pXColor = 0;                           //color table
115
123
  else
116
124
  { iLargeurEcran = LARG_ECRAN_PHY * 2;
117
125
    iHauteurEcran = HAUT_ECRAN_PHY * 2;
118
 
  }
 
126
  }
 
127
 
119
128
 
120
129
 
121
130
  // initialize SDL screen .....................................................
141
150
    return 0;
142
151
  }
143
152
#ifdef _VERBEUX_
144
 
  if(iVerbeux == 1)
 
153
  if(power_conf->verbose)
145
154
  { printf
146
155
      ("> sdl_tlk.cpp/xw_init(): depth of screen: %i; bytes per pixel: %i;\n",
147
156
       iProfondeur, iOctetsParPixel);
152
161
 
153
162
  SDL_EnableUNICODE(1);
154
163
#ifdef _VERBEUX_
155
 
  if(iVerbeux == 1)
 
164
  if(power_conf->verbose)
156
165
    afficheMessage("> sdl_tlk.cpp/xw_init(): successful initialization!");
157
166
#endif
158
167
  return 1;
159
168
}
160
169
 
161
170
//------------------------------------------------------------------------------
162
 
// SDL : initialise le mode video / initialize vide mode
163
 
// sortie / output <= 0 : erreur
 
171
// SDL: initialize video mode
 
172
// return: 0 = > error / 1 => no error
164
173
//------------------------------------------------------------------------------
165
174
int init_video_mode()
166
175
{
167
 
  Uint32 flag;
168
 
  Uint32 bpp;
169
 
  
170
 
  // test le mode video --------------------------------------------------------  
171
 
  flag = SDL_ANYFORMAT;
172
 
  if(iOctetsParPixel == 1)
173
 
    flag = flag | SDL_HWPALETTE;
174
 
  if(fullscreen > 0)
175
 
    flag = flag | SDL_FULLSCREEN; 
176
 
  bpp = SDL_VideoModeOK(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
177
 
  if(!bpp)
178
 
  { 
179
 
    if(!fullscreen)
180
 
    { fprintf(stderr,
181
 
        "sdl_tlk.cpp/xw_init() : SDL_VideoModeOK() Mode not available : %s",
182
 
        SDL_GetError());
183
 
      return 0;
184
 
    }
185
 
    // echec en plein ecran, ressaie en mode fenetree
186
 
    else 
187
 
    { fullscreen = 0;
188
 
      flag = SDL_ANYFORMAT;
189
 
      if(iOctetsParPixel == 1)
190
 
        flag = flag | SDL_HWPALETTE;
191
 
      bpp = SDL_VideoModeOK(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
192
 
      if(!bpp)
193
 
      { fprintf(stderr,
194
 
          "sdl_tlk.cpp/xw_init() : SDL_VideoModeOK() Mode not available : %s",
195
 
          SDL_GetError());
196
 
        return 0;
197
 
      }
198
 
    }
199
 
  }
200
 
  
201
 
  // initialie le mode video ---------------------------------------------------
202
 
  pPowerMangaDisplay =
203
 
    SDL_SetVideoMode(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
204
 
  if(!pPowerMangaDisplay)
205
 
  { fprintf(stderr,
206
 
      "ecran_hard::ecran_init() : SDL_SetVideoMode() failed: %s\n",
207
 
    SDL_GetError());
208
 
    return 0;
209
 
  }
210
 
  SDL_WM_SetCaption(nomfenetre, nomfenetre);
211
 
  iAffiche = 0; // force refresh all the screen
212
 
  if(fullscreen > 0)
213
 
    SDL_ShowCursor(SDL_DISABLE);
214
 
  else 
215
 
    SDL_ShowCursor(SDL_ENABLE);  
216
 
  return 1;
 
176
        Uint32 flag;
 
177
        Uint32 bpp;
 
178
 
 
179
        //##############################################################
 
180
        // 640x400 => 640x480 (win32 only)
 
181
        //##############################################################
 
182
        if ((vmode) && (vmode2)) {
 
183
                iHauteurEcran = 480;
 
184
        }
 
185
        
 
186
        //##############################################################
 
187
        // test video mode
 
188
        //##############################################################
 
189
        flag = SDL_ANYFORMAT;
 
190
        if(iOctetsParPixel == 1)
 
191
                flag = flag | SDL_HWPALETTE;
 
192
        if(power_conf->fullscreen > 0)
 
193
                flag = flag | SDL_FULLSCREEN; 
 
194
        bpp = SDL_VideoModeOK(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
 
195
        if(!bpp)
 
196
        {       if(!power_conf->fullscreen)
 
197
                {       fprintf(stderr,
 
198
                                "sdl_tlk.cpp/init_video_mode(): SDL_VideoModeOK() return: %s",
 
199
                                SDL_GetError());
 
200
                        return 0;
 
201
                }
 
202
                else 
 
203
                {
 
204
                        // fullscreen fail, try in window mode
 
205
                        power_conf->fullscreen = 0;
 
206
                        flag = SDL_ANYFORMAT;
 
207
                        if(iOctetsParPixel == 1)
 
208
                                flag = flag | SDL_HWPALETTE;
 
209
                        bpp = SDL_VideoModeOK(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
 
210
                        if(!bpp)
 
211
                        {       fprintf(stderr,
 
212
                                        "sdl_tlk.cpp/init_video_mode(): SDL_VideoModeOK() return: %s",
 
213
                                        SDL_GetError());
 
214
                                return 0;
 
215
                        }
 
216
                }
 
217
        }
 
218
 
 
219
  
 
220
        //##############################################################
 
221
        // initialize video mode
 
222
        //##############################################################
 
223
        pPowerMangaDisplay =
 
224
                SDL_SetVideoMode(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
 
225
        if(!pPowerMangaDisplay)
 
226
        {       fprintf(stderr,
 
227
                        "sdl_tlk.cpp/init_video_mode(): SDL_SetVideoMode() return %s\n",
 
228
                        SDL_GetError());
 
229
                return 0;
 
230
        }
 
231
  
 
232
        //##############################################################
 
233
        // restore valid height screen (win32 only)
 
234
        //##############################################################
 
235
        if ((vmode) && (vmode2)) {
 
236
                iHauteurEcran = HAUT_ECRAN_PHY * 2;
 
237
        }
 
238
 
 
239
        SDL_WM_SetCaption(nomfenetre, nomfenetre);
 
240
        iAffiche = 0; // force refresh all the screen
 
241
        if(power_conf->fullscreen > 0)
 
242
                SDL_ShowCursor(SDL_DISABLE);
 
243
        else 
 
244
                SDL_ShowCursor(SDL_ENABLE);  
 
245
        return 1;
217
246
}
218
247
 
219
248
//------------------------------------------------------------------------------
428
457
  touch[47]  = k[SDLK_p];                 //P P=PAUSE
429
458
  touch[58]  = k[SDLK_q];                 //Q CTRL+Q gameover
430
459
  touch[60]  = k[SDLK_s];                 //S CTRL+S coupe la musique
431
 
    
 
460
 
432
461
  touch[73]  |= k[SDLK_KP6];              //right arrow 
433
462
  touch[71]  |= k[SDLK_KP4];              //left arrow
434
463
  touch[55]  |= k[SDLK_KP8];              //up arrow
455
484
        break;                                               // window 320*200
456
485
      case 1:
457
486
        fenetre640x400();
458
 
        break;                                               // window 640x480
 
487
        break;                                               
459
488
    }
460
489
  }
461
490
}
501
530
    }
502
531
    break;
503
532
    
504
 
    //mode 640x400
 
533
    //mode 640x400    
505
534
    case 1:
506
535
      { copy2X(ecran_playanim, ecran_ram640, 320, 200, 0,
507
536
               iLargeurEcran * iOctetsParPixel * 2 -
508
537
               (iLargeurEcran * iOctetsParPixel));
509
 
      rsour.x = 0; rsour.y = 0;
 
538
      rsour.x = 0; 
 
539
          
 
540
          if (vmode2) 
 
541
         rsour.y = 40;
 
542
          else 
 
543
             rsour.y = 0;
 
544
 
510
545
      rsour.w = iLargeurEcran; rsour.h = iHauteurEcran;
511
546
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
512
547
      if(v < 0)
513
548
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
514
549
 
515
 
      }
516
 
      SDL_UpdateRect(pPowerMangaDisplay, 0, 0, 
517
 
                     pPowerMangaDisplay->w, pPowerMangaDisplay->h);
 
550
      }
 
551
          
 
552
            if (vmode2) 
 
553
                        SDL_UpdateRect(pPowerMangaDisplay, 0, 40, 
 
554
                     pPowerMangaDisplay->w, pPowerMangaDisplay->h - 40);
 
555
                else
 
556
                        SDL_UpdateRect(pPowerMangaDisplay, 0, 0, 
 
557
                     pPowerMangaDisplay->w, pPowerMangaDisplay->h);
 
558
          
 
559
 
518
560
        break;
519
561
    }
520
562
}
632
674
//------------------------------------------------------------------------------
633
675
void fenetre640x400()
634
676
{
635
 
  Uint32 v;
 
677
  Uint32 v;
 
678
  int           starty;
636
679
  SDL_Rect rdest;
637
680
  SDL_Rect rsour;
638
681
  char *_pSource =
644
687
  copy2X_512x440(_pSource, 
645
688
                 ecran_ram640 + (iLargeurEcran * iOctetsParPixel * 32),
646
689
                 HAUT_ECR_RAM
647
 
  );
 
690
  );
 
691
 
 
692
 
 
693
  // mode 640x480
 
694
  if (vmode2) 
 
695
          starty = 40;
 
696
  else 
 
697
          starty = 0;
 
698
 
648
699
 
649
700
 
650
701
  if(iAffiche)
651
702
  { rsour.x = 0; rsour.y = 32; 
652
 
    rsour.w = LARG_ECR_RAM * 2; rsour.h = HAUT_ECR_RAM * 2;
653
 
    v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
 
703
    rsour.w = LARG_ECR_RAM * 2; rsour.h = HAUT_ECR_RAM * 2;
 
704
        rdest.x = 0; rdest.y = 32 + starty; 
 
705
    rdest.w = LARG_ECR_RAM * 2; rdest.h = HAUT_ECR_RAM * 2;
 
706
    v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
654
707
    if(v < 0)
655
708
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
656
709
 
664
717
             (iLargeurEcran * 2 * iOctetsParPixel) -
665
718
             128 * iOctetsParPixel * 2);
666
719
      rsour.x = 68 * 2; rsour.y = 0; rsour.w = 128 * 2; rsour.h = 16 * 2;
667
 
      rdest.x = 68 * 2; rdest.y = 0; rdest.w = 128 * 2; rdest.h = 16 * 2;
 
720
      rdest.x = 68 * 2; rdest.y = starty; rdest.w = 128 * 2; rdest.h = 16 * 2;
668
721
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
669
722
      if(v < 0)
670
723
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
680
733
             (iLargeurEcran * iOctetsParPixel * 2) -
681
734
             14 * iOctetsParPixel * 2);
682
735
      rsour.x = (LARG_ECR_RAM + 41) * 2; rsour.y = (SCR_HAUTE + 171) * 2;
683
 
      rsour.w = 14 * 2; rsour.h = 8 * 2;
684
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
 
736
      rsour.w = 14 * 2; rsour.h = 8 * 2;
 
737
          rdest.x = (LARG_ECR_RAM + 41) * 2; rdest.y = (SCR_HAUTE + 171) * 2 + starty;
 
738
      rdest.w = 14 * 2; rdest.h = 8 * 2;
 
739
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
685
740
      if(v < 0)
686
741
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
687
742
      iBonusX2Affiche = 0;
697
752
             (iLargeurEcran * iOctetsParPixel * 2) -
698
753
             14 * iOctetsParPixel * 2);
699
754
      rsour.x = (LARG_ECR_RAM + 41) * 2; rsour.y = (SCR_HAUTE + 5) * 2;
700
 
      rsour.w = 14 * 2; rsour.h = 8 * 2;
701
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
 
755
      rsour.w = 14 * 2; rsour.h = 8 * 2;
 
756
          rdest.x = (LARG_ECR_RAM + 41) * 2; rdest.y = (SCR_HAUTE + 5) * 2 + starty;
 
757
      rdest.w = 14 * 2; rdest.h = 8 * 2;
 
758
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
702
759
      if(v < 0)
703
760
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
704
761
      iBonusX4Affiche = 0;
717
774
             (iLargeurEcran * iOctetsParPixel * 2) -
718
775
             28 * iOctetsParPixel * 2);
719
776
      rsour.x = (LARG_ECR_RAM + _iOptionX) * 2; rsour.y = (SCR_HAUTE + _iOptionY) * 2;
720
 
      rsour.w = 28 * 2; rsour.h = 28 * 2;
721
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
 
777
      rsour.w = 28 * 2; rsour.h = 28 * 2;
 
778
          rdest.x = (LARG_ECR_RAM + _iOptionX) * 2; rdest.y = (SCR_HAUTE + _iOptionY) * 2 + starty;
 
779
      rdest.w = 28 * 2; rdest.h = 28 * 2;
 
780
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
722
781
      if(v < 0)
723
782
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
724
783
    }
735
794
             (iLargeurEcran * iOctetsParPixel * 2) -
736
795
             100 * iOctetsParPixel * 2);
737
796
      rsour.x = 210 * 2; rsour.y = 3 * 2;
738
 
      rsour.w = 100 * 2; rsour.h = 9 * 2;
739
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
 
797
      rsour.w = 100 * 2; rsour.h = 9 * 2;
 
798
          rdest.x = 210 * 2; rdest.y = 3 * 2 + starty;
 
799
      rdest.w = 100 * 2; rdest.h = 9 * 2;
 
800
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
740
801
      if(v < 0)
741
802
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
742
803
    }
752
813
             45 * iOctetsParPixel * 2);
753
814
      rsour.x = 10 * 2; rsour.y = 3 * 2;
754
815
      rsour.w = 45 * 2; rsour.h = 9 * 2;
755
 
      rdest.x = 10 * 2; rdest.y = 3 * 2;
 
816
      rdest.x = 10 * 2; rdest.y = 3 * 2 + starty;
756
817
      rdest.w = 45 * 2; rdest.h = 9 * 2;
757
818
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
758
819
      if(v < 0)
773
834
           iLargeurEcran * iOctetsParPixel * 2 -
774
835
           (OPT_LARGE * 2 * iOctetsParPixel));
775
836
    rsour.x = 0; rsour.y = 0; rsour.w = iLargeurEcran; rsour.h = iHauteurEcran;
776
 
    rdest.x = 0; rdest.y = 0; rdest.w = iLargeurEcran; rdest.h = iHauteurEcran;
 
837
    rdest.x = 0; rdest.y = starty; rdest.w = iLargeurEcran; rdest.h = iHauteurEcran;
777
838
    v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
778
839
    if(v < 0)
779
840
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());     
780
841
    iAffiche = 1;
781
842
    iOptionIndex = -1;
782
 
  }     
783
 
  SDL_UpdateRect(pPowerMangaDisplay, 0, 0, pPowerMangaDisplay->w, pPowerMangaDisplay->h);    
784
 
}
 
843
  }     
 
844
 
 
845
  SDL_UpdateRect(pPowerMangaDisplay, 0, starty, pPowerMangaDisplay->w, pPowerMangaDisplay->h - starty);    
 
846
}
 
847
 
 
848
 
 
849
 
785
850
 
786
851
//------------------------------------------------------------------------------
787
852
// SDL : ferme l'affichage sous SDL
799
864
  pEcranOptXImage = 0;
800
865
  SDL_Quit();
801
866
#ifdef _VERBEUX_
802
 
  if(iVerbeux > 0)
 
867
  if(power_conf->verbose)
803
868
    afficheMessage("> sdl_tlk.cpp/xw_kill() / SDL_Quit");
804
869
#endif
805
870
  return 1;
941
1006
  pListeXImage[_iXimageLibre] = _pXImage;
942
1007
  iNombreXImage++;
943
1008
#ifdef _VERBEUX_
944
 
  if(iVerbeux > 0)
 
1009
  if(power_conf->verbose)
945
1010
    fprintf(stdout,
946
1011
      "> sdl_tlk.cpp/creeXImage(): SDL_CreateRGBSurface(%i,%i,%i)\n",
947
1012
      _iLarge,_iHaute,iProfondeur2);
965
1030
      pListeXImage[_iIndex] = 0;
966
1031
      iNombreXImage--;
967
1032
#ifdef _VERBEUX_
968
 
      if(iVerbeux > 0)
 
1033
      if(power_conf->verbose)
969
1034
        fprintf(stdout,
970
1035
          "> sdl_tlk.cpp/libereXImage(): SDL_FreeSurface; %i,%i\n", w, h);
971
1036
#endif
991
1056
      pListeXImage[_iIndex] = 0;
992
1057
      iNombreXImage--;
993
1058
#ifdef _VERBEUX_
994
 
      if(iVerbeux > 0)
 
1059
      if(power_conf->verbose)
995
1060
        fprintf(stdout,
996
1061
          "> sdl_tlk.cpp/libereXImage(): SDL_FreeSurface; %i,%i\n", w, h);
997
1062
#endif