Subversion Repositories Games.Rick Dangerous

Rev

Rev 7 | Rev 10 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 9
Line 155... Line 155...
155
   game_state = INIT_GAME;
155
   game_state = INIT_GAME;
156
 
156
 
157
   /* main loop */
157
   /* main loop */
158
   while (game_state != EXIT)
158
   while (game_state != EXIT)
159
   {
159
   {
-
 
160
      // Pierre-Marie Baty -- intro runs faster
160
      if (game_state != INTRO_MAP)
161
      if (game_state != INTRO_MAP)
161
         game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD;
162
         game_period = (sysarg_args_period ? sysarg_args_period : GAME_PERIOD);
162
      else
163
      else
163
         game_period = (sysarg_args_period ? sysarg_args_period : GAME_PERIOD) / 2;
164
         game_period = (sysarg_args_period ? sysarg_args_period : GAME_PERIOD) / 2;
164
 
165
 
165
      /* timer */
166
      /* timer */
166
      tmx = tm; tm = sys_gettime (); tmx = tm - tmx;
167
      tmx = tm; tm = sys_gettime (); tmx = tm - tmx;
Line 184... Line 185...
184
      /* frame */
185
      /* frame */
185
      frame ();
186
      frame ();
186
   }
187
   }
187
 
188
 
188
   freedata (); /* free cached data */
189
   freedata (); /* free cached data */
-
 
190
}
-
 
191
 
-
 
192
 
-
 
193
// Pierre-Marie Baty -- addition: sort high scores
-
 
194
int sort_hscores (const void *q1, const void *q2)
-
 
195
{
-
 
196
   return (((hscore_t *) q1)->score < ((hscore_t *) q2)->score);
189
}
197
}
190
 
198
 
191
 
199
 
192
/*
200
/*
193
 * Prepare frame
201
 * Prepare frame
Line 368... Line 376...
368
            if (game_map >= 0x04)
376
            if (game_map >= 0x04)
369
            {
377
            {
370
               /* reached end of game */
378
               /* reached end of game */
371
               sysarg_args_map = 0;
379
               sysarg_args_map = 0;
372
               sysarg_args_submap = 0;
380
               sysarg_args_submap = 0;
-
 
381
               sysarg_args_score = 0;
373
               game_state = GAMEOVER;
382
               game_state = GAMEOVER;
374
            }
383
            }
375
            else
384
            else
376
            {
385
            {
377
               /* initialize game */
386
               /* initialize game */
Line 507... Line 516...
507
      while (i < MAP_NBR_CONNECT && (map_connect[i].submap != game_submap || map_connect[i].dir != RIGHT))
516
      while (i < MAP_NBR_CONNECT && (map_connect[i].submap != game_submap || map_connect[i].dir != RIGHT))
508
         i++;
517
         i++;
509
      map_frow = map_connect[i].rowin - 0x10;
518
      map_frow = map_connect[i].rowin - 0x10;
510
      ent_ents[1].y = 0x10 << 3;
519
      ent_ents[1].y = 0x10 << 3;
511
   }
520
   }
-
 
521
 
-
 
522
   // Pierre-Marie Baty -- addition: start score
-
 
523
   if (sysarg_args_score != 0)
-
 
524
      game_score = sysarg_args_score + 1;
512
 
525
 
513
   ent_ents[1].x = map_maps[game_map].x;
526
   ent_ents[1].x = map_maps[game_map].x;
514
   ent_ents[1].y = map_maps[game_map].y;
527
   ent_ents[1].y = map_maps[game_map].y;
515
   ent_ents[1].w = 0x18;
528
   ent_ents[1].w = 0x18;
516
   ent_ents[1].h = 0x15;
529
   ent_ents[1].h = 0x15;
Line 570... Line 583...
570
   game_rects = r; /* take care to cleanup draw_STATUSRECT->next later! */
583
   game_rects = r; /* take care to cleanup draw_STATUSRECT->next later! */
571
 
584
 
572
   if (!E_RICK_STTST (E_RICK_STZOMBIE))
585
   if (!E_RICK_STTST (E_RICK_STZOMBIE))
573
   {
586
   {
574
      /* need to scroll ? */
587
      /* need to scroll ? */
575
      if (ent_ents[1].y >= 0xCC)
588
      if (ent_ents[1].y >= 200 + 4)
576
      {
589
      {
577
         game_state = SCROLL_UP;
590
         game_state = SCROLL_UP;
578
         return;
591
         return;
579
      }
592
      }
580
      if (ent_ents[1].y <= 0x60)
593
      if (ent_ents[1].y <= 100 - 4)
581
      {
594
      {
582
         game_state = SCROLL_DOWN;
595
         game_state = SCROLL_DOWN;
583
         return;
596
         return;
584
      }
597
      }
585
   }
598
   }
Line 592... Line 605...
592
 * restart
605
 * restart
593
 *
606
 *
594
 */
607
 */
595
static void restart (void)
608
static void restart (void)
596
{
609
{
597
   E_RICK_STRST (E_RICK_STDEAD | E_RICK_STZOMBIE);
610
   E_RICK_STRST (/*E_RICK_STDEAD | E_RICK_STZOMBIE*/ 0xff); // Pierre-Marie Baty -- correct sprite position on restart
598
 
611
 
599
   game_bullets = 6;
612
   game_bullets = 6;
600
   game_bombs = 6;
613
   game_bombs = 6;
601
 
614
 
602
   ent_ents[1].n = 1;
615
   ent_ents[1].n = 1;
Line 664... Line 677...
664
   WAV_ENTITY[4] = syssnd_load ("sounds/ent4.wav");
677
   WAV_ENTITY[4] = syssnd_load ("sounds/ent4.wav");
665
   WAV_ENTITY[5] = syssnd_load ("sounds/ent5.wav");
678
   WAV_ENTITY[5] = syssnd_load ("sounds/ent5.wav");
666
   WAV_ENTITY[6] = syssnd_load ("sounds/ent6.wav");
679
   WAV_ENTITY[6] = syssnd_load ("sounds/ent6.wav");
667
   WAV_ENTITY[7] = syssnd_load ("sounds/ent7.wav");
680
   WAV_ENTITY[7] = syssnd_load ("sounds/ent7.wav");
668
   WAV_ENTITY[8] = syssnd_load ("sounds/ent8.wav");
681
   WAV_ENTITY[8] = syssnd_load ("sounds/ent8.wav");
-
 
682
 
-
 
683
   // Pierre-Marie Baty -- addition: load high scores
-
 
684
   {
-
 
685
      char hiscorefile_fullpathname[1024];
-
 
686
      char linebuf[256];
-
 
687
      hscore_t *hscore;
-
 
688
      U32 score;
-
 
689
      char *ptr;
-
 
690
      size_t i, j;
-
 
691
      FILE *fp;
-
 
692
      sprintf_s (hiscorefile_fullpathname, 1024, "%s/%s", sys_getbasepath (), "hiscores.txt");
-
 
693
      fopen_s (&fp, hiscorefile_fullpathname, "rb");
-
 
694
      if (fp != NULL)
-
 
695
      {
-
 
696
         for (i = 0; (fgets (linebuf, sizeof (linebuf), fp) != NULL) && (i < 8);)
-
 
697
         {
-
 
698
            score = strtol (linebuf, &ptr, 10);
-
 
699
            if (ptr <= linebuf)
-
 
700
               continue;
-
 
701
            while ((*ptr == '\t') || (*ptr == ' '))
-
 
702
               ptr++;
-
 
703
            hscore = &game_hscores[i++];
-
 
704
            hscore->score = score;
-
 
705
            for (j = 0; j < sizeof (hscore->name); j++)
-
 
706
               hscore->name[j] = '@';
-
 
707
            for (j = 0; j < sizeof (hscore->name); j++, ptr++)
-
 
708
               hscore->name[j] = (((*ptr >= 'A') && (*ptr <= 'Z')) || (*ptr == '.') ? *ptr : '@');
-
 
709
         }
-
 
710
         qsort (game_hscores, 8, sizeof (hscore_t), sort_hscores);
-
 
711
         fclose (fp);
-
 
712
      }
-
 
713
   }
669
}
714
}
670
 
715
 
671
 
716
 
672
/*
717
/*
673
 *
718
 *
Line 696... Line 741...
696
   syssnd_free (WAV_ENTITY[4]);
741
   syssnd_free (WAV_ENTITY[4]);
697
   syssnd_free (WAV_ENTITY[5]);
742
   syssnd_free (WAV_ENTITY[5]);
698
   syssnd_free (WAV_ENTITY[6]);
743
   syssnd_free (WAV_ENTITY[6]);
699
   syssnd_free (WAV_ENTITY[7]);
744
   syssnd_free (WAV_ENTITY[7]);
700
   syssnd_free (WAV_ENTITY[8]);
745
   syssnd_free (WAV_ENTITY[8]);
-
 
746
 
-
 
747
   // Pierre-Marie Baty -- addition: save high scores
-
 
748
   {
-
 
749
      char hiscorefile_fullpathname[1024];
-
 
750
      size_t i, j;
-
 
751
      FILE *fp;
-
 
752
      sprintf_s (hiscorefile_fullpathname, 1024, "%s/%s", sys_getbasepath (), "hiscores.txt");
-
 
753
      fopen_s (&fp, hiscorefile_fullpathname, "wb");
-
 
754
      if (fp != NULL)
-
 
755
      {
-
 
756
         for (i = 0; i < sizeof (game_hscores) / sizeof (game_hscores[0]); i++)
-
 
757
         {
-
 
758
            fprintf (fp, "%d\t", game_hscores[i].score);
-
 
759
            for (j = 0; j < sizeof (game_hscores[i].name); j++)
-
 
760
               fputc ((game_hscores[i].name[j] != '@' ? game_hscores[i].name[j] : ' '), fp);
-
 
761
            fputc ('\n', fp);
-
 
762
         }
-
 
763
         fclose (fp);
-
 
764
      }
-
 
765
   }
701
}
766
}